/** * * */ function __construct($fileOrXml, $urls = null) { //io::out('Package __construct: '.(is_null($urls)?$fileOrXml:implode(', ',$urls))); $this->xml = new DomDocument(); try { if ($fileOrXml instanceof iFile) { $packageFile = $fileOrXml; if (!$packageFile->exists()) { throw new PackageException('PackageFile(' . $packageFile . ') not exists.'); } $tmpDir = Dir::get(Config::getInstance()->root_dir, true)->getDir(Config::getInstance()->temp_dir); $xmlFile = Packer::unpackFile($packageFile, $tmpDir, 'package.xml'); $this->xml->load($xmlFile); $this->file = $packageFile; $this->status = $this->determineStatus(); } else { if (!is_array($urls) || count($urls) == 0) { throw new PackageException('Cant create package: list of URLs not set or empty.'); } $this->urls = $urls; $this->xml->appendChild($this->xml->importNode($fileOrXml, true)); $this->status = Package::FOUNDED; } // TODO Валидировать xml-schemas $this->name = $this->xml->getElementsByTagName('name')->item(0)->nodeValue; $this->version = $this->xml->getElementsByTagName('version')->item(0)->nodeValue; } catch (DOMException $e) { throw PackageException('Error while processing or parsing xml file with Message:' . $e->getMessage()); } }