Ejemplo n.º 1
0
 public static function rebuildConfiguration($config_pathname = NULL)
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $doc->appendChild($doc->createElement('extensions'));
     $root = $doc->documentElement;
     foreach (new ExtensionIterator() as $extension) {
         // TODO: Check if the extension is already present in the config, and retain the version & status if it is
         // This ensures that the status of "requires-update" remains intact.
         $pathname = self::getPathFromClass(get_class($extension));
         $handle = self::getHandleFromPath($pathname);
         $element = $doc->createElement('extension');
         $element->setAttribute('handle', $handle);
         $node = end(self::$extension_configuration->xpath("//extension[@handle='{$handle}'][1]"));
         if (!empty($node)) {
             $element->setAttribute('version', $node->attributes()->version);
             $element->setAttribute('status', $node->attributes()->status);
         } else {
             $element->setAttribute('version', $extension->about()->version);
             $element->setAttribute('status', self::status($handle));
         }
         $root->appendChild($element);
         if (method_exists($extension, 'getSubscribedDelegates')) {
             $delegates = $doc->createElement('delegates');
             foreach ((array) $extension->getSubscribedDelegates() as $delegate) {
                 $item = $doc->createElement('item');
                 $item->setAttribute('page', $delegate['page']);
                 $item->setAttribute('delegate', $delegate['delegate']);
                 $item->setAttribute('callback', $delegate['callback']);
                 $delegates->appendChild($item);
             }
             $element->appendChild($delegates);
         }
     }
     self::$extension_configuration = simplexml_import_dom($doc);
     self::saveConfiguration($config_pathname);
 }