67 $xml = file_get_contents( $file );
69 if ( $xml ===
false ) {
70 throw new RuntimeException(
'Failed to read ' . $file .
'!' );
82 $document =
new DOMDocument();
84 $oldLibXmlErrors = libxml_use_internal_errors(
true );
85 $ok = $document->loadXML( $xml, LIBXML_NONET );
88 $errors = libxml_get_errors();
89 libxml_use_internal_errors( $oldLibXmlErrors );
91 foreach ( $errors
as $error ) {
93 throw new InvalidArgumentException(
94 'Malformed XML: ' . $error->message .
' in line ' . $error->line
98 throw new InvalidArgumentException(
'Malformed XML!' );
101 libxml_use_internal_errors( $oldLibXmlErrors );
110 $this->
store->saveSites( $sites );
123 $oldSites = $this->
store->getSites();
125 $current = $root->firstChild;
127 if ( $current instanceof DOMElement && $current->tagName ===
'site' ) {
129 $site = $this->
makeSite( $current );
130 $key = $site->getGlobalId();
132 if ( $oldSites->hasSite( $key ) ) {
133 $oldSite = $oldSites->getSite( $key );
134 $site->setInternalId( $oldSite->getInternalId() );
137 $sites[$key] = $site;
138 }
catch ( Exception $ex ) {
143 $current = $current->nextSibling;
155 public function makeSite( DOMElement $siteElement ) {
156 if ( $siteElement->tagName !==
'site' ) {
157 throw new InvalidArgumentException(
'Expected <site> tag, found ' . $siteElement->tagName );
163 $site->setForward( $this->
hasChild( $siteElement,
'forward' ) );
164 $site->setGlobalId( $this->
getChildText( $siteElement,
'globalid' ) );
168 $pathTags = $siteElement->getElementsByTagName(
'path' );
169 for ( $i = 0; $i < $pathTags->length; $i++ ) {
170 $pathElement = $pathTags->item( $i );
172 $path = $pathElement->textContent;
174 $site->setPath( $pathType,
$path );
177 $idTags = $siteElement->getElementsByTagName(
'localid' );
178 for ( $i = 0; $i < $idTags->length; $i++ ) {
179 $idElement = $idTags->item( $i );
181 $id = $idElement->textContent;
183 $site->addLocalId( $idType, $id );
201 $node = $element->getAttributeNode(
$name );
204 if ( $default !==
false ) {
208 'Required ' .
$name .
' attribute not found in <' . $element->tagName .
'> tag'
213 return $node->textContent;
225 $elements = $element->getElementsByTagName(
$name );
227 if ( $elements->length < 1 ) {
228 if ( $default !==
false ) {
232 'Required <' .
$name .
'> tag not found inside <' . $element->tagName .
'> tag'
237 $node = $elements->item( 0 );
238 return $node->textContent;
256 if ( $this->exceptionCallback ) {
257 call_user_func( $this->exceptionCallback, $ex );