当前位置: 首页>>代码示例>>PHP>>正文


PHP PEAR_Installer::sortPackagesForInstall方法代码示例

本文整理汇总了PHP中PEAR_Installer::sortPackagesForInstall方法的典型用法代码示例。如果您正苦于以下问题:PHP PEAR_Installer::sortPackagesForInstall方法的具体用法?PHP PEAR_Installer::sortPackagesForInstall怎么用?PHP PEAR_Installer::sortPackagesForInstall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PEAR_Installer的用法示例。

在下文中一共展示了PEAR_Installer::sortPackagesForInstall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: doInstallPlugin

 /**
  * Installs a plugin
  *
  * @see installPlugin()
  */
 protected function doInstallPlugin($plugin, $options = array())
 {
     $channel = isset($options['channel']) ? $options['channel'] : $this->environment->getConfig()->get('default_channel');
     $stability = isset($options['stability']) ? $options['stability'] : $this->environment->getConfig()->get('preferred_state', null, $channel);
     $version = isset($options['version']) ? $options['version'] : null;
     $isPackage = true;
     if (0 === strpos($plugin, 'http://') || file_exists($plugin)) {
         if (0 === strpos($plugin, 'http://plugins.symfony-project.')) {
             throw new sfPluginException("You try to install a symfony 1.0 plugin.\nPlease read the help message of this task to know how to install a plugin for the current version of symfony.");
         }
         $download = $plugin;
         $isPackage = false;
     } else {
         if (false !== strpos($plugin, '/')) {
             list($channel, $plugin) = explode('/', $plugin);
         }
     }
     $this->dispatcher->notify(new sfEvent($this, 'plugin.pre_install', array('channel' => $channel, 'plugin' => $plugin, 'is_package' => $isPackage)));
     if ($isPackage) {
         $this->environment->getRest()->setChannel($channel);
         if (!preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $plugin)) {
             throw new sfPluginException(sprintf('Plugin name "%s" is not a valid package name', $plugin));
         }
         if (!$version) {
             $version = $this->getPluginVersion($plugin, $stability);
         } else {
             if (!$this->isPluginCompatible($plugin, $version)) {
                 throw new sfPluginDependencyException(sprintf('Plugin "%s" in version "%s" is not compatible with the current application', $plugin, $version));
             }
         }
         if (!preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $version)) {
             throw new sfPluginException(sprintf('Plugin version "%s" is not a valid version', $version));
         }
         $existing = $this->environment->getRegistry()->packageInfo($plugin, 'version', $channel);
         if (version_compare($existing, $version) === 0) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Plugin is already installed')));
             return true;
         }
         // skip if the plugin is already installing and we are here through a dependency)
         if (isset($this->installing[$channel . '/' . $plugin])) {
             return true;
         }
         // convert the plugin package into a discrete download URL
         $download = $this->environment->getRest()->getPluginDownloadURL($plugin, $version, $stability);
         if (PEAR::isError($download)) {
             throw new sfPluginException(sprintf('Problem downloading the plugin "%s": %s', $plugin, $download->getMessage()));
         }
     }
     // download the plugin and install
     $class = $this->environment->getOption('downloader_base_class');
     $downloader = new $class($this, array('upgrade' => true), $this->environment->getConfig());
     $this->installing[$channel . '/' . $plugin] = true;
     if ($isPackage) {
         $this->checkPluginDependencies($plugin, $version, isset($options['install_deps']) ? (bool) $options['install_deps'] : false);
     }
     // download the actual URL to the plugin
     $downloaded = $downloader->download(array($download));
     if (PEAR::isError($downloaded)) {
         throw new sfPluginException(sprintf('Problem when downloading "%s": %s', $download, $downloaded->getMessage()));
     }
     $errors = $downloader->getErrorMsgs();
     if (count($errors)) {
         $err = array();
         foreach ($errors as $error) {
             $err[] = $error;
         }
         if (!count($downloaded)) {
             throw new sfPluginException(sprintf('Plugin "%s" installation failed: %s', $plugin, implode("\n", $err)));
         }
     }
     $pluginPackage = $downloaded[0];
     $installer = new PEAR_Installer($this);
     $installer->setOptions(array('upgrade' => true));
     $packages = array($pluginPackage);
     $installer->sortPackagesForInstall($packages);
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $err = $installer->setDownloadedPackages($packages);
     if (PEAR::isError($err)) {
         PEAR::staticPopErrorHandling();
         throw new sfPluginException($err->getMessage());
     }
     $info = $installer->install($pluginPackage, array('upgrade' => true));
     PEAR::staticPopErrorHandling();
     if (PEAR::isError($info)) {
         throw new sfPluginException(sprintf('Installation of "%s" plugin failed: %s', $plugin, $info->getMessage()));
     }
     if (is_array($info)) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Installation successful for plugin "%s"', $plugin))));
         $this->dispatcher->notify(new sfEvent($this, 'plugin.post_install', array('channel' => $channel, 'plugin' => $plugin)));
         unset($this->installing[$channel . '/' . $plugin]);
         return true;
     } else {
         throw new sfPluginException(sprintf('Installation of "%s" plugin failed', $plugin));
     }
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:100,代码来源:sfPluginManager.class.php



注:本文中的PEAR_Installer::sortPackagesForInstall方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。