Exemplo n.º 1
0
 /**
  * Write the model definitions of the provided models to the provided model definition file
  * @param zibo\library\filesystem\File $file
  * @param array $models models to write to file
  * @return null
  */
 public function writeModelsToFile(File $file, array $models)
 {
     if (!$models) {
         if ($file->exists()) {
             $file->delete();
         }
         return;
     }
     $dom = new Document('1.0', 'utf-8');
     $dom->formatOutput = true;
     $modelsElement = $dom->createElement(self::TAG_ROOT);
     $dom->appendChild($modelsElement);
     foreach ($models as $model) {
         $modelElement = $this->getElementFromModel($dom, $model);
         if ($modelElement != null) {
             $importedModelElement = $dom->importNode($modelElement, true);
             $modelsElement->appendChild($importedModelElement);
         }
     }
     $dom->save($file);
 }
Exemplo n.º 2
0
 /**
  * Write modules to the provided path
  * @param zibo\library\filesystem\File $path Path to write the modules definitions to
  * @param array $modules Array with Module instances
  * @return null
  */
 public function writeModules(File $path, array $modules)
 {
     $dom = new Document('1.0', 'utf-8');
     $dom->formatOutput = true;
     $dom->setSchemaFileFromConfig(self::CONFIG_MODULES_SCHEMA);
     $modulesElement = $dom->createElementNS(self::XML_NAMESPACE, self::TAG_MODULES);
     $modulesElement->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', self::XML_NAMESPACE . ' ' . self::XML_NAMESPACE . ' ');
     $dom->appendChild($modulesElement);
     foreach ($modules as $namespace => $names) {
         foreach ($names as $name => $module) {
             $moduleElement = $this->getModuleElementFromModule($dom, $module, self::TAG_MODULE);
             $modulesElement->appendChild($moduleElement);
         }
     }
     $path->create();
     $file = new File($path, self::MODULE_FILE);
     $dom->save($file->getPath());
 }
Exemplo n.º 3
0
 /**
  * Reads the index of this repository
  * @return null
  */
 private function readIndexFile()
 {
     $indexFile = new File($this->directory, self::INDEX_FILE);
     $dom = new Document('1.0', 'utf-8');
     $dom->formatOutput = true;
     $dom->preserveWhiteSpace = false;
     if (!$indexFile->exists()) {
         Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, 'Initializing new index file', $indexFile, 0, RepositoryModule::LOG_NAME);
         $modulesElement = $dom->createElement(RepositoryModule::TAG_MODULES);
         $repositoryElement = $dom->createElement(RepositoryModule::TAG_REPOSITORY);
         $repositoryElement->appendChild($modulesElement);
         $dom->appendChild($repositoryElement);
     } else {
         $dom->setRelaxNGFileFromConfig(self::CONFIG_REPOSITORY_RNG);
         $success = @$dom->load($indexFile);
         if (!$success) {
             $error = error_get_last();
             throw new ZiboException("Failed loading {$indexFile} into a DOM tree: " . $error['message']);
         }
     }
     $this->indexDom = $dom;
 }