Example #1
0
 function makePackage(\PEAR2\Pyrus\PackageFile\v2 $pf)
 {
     foreach ($pf->files as $name => $blah) {
         file_put_contents($this->__DIR__ . '/' . $name, 'hi');
     }
     file_put_contents($this->__DIR__ . '/package.xml', $pf);
     $package1 = new \PEAR2\Pyrus\Package(false);
     $xmlcontainer = new \PEAR2\Pyrus\PackageFile($pf);
     $xml = new \PEAR2\Pyrus\Package\Xml($this->__DIR__ . '/package.xml', $package1, $xmlcontainer);
     $package1->setInternalPackage($xml);
     $package1->archivefile = $this->__DIR__ . '/package.xml';
     $this->scs->saveRelease($package1, 'cellog');
     foreach ($pf->files as $name => $blah) {
         unlink($this->__DIR__ . '/' . $name);
     }
     unlink($this->__DIR__ . '/package.xml');
 }
 public static function install_pear_package($package, $channel = 'pear2.php.net', $upgrade_if_installed = true)
 {
     self::discover_channel($channel);
     $cfg = PEAR2\Pyrus\Config::current();
     $registry = $cfg->registry;
     $full_name = $channel . '/' . $package;
     $package = new PEAR2\Pyrus\Package($full_name);
     if (isset($registry->package[$full_name])) {
         if (true === $upgrade_if_installed and $package->isUpgradeable()) {
             $registry->replace($package);
         }
     } else {
         // install
         PEAR2\Pyrus\Installer::begin();
         PEAR2\Pyrus\Installer::prepare($package);
         PEAR2\Pyrus\Installer::commit();
         // $registry->package[] = $package;
     }
 }
Example #3
0
$pf->name = 'P1';
$pf->channel = 'pear2.php.net';
$pf->summary = 'testing';
$pf->version['release'] = '1.0.0';
$pf->stability['release'] = 'stable';
$pf->description = 'hi description';
$pf->notes = 'my notes';
$pf->maintainer['cellog']->role('lead')->email('*****@*****.**')->active('yes')->name('Greg Beaver');
$pf->files['glooby1'] = array('role' => 'php');

$pf->setPackagefile(__DIR__ . '/package.xml');

file_put_contents(__DIR__ . '/package.xml', $pf);

$package1 = new \PEAR2\Pyrus\Package(false);
$xmlcontainer = new \PEAR2\Pyrus\PackageFile($pf);
$xml = new \PEAR2\Pyrus\Package\Xml(__DIR__ . '/package.xml', $package1, $xmlcontainer);
$package1->setInternalPackage($xml);
$package1->archivefile = __DIR__ . '/package.xml';
$scs->saveRelease($package1, 'cellog', $cert[0], $cert[1]);

