Development

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

You must first sign up to be able to contribute.

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

Revision 23810, 2.9 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • 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->aliases = array();
37     $this->namespace = 'plugin';
38     $this->name = 'publish-assets';
39
40     $this->briefDescription = 'Publishes web assets for all plugins';
41
42     $this->detailedDescription = <<<EOF
43 The [plugin:publish-assets|INFO] task will publish web assets from all plugins.
44
45   [./symfony plugin:publish-assets|INFO]
46
47 In fact this will send the [plugin.post_install|INFO] event to each plugin.
48
49 You can specify which plugin or plugins should install their assets by passing
50 those plugins' names as arguments:
51
52   [./symfony plugin:publish-assets sfDoctrinePlugin|INFO]
53 EOF;
54   }
55
56   /**
57    * @see sfTask
58    */
59   protected function execute($arguments = array(), $options = array())
60   {
61     $enabledPlugins = $this->configuration->getPlugins();
62
63     if ($diff = array_diff($arguments['plugins'], $enabledPlugins))
64     {
65       throw new InvalidArgumentException('Plugin(s) not found: '.join(', ', $diff));
66     }
67
68     if ($options['core-only'])
69     {
70       $corePlugins = sfFinder::type('dir')->relative()->maxdepth(0)->in($this->configuration->getSymfonyLibDir().'/plugins');
71       $arguments['plugins'] = array_unique(array_merge($arguments['plugins'], array_intersect($enabledPlugins, $corePlugins)));
72     }
73     else if (!count($arguments['plugins']))
74     {
75       $arguments['plugins'] = $enabledPlugins;
76     }
77
78     foreach ($arguments['plugins'] as $plugin)
79     {
80       $pluginConfiguration = $this->configuration->getPluginConfiguration($plugin);
81
82       $this->logSection('plugin', 'Configuring plugin - '.$plugin);
83       $this->installPluginAssets($plugin, $pluginConfiguration->getRootDir());
84     }
85   }
86
87   /**
88    * Installs web content for a plugin.
89    *
90    * @param string $plugin The plugin name
91    * @param string $dir    The plugin directory
92    */
93   protected function installPluginAssets($plugin, $dir)
94   {
95     $webDir = $dir.DIRECTORY_SEPARATOR.'web';
96
97     if (is_dir($webDir))
98     {
99       $this->getFilesystem()->relativeSymlink($webDir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin, true);
100     }
101   }
102 }
103
Note: See TracBrowser for help on using the browser.