sfPluginInstallTask.class.php 4.3 KB

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