コード例 #1
0
ファイル: Commands.php プロジェクト: helgi/Pyrus
 /**
  * install a local or remote package
  *
  * @param array $args
  */
 function install($args, $options)
 {
     if ($options['plugin']) {
         \Pyrus\Main::$options['install-plugins'] = true;
     }
     if ($options['force']) {
         \Pyrus\Main::$options['force'] = true;
     }
     if (isset($options['packagingroot']) && $options['packagingroot']) {
         \Pyrus\Main::$options['packagingroot'] = $options['packagingroot'];
     }
     if ($options['optionaldeps']) {
         \Pyrus\Main::$options['optionaldeps'] = $options['optionaldeps'];
     }
     \Pyrus\Installer::begin();
     try {
         $packages = array();
         foreach ($args['package'] as $arg) {
             \Pyrus\Installer::prepare($packages[] = new \Pyrus\Package($arg));
         }
         \Pyrus\Installer::commit();
         foreach (\Pyrus\Installer::getInstalledPackages() as $package) {
             echo 'Installed ' . $package->channel . '/' . $package->name . '-' . $package->version['release'] . "\n";
             if ($package->type === 'extsrc' || $package->type === 'zendextsrc') {
                 echo " ==> To build this PECL package, use the build command\n";
             }
         }
         $optionals = \Pyrus\Installer::getIgnoredOptionalDeps();
         if (count($optionals)) {
             echo "Optional dependencies that will not be installed, use --optionaldeps:\n";
         }
         foreach ($optionals as $dep => $packages) {
             echo $dep, ' depended on by ', implode(', ', array_keys($packages)), "\n";
         }
     } catch (\Exception $e) {
         if ($e instanceof \Pyrus\Channel\Exception && strpos($arg, '/') === false) {
             echo "Sorry there was an error retrieving " . \Pyrus\Config::current()->default_channel . "/{$arg} from the default channel\n";
         }
         // If this is an undiscovered channel, handle it gracefully
         if ($e instanceof \Pyrus\Package\Exception && $e->getPrevious() instanceof \Pyrus\ChannelRegistry\Exception && $e->getPrevious()->getPrevious() instanceof \Pyrus\ChannelRegistry\ParseException && $e->getPrevious()->getPrevious()->why == 'channel' && strpos($arg, '/') !== false) {
             $channel = substr($arg, 0, strrpos($arg, '/'));
             echo "Sorry, the channel \"{$channel}\" is unknown.\n";
             return $this->installUnknownChannelExceptionHandler($args, $options, $e, $channel);
         }
         if ($e instanceof \Pyrus\ChannelRegistry\Exception && $e->getPrevious() instanceof \Pyrus\ChannelRegistry\ParseException && $e->getPrevious()->why == 'channel' && preg_match('/^unknown channel \\"(.*)\\" in \\"(.*)\\"$/', $e->getPrevious()->getMessage(), $matches)) {
             echo "Sorry, {$arg} references an unknown channel {$matches[1]} for {$matches[2]}\n";
             return $this->installUnknownChannelExceptionHandler($args, $options, $e, $matches[1]);
         }
         $this->exceptionHandler($e);
         exit(1);
     }
 }