/** * @param string $package path to package file */ function __construct($package, \Pyrus\Package $parent) { $package = realpath($package); if (!$package) { throw new Phar\Exception('Phar package ' . $package . ' does not exist'); } $pxml = false; $this->archive = $package; try { if (\Phar::isValidPharFilename($package, 1)) { $phar = new \Phar($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME); $pxml = 'phar://' . $package . '/' . $phar->getMetaData(); } else { $phar = new \PharData($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME); if ($phar->getMetaData()) { $pxml = 'phar://' . $package . '/' . $phar->getMetaData(); } } } catch (\Exception $e) { throw new Phar\Exception('Could not open Phar archive ' . $package, $e); } $package = str_replace('\\', '/', $package); try { if ($pxml === false) { $info = pathinfo($package); $internal = $info['filename']; if (isset($phar[$internal . '/.xmlregistry'])) { if ($phar instanceof \PharData) { $iterate = new \PharData('phar://' . $package . '/' . $internal . '/.xmlregistry'); } else { $iterate = new \Phar('phar://' . $package . '/' . $internal . '/.xmlregistry'); } foreach (new \RecursiveIteratorIterator($iterate, \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { $filename = $file->getFileName(); // default to new package.xml if (preg_match('@^(.+)\\-package.xml$@', $filename)) { $pxml = $file->getPathName(); break; } } } else { foreach (array('package2.xml', $internal . '/' . 'package2.xml', 'package.xml', $internal . '/' . 'package.xml') as $checkfile) { if (isset($phar[$checkfile])) { $this->_BCpackage = true; $pxml = $phar[$checkfile]->getPathName(); break; } } } } if ($pxml === false) { throw new Phar\Exception('No package.xml in archive'); } } catch (\Exception $e) { throw new Phar\Exception('Could not extract Phar archive ' . $package, $e); } parent::__construct(new \Pyrus\PackageFile($pxml, 'Pyrus\\PackageFile\\v2'), $parent); }
/** * Overloaded constructor * * @param string $path Path to the module package * * @return void */ public function __construct($path) { if (!\Includes\Utils\FileManager::isFileReadable($path)) { \Includes\ErrorHandler::fireError('Unable to read module package: "' . $path . '"'); } $this->setRepositoryPath($path); $module = new \PharData($this->getRepositoryPath()); $this->metadata = $module->getMetaData(); if (empty($this->metadata)) { \Includes\ErrorHandler::fireError('Unable to read module metadata: "' . $path . '"'); } parent::__construct(); }