// clean up
unlink(dirname(__DIR__) . '/pearconfig.xml');
unlink(dirname(__DIR__) . '/.config');
for ($i = 1; $i <= 1; $i++) {
    unlink(__DIR__ . "/glooby$i");
}
unlink(__DIR__ . '/package.xml');
$dir = dirname(__DIR__) . '/.configsnapshots';
include __DIR__ . '/../../../clean.php.inc';
Example #4
0
 public function info($package, $channel, $field)
 {
     if (!$this->exists($package, $channel)) {
         throw new Exception('Unknown package ' . $channel . '/' . $package);
     }
     $packagefile = glob($this->_namePath($channel, $package) . DIRECTORY_SEPARATOR . '*.xml');
     if (!$packagefile || !isset($packagefile[0])) {
         throw new Exception('Cannot find registry for package ' . $channel . '/' . $package);
     }
     $packageobject = new \PEAR2\Pyrus\Package($packagefile[0]);
     if ($field === null) {
         return $packageobject->getInternalPackage()->getPackageFile()->getPackageFileObject();
     }
     if ($field == 'version') {
         $field = 'release-version';
     } elseif ($field == 'installedfiles') {
         $ret = array();
         try {
             $config = new \PEAR2\Pyrus\Config\Snapshot($packageobject->date . ' ' . $packageobject->time);
         } catch (\Exception $e) {
             throw new Exception('Cannot retrieve files, config ' . 'snapshot could not be processed', $e);
         }
         $roles = array();
         foreach (Role::getValidRoles($packageobject->getPackageType()) as $role) {
             // set up a list of file role => configuration variable
             // for storing in the registry
             $roles[$role] = Role::factory($packageobject->getPackageType(), $role);
         }
         $ret = array();
         foreach ($packageobject->installcontents as $file) {
             $relativepath = $roles[$file->role]->getRelativeLocation($packageobject, $file);
             if (!$relativepath) {
                 continue;
             }
             $filepath = $config->{$roles[$file->role]->getLocationConfig()} . DIRECTORY_SEPARATOR . $relativepath;
             $attrs = $file->getArrayCopy();
             $ret[$filepath] = $attrs['attribs'];
             $ret[$filepath]['installed_as'] = $filepath;
             $ret[$filepath]['relativepath'] = $relativepath;
             $ret[$filepath]['configpath'] = $config->{$roles[$file->role]->getLocationConfig()};
         }
         return $ret;
     } elseif ($field == 'dirtree') {
         $files = $this->info($package, $channel, 'installedfiles');
         foreach ($files as $file => $unused) {
             do {
                 $file = dirname($file);
                 if (strlen($file) > strlen($this->_path)) {
                     $ret[$file] = 1;
                 }
             } while (strlen($file) > strlen($this->_path));
         }
         $ret = array_keys($ret);
         usort($ret, 'strnatcasecmp');
         return array_reverse($ret);
     }
     return $packageobject->{$field};
 }
Example #5
0
 function validate()
 {
     $package = new \PEAR2\Pyrus\Package(false);
     $xmlcontainer = new \PEAR2\Pyrus\PackageFile($this->pxml);
     $xml = new \PEAR2\Pyrus\Package\Xml($this->path . '/package.xml', $package, $xmlcontainer);
     $package->setInternalPackage($xml);
     $this->pxml->getValidator()->validate($package);
 }
Example #6
0
$xmlcontainer = new \PEAR2\Pyrus\PackageFile($p32);
$xml = new \PEAR2\Pyrus\Package\Xml(__DIR__ . '/package.xml', $package3, $xmlcontainer);
$package3->setInternalPackage($xml);
file_put_contents(__DIR__ . '/package.xml', $p32);
$package3->archivefile = __DIR__ . '/package.xml';
$scs->saveRelease($package3, 'cellog');

$package3 = new \PEAR2\Pyrus\Package(false);
$xmlcontainer = new \PEAR2\Pyrus\PackageFile($p3);
$xml = new \PEAR2\Pyrus\Package\Xml(__DIR__ . '/package.xml', $package3, $xmlcontainer);
$package3->setInternalPackage($xml);
file_put_contents(__DIR__ . '/package.xml', $p3);
$package3->archivefile = __DIR__ . '/package.xml';
$scs->saveRelease($package3, 'cellog');

$package3 = new \PEAR2\Pyrus\Package(false);
$xmlcontainer = new \PEAR2\Pyrus\PackageFile($p3beta);
$xml = new \PEAR2\Pyrus\Package\Xml(__DIR__ . '/package.xml', $package3, $xmlcontainer);
$package3->setInternalPackage($xml);
file_put_contents(__DIR__ . '/package.xml', $p3beta);
$package3->archivefile = __DIR__ . '/package.xml';
$scs->saveRelease($package3, 'cellog');

