Development

/branches/1.4/lib/task/plugin/sfPluginPublishAssetsTask.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/task/plugin/sfPluginPublishAssetsTask.class.php

Revision 23922, 2.9 kB (checked in by fabien, 5 years ago)

[1.4] removed deprecated stuff

  • Property svn:mergeinfo set to
  • 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) 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  * Publishes Web Assets for Core and third party plugins
15  *
16  * @package    symfony
17  * @subpackage task
18  * @author     Fabian Lange <fabian.lange@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPluginPublishAssetsTask extends sfPluginBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addArguments(array(
29       new sfCommandArgument('plugins', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'Publish this plugin\'s assets'),
30     ));
31
32     $this->addOptions(array(
33       new sfCommandOption('core-only', '', sfCommandOption::PARAMETER_NONE, 'If set only core plugins will publish their assets'),
34     ));
35
36     $this->namespace = 'plugin';
37     $this->name = 'publish-assets';
38
39     $this->briefDescription = 'Publishes web assets for all plugins';
40
41     $this->detailedDescription = <<<EOF
42 The [plugin:publish-assets|INFO] task will publish web assets from all plugins.
43
44   [./symfony plugin:publish-assets|INFO]
45
46 In fact this will send the [plugin.post_install|INFO] event to each plugin.
47
48 You can specify which plugin or plugins should install their assets by passing
49 those plugins' names as arguments:
50
51   [./symfony plugin:publish-assets sfDoctrinePlugin|INFO]
52 EOF;
53   }
54
55   /**
56    * @see sfTask
57    */
58   protected function execute($arguments = array(), $options = array())
59   {
60     $enabledPlugins = $this->configuration->getPlugins();
61
62     if ($diff = array_diff($arguments['plugins'], $enabledPlugins))
63     {
64       throw new InvalidArgumentException('Plugin(s) not found: '.join(', ', $diff));
65     }
66
67     if ($options['core-only'])
68     {
69       $corePlugins = sfFinder::type('dir')->relative()->maxdepth(0)->in($this->configuration->getSymfonyLibDir().'/plugins');
70       $arguments['plugins'] = array_unique(array_merge($arguments['plugins'], array_intersect($enabledPlugins, $corePlugins)));
71     }
72     else if (!count($arguments['plugins']))
73     {
74       $arguments['plugins'] = $enabledPlugins;
75     }
76
77     foreach ($arguments['plugins'] as $plugin)
78     {
79       $pluginConfiguration = $this->configuration->getPluginConfiguration($plugin);
80
81       $this->logSection('plugin', 'Configuring plugin - '.$plugin);
82       $this->installPluginAssets($plugin, $pluginConfiguration->getRootDir());
83     }
84   }
85
86   /**
87    * Installs web content for a plugin.
88    *
89    * @param string $plugin The plugin name
90    * @param string $dir    The plugin directory
91    */
92   protected function installPluginAssets($plugin, $dir)
93   {
94     $webDir = $dir.DIRECTORY_SEPARATOR.'web';
95
96     if (is_dir($webDir))
97     {
98       $this->getFilesystem()->relativeSymlink($webDir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin, true);
99     }
100   }
101 }
102
Note: See TracBrowser for help on using the browser.