1. sfPluginInstallTask.class.php
  2. /** * Installs a plugin. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfPluginInstallTask.class.php 23922 2009-11-14 14:58:38Z fabien $ */
  3. class sfPluginInstallTask extends sfPluginBaseTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addArguments(array(
  11. new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The plugin name'),
  12. ));
  13. $this->addOptions(array(
  14. new sfCommandOption('stability', 's', sfCommandOption::PARAMETER_REQUIRED, 'The preferred stability (stable, beta, alpha)', null),
  15. new sfCommandOption('release', 'r', sfCommandOption::PARAMETER_REQUIRED, 'The preferred version', null),
  16. new sfCommandOption('channel', 'c', sfCommandOption::PARAMETER_REQUIRED, 'The PEAR channel name', null),
  17. new sfCommandOption('install_deps', 'd', sfCommandOption::PARAMETER_NONE, 'Whether to force installation of required dependencies', null),
  18. new sfCommandOption('force-license', null, sfCommandOption::PARAMETER_NONE, 'Whether to force installation even if the license is not MIT like'),
  19. ));
  20. $this->namespace = 'plugin';
  21. $this->name = 'install';
  22. $this->briefDescription = 'Installs a plugin';
  23. $this->detailedDescription = <<<EOF
  24. The [plugin:install|INFO] task installs a plugin:
  25. [./symfony plugin:install sfGuardPlugin|INFO]
  26. By default, it installs the latest [stable|COMMENT] release.
  27. If you want to install a plugin that is not stable yet,
  28. use the [stability|COMMENT] option:
  29. [./symfony plugin:install --stability=beta sfGuardPlugin|INFO]
  30. [./symfony plugin:install -s beta sfGuardPlugin|INFO]
  31. You can also force the installation of a specific version:
  32. [./symfony plugin:install --release=1.0.0 sfGuardPlugin|INFO]
  33. [./symfony plugin:install -r 1.0.0 sfGuardPlugin|INFO]
  34. To force installation of all required dependencies, use the [install_deps|INFO] flag:
  35. [./symfony plugin:install --install-deps sfGuardPlugin|INFO]
  36. [./symfony plugin:install -d sfGuardPlugin|INFO]
  37. By default, the PEAR channel used is [symfony-plugins|INFO]
  38. (plugins.symfony-project.org).
  39. You can specify another channel with the [channel|COMMENT] option:
  40. [./symfony plugin:install --channel=mypearchannel sfGuardPlugin|INFO]
  41. [./symfony plugin:install -c mypearchannel sfGuardPlugin|INFO]
  42. You can also install PEAR packages hosted on a website:
  43. [./symfony plugin:install http://somewhere.example.com/sfGuardPlugin-1.0.0.tgz|INFO]
  44. Or local PEAR packages:
  45. [./symfony plugin:install /home/fabien/plugins/sfGuardPlugin-1.0.0.tgz|INFO]
  46. If the plugin contains some web content (images, stylesheets or javascripts),
  47. the task creates a [%name%|COMMENT] symbolic link for those assets under [web/|COMMENT].
  48. On Windows, the task copy all the files to the [web/%name%|COMMENT] directory.
  49. EOF;
  50. }
  51. /**
  52. * @see sfTask
  53. */
  54. protected function execute($arguments = array(), $options = array())
  55. {
  56. $this->logSection('plugin', sprintf('installing plugin "%s"', $arguments['name']));
  57. $options['version'] = $options['release'];
  58. unset($options['release']);
  59. // license compatible?
  60. if (!$options['force-license'])
  61. {
  62. try
  63. {
  64. $license = $this->getPluginManager()->getPluginLicense($arguments['name'], $options);
  65. }
  66. catch (Exception $e)
  67. {
  68. throw new sfCommandException(sprintf('%s (use --force-license to force installation)', $e->getMessage()));
  69. }
  70. if (false !== $license)
  71. {
  72. $temp = trim(str_replace('license', '', strtolower($license)));
  73. if (null !== $license && !in_array($temp, array('mit', 'bsd', 'lgpl', 'php', 'apache')))
  74. {
  75. throw new sfCommandException(sprintf('The license of this plugin "%s" is not MIT like (use --force-license to force installation).', $license));
  76. }
  77. }
  78. }
  79. $this->getPluginManager()->installPlugin($arguments['name'], $options);
  80. }
  81. }

Debug toolbar