// clean up
unlink(dirname(__DIR__) . '/pearconfig.xml');
unlink(dirname(__DIR__) . '/.config');
for ($i = 1; $i <= 3; $i++) {
    unlink(__DIR__ . "/glooby$i");
}
unlink(__DIR__ . '/package.xml');
$dir = dirname(__DIR__) . '/.configsnapshots';
Example #7
0
    public function installCustomRole()
    {
        $pf = new \PEAR2\Pyrus\PackageFile\v2;

        $pf->name = 'PyrusBundlePlugin';
        $pf->channel = 'pear2.php.net';
        $pf->summary = 'Local';
        $pf->description = 'Description';
        $pf->notes = 'My Notes';
        $pf->maintainer['naderman']->role('lead')->email('*****@*****.**')->active('yes')->name('Nils Adermann');
        $pf->files['Bundle.xml'] = array(
            'attribs' => array('role' => 'customrole'),
        );
        $pf->files['PyrusBundlePlugin/Role/Bundle.php'] = array(
            'attribs' => array('role' => 'php'),
        );

        $package_xml = __DIR__ . '/plugin/package.xml';
        $pf->setPackagefile($package_xml);

        $package = new \PEAR2\Pyrus\Package(false);
        $xmlcontainer = new \PEAR2\Pyrus\PackageFile($pf);
        $xml = new \PEAR2\Pyrus\Package\Xml($package_xml, $package, $xmlcontainer);
        $package->setInternalPackage($xml);
        \PEAR2\Pyrus\Main::$options['install-plugins'] = true;

        \PEAR2\Pyrus\Installer::begin();
        \PEAR2\Pyrus\Installer::prepare($package);
        \PEAR2\Pyrus\Installer::commit();

        $this->readConfig();
    }
Example #8
0
 function info($args, $options)
 {
     if (!$options['forceremote']) {
         if (file_exists($args['package'])) {
             $package = new \PEAR2\Pyrus\Package($args['package']);
             $installed = false;
         } elseif (isset(\PEAR2\Pyrus\Config::current()->registry->package[$args['package']])) {
             $package = \PEAR2\Pyrus\Config::current()->registry->package[$args['package']];
             $installed = true;
         }
     }
     if (!isset($package)) {
         $installed = false;
         $package = new \PEAR2\Pyrus\Package($args['package'], $options['forceremote']);
     }
     echo $this->wrap($package->name . ' (' . $package->channel . ' Channel)'), "\n";
     echo str_repeat('-', 80), "\n";
     // this next line ensures we get an accurate reading on a remote abstract package
     if (!$installed && $package->isRemote()) {
         $package->grabEntirePackagexml();
     }
     if (!isset($args['field'])) {
         echo 'Package type: ';
         switch ($package->type) {
             case 'php':
                 echo "PHP package\n";
                 break;
             case 'extsrc':
                 echo "Extension source package\n";
                 break;
             case 'zendextsrc':
                 echo "Zend Extension source package\n";
                 break;
             case 'extbin':
                 echo "Extension binary package\n";
                 break;
             case 'zendextbin':
                 echo "Zend Extension binary package\n";
                 break;
             case 'bundle':
                 echo "Package Bundle\n";
                 break;
         }
         echo 'Version:      ', $package->version['release'], ' (API ', $package->version['api'], "), ";
         echo 'Stability:    ', $package->stability['release'], ' (API ', $package->stability['api'], ")\n";
         echo 'Release Date: ', $package->date;
         if ($package->time) {
             echo ' ', $package->time;
         }
         echo "\n";
         echo "Package Summary: ", $this->columnWrap($package->summary, strlen("Package Summary: ")), "\n";
         echo "Package Description Excerpt:\n   ", $this->columnWrap(substr(rtrim($package->description), 0, 171) . '...', 3), "\n";
         echo '(`php pyrus.phar info ' . $args['package'] . " description` for full description)\n";
         echo "Release Notes Excerpt:\n   ", $this->columnWrap(substr(rtrim($package->notes), 0, 171) . '...', 3), "\n";
         echo '(`php pyrus.phar info ' . $args['package'] . " notes` for full release notes)\n";
         if ($installed) {
             // check for upgrades
             try {
                 $tester = new \PEAR2\Pyrus\Package($package->channel . '/' . $package->name, true);
                 $upgrades = $tester->getAllUpgrades($package->version['release']);
                 if (count($upgrades)) {
                     echo "Upgrades available:\n";
                     foreach ($upgrades as $info) {
                         echo '  Version ', $info['v'], ' (', $info['s'], ")\n";
                     }
                 }
             } catch (\Exception $e) {
                 // ignore problems here, no need to freak out if checking for upgrades fails
                 if ($this->verbose > 3) {
                     echo $e;
                 }
             }
         }
     } elseif ($args['field'] == 'description') {
         echo "Package Description:\n   ", $this->columnWrap(trim($package->description), 3), "\n";
     } elseif ($args['field'] == 'notes') {
         echo "Release Notes:\n   ", $this->columnWrap($package->notes, 3), "\n";
     } elseif ($args['field'] == 'files') {
         if ($installed) {
             echo "Package Files (installed):\n";
             foreach (\PEAR2\Pyrus\Config::current()->registry->info($package->name, $package->channel, 'installedfiles') as $file => $info) {
                 echo $file, ' (', $info['role'], ")\n";
             }
         } else {
             if ($package->isRemote()) {
                 echo "Package Files:\n";
                 foreach ($package->contents as $file) {
                     echo $file->name, ' (', $file->role, ")\n";
                 }
             } else {
                 echo "Package Files (as would be installed):\n";
                 foreach ($package->installcontents as $file) {
                     echo $file->name, ' (', $file->role, ")\n";
                 }
             }
         }
     } else {
         echo "Unknown sub-field ", $args['field'], " must be one of description, notes, or files\n";
     }
 }
