Example #1
0
 function __construct($package, \PEAR2\Pyrus\Package $parent, \PEAR2\Pyrus\PackageFile $info = null)
 {
     $this->archive = $package;
     if ($info === null) {
         $info = new \PEAR2\Pyrus\PackageFile($package);
     }
     parent::__construct($info, $parent);
 }
Example #2
0
 function __construct(\PEAR2\Pyrus\PackageFile $packagefile, $parent = null, \PEAR2\Pyrus\Registry $registry)
 {
     $this->registry = $registry;
     parent::__construct($packagefile, $parent);
 }
Example #3
0
    /**
     * @param string $package path to package file
     */
    function __construct($package, \PEAR2\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 \PEAR2\Pyrus\PackageFile($pxml,
                                                       'PEAR2\Pyrus\PackageFile\v2'),
                            $parent);
    }