Development

/branches/1.3/lib/task/plugin/sfPluginInstallTask.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/task/plugin/sfPluginInstallTask.class.php

Revision 21908, 4.2 kB (checked in by fabien, 5 years ago)

[1.3] made some optimizations by replacing is_null() by null ===

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