Example #9
0
    protected function fromUrl($param, $saveparam = '')
    {
        $this->type = 'url';
        $dir = Config::current()->download_dir;
        try {
            $response = \PEAR2\Pyrus\Main::downloadWithProgress($param);
            if ($response->code != '200') {
                throw new Exception('Download failed, received ' . $response->code);
            }

            $info = parse_url($param);
            $name = urldecode(basename($info['path']));
            if (isset($response->headers['content-disposition'])) {
                if (preg_match('/filename="(.+)"/', $response->headers['content-disposition'], $match)) {
                    $name = $match[1];
                }
            }

            if (!@file_exists($dir)) {
                mkdir($dir, 0755, true);
            }

            if (false === file_put_contents($dir . DIRECTORY_SEPARATOR . $name, $response->body)) {
                throw new Exception('Unable to save package '.$name.' to downloads directory, '.$dir.'. Do we have permission to write there?');
            }

            // whew, download worked!
            $a = new \PEAR2\Pyrus\Package($dir . DIRECTORY_SEPARATOR . $name);
            return $a->getInternalPackage();
        } catch (\PEAR2\Pyrus\HTTPException $e) {
            throw $e; // pass it along
        } catch (\Exception $e) {
            if (!empty($saveparam)) {
                $saveparam = ", cannot download \"$saveparam\"";
            }
            throw new Exception('Could not download from "' . $param . '"' . $saveparam, $e);
        }
    }
Example #10
0
 /** @todo Consider simply injecting the Package object as appropriate */
 function package($frontend, $args, $options)
 {
     $path = getcwd() . DIRECTORY_SEPARATOR;
     $package = new \PEAR2\Pyrus\Package(null);
     if (!isset($args['packagexml']) && !file_exists($path . 'package.xml') && !file_exists($path . 'package2.xml')) {
         throw new \PEAR2\Pyrus\PackageFile\Exception("No package.xml or package2.xml found in " . $path);
     }
     if (isset($args['packagexml'])) {
         $package = new \PEAR2\Pyrus\Package($args['packagexml']);
     } else {
         // first try ./package.xml
         if (file_exists($path . 'package.xml')) {
             try {
                 $package = new \PEAR2\Pyrus\Package($path . 'package.xml');
             } catch (\PEAR2\Pyrus\PackageFile\Exception $e) {
                 if ($e->getCode() != -3) {
                     throw $e;
                 }
                 if (!file_exists($path . 'package2.xml')) {
                     throw $e;
                 }
                 $package = new \PEAR2\Pyrus\Package($path . 'package2.xml');
                 // now the creator knows to do the magic of package2.xml/package.xml
                 $package->thisIsOldAndCrustyCompatible();
             }
         }
         // Alternatively; there's only a package2.xml
         if (file_exists($path . 'package2.xml') && !file_exists($path . 'package.xml')) {
             $package = new \PEAR2\Pyrus\Package($path . 'package2.xml');
         }
     }
     if ($package->isNewPackage()) {
         if (!$options['phar'] && !$options['zip'] && !$options['tar'] && !$options['tgz']) {
             // try tgz first
             if (extension_loaded('zlib')) {
                 $options['tgz'] = true;
             } else {
                 $options['tar'] = true;
             }
         }
         if ($options['phar'] && ini_get('phar.readonly')) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception("Cannot create phar archive, pass -dphar.readonly=0");
         }
     } else {
         if ($options['zip'] || $options['phar']) {
             echo "Zip and Phar archives can only be created for PEAR2 packages, ignoring\n";
         }
         if (extension_loaded('zlib')) {
             $options['tgz'] = true;
         } else {
             $options['tar'] = true;
         }
     }
     // get openssl cert if set, and password
     if (\PEAR2\Pyrus\Config::current()->openssl_cert) {
         if ('yes' == $frontend->ask('Sign package?', array('yes', 'no'), 'yes')) {
             $cert = \PEAR2\Pyrus\Config::current()->openssl_cert;
             if (!file_exists($cert)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('OpenSSL certificate ' . $cert . ' does not exist');
             }
             $releaser = \PEAR2\Pyrus\Config::current()->handle;
             $maintainers = array();
             foreach ($package->maintainer as $maintainer) {
                 $maintainers[] = $maintainer->user;
             }
             if (!strlen($releaser)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('handle configuration variable must be from ' . 'package.xml (one of ' . implode(', ', $maintainers) . ')');
             }
             if (!in_array($releaser, $maintainers)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('handle configuration variable must be from ' . 'package.xml (one of ' . implode(', ', $maintainers) . ')');
             }
             $passphrase = $frontend->ask('passphrase for OpenSSL PKCS#12 certificate?');
             if (!$passphrase) {
                 $passphrase = '';
             }
         } else {
             $releaser = $cert = null;
             $passphrase = '';
         }
     } else {
         $releaser = $cert = null;
         $passphrase = '';
     }
     $sourcepath = \PEAR2\Pyrus\Main::getSourcePath();
     if (0 !== strpos($sourcepath, 'phar://')) {
         // running from svn, assume we're in a standard package layout with a vendor dir
         // TODO: Improve this to automatically find latest releases from pear2.php.net
         $exceptionpath = $autoloadpath = $multierrorspath = realpath($sourcepath . '/../../vendor/php') . '/PEAR2';
         if (!file_exists($exceptionpath . '/Exception.php')) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('Cannot locate PEAR2/Exception in a local vendor/ dir. ' . 'It is best to install the latest versions of these locally.');
         }
     } else {
         $exceptionpath = $autoloadpath = $multierrorspath = dirname($sourcepath) . '/PEAR2';
     }
     $extras = array();
     $stub = false;
     if ($options['tgz'] && extension_loaded('zlib')) {
         $mainfile = $package->name . '-' . $package->version['release'] . '.tgz';
         $mainformat = \Phar::TAR;
         $maincompress = \Phar::GZ;
     } elseif ($options['tgz']) {
         $options['tar'] = true;
     }
     if ($options['tar']) {
         if (isset($mainfile)) {
             $extras[] = array('tar', \Phar::TAR, \Phar::NONE);
         } else {
             $mainfile = $package->name . '-' . $package->version['release'] . '.tar';
             $mainformat = \Phar::TAR;
             $maincompress = \Phar::NONE;
         }
     }
     if ($options['phar']) {
         if (isset($mainfile)) {
             $extras[] = array('phar', \Phar::PHAR, \Phar::GZ);
         } else {
             $mainfile = $package->name . '-' . $package->version['release'] . '.phar';
             $mainformat = \Phar::PHAR;
             $maincompress = \Phar::NONE;
         }
         if (!$options['stub'] && file_exists(dirname($package->archivefile) . '/stub.php')) {
             $stub = file_get_contents(dirname($package->archivefile) . '/stub.php');
         } elseif ($options['stub'] && file_exists($options['stub'])) {
             $stub = file_get_contents($options['stub']);
         }
         $stub = str_replace('@PACKAGE_VERSION' . '@', $package->version['release'], $stub);
     }
     if ($options['zip']) {
         if (isset($mainfile)) {
             $extras[] = array('zip', \Phar::ZIP, \Phar::NONE);
         } else {
             $mainfile = $package->name . '-' . $package->version['release'] . '.zip';
             $mainformat = \Phar::ZIP;
             $maincompress = \Phar::NONE;
         }
     }
     if (isset($options['outputfile'])) {
         $mainfile = $options['outputfile'];
     }
     echo "Creating ", $mainfile, "\n";
     if (null == $cert) {
         $cloner = new \PEAR2\Pyrus\Package\Cloner($mainfile);
         $clone = $extras;
         $extras = array();
     } else {
         foreach ($extras as $stuff) {
             echo "Creating ", $package->name, '-', $package->version['release'], '.', $stuff[0], "\n";
         }
         $clone = array();
     }
     $creator = new \PEAR2\Pyrus\Package\Creator(array(new \PEAR2\Pyrus\Developer\Creator\Phar($mainfile, $stub, $mainformat, $maincompress, $extras, $releaser, $package, $cert, $passphrase)), $exceptionpath, $autoloadpath, $multierrorspath);
     if (!$options['extrasetup'] && file_exists(dirname($package->archivefile) . '/extrasetup.php')) {
         $options['extrasetup'] = 'extrasetup.php';
     }
     if ($options['extrasetup']) {
         // encapsulate the extrafiles inside a closure so there is no access to the variables in this function
         $getinfo = function () use($options, $package) {
             $file = $options['extrasetup'];
             if (!file_exists(dirname($package->archivefile) . '/' . $file)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file must be in the same directory as package.xml');
             }
             include dirname($package->archivefile) . '/' . $file;
             if (!isset($extrafiles)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file must set $extrafiles variable to an array of files');
             }
             if (!is_array($extrafiles)) {
                 throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file must set $extrafiles variable to an array of files');
             }
             foreach ($extrafiles as $path => $file) {
                 if (is_object($file)) {
                     if ($file instanceof \PEAR2\Pyrus\PackageInterface || $file instanceof \PEAR2\Pyrus\PackageFileInterface) {
                         continue;
                     }
                     throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file object must implement \\PEAR2\\Pyrus\\PackageInterface or \\PEAR2\\Pyrus\\PackageFileInterface');
                 }
                 if (!file_exists($file)) {
                     throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file ' . $file . ' does not exist');
                 }
                 if (!is_string($path)) {
                     throw new \PEAR2\Pyrus\Developer\Creator\Exception('extrasetup file ' . $file . ' index should be the path to save in the' . ' release');
                 }
             }
             return $extrafiles;
         };
         $extrafiles = $getinfo();
     } else {
         $extrafiles = array();
     }
     $creator->render($package, $extrafiles);
     if (count($clone)) {
         foreach ($clone as $extra) {
             echo "Creating ", $package->name, '-', $package->version['release'], '.', $extra[0], "\n";
             $cloner->{'to' . $extra[0]}();
         }
     }
     echo "done\n";
 }