sfPluginPublishAssetsTask.class.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 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. * Publishes Web Assets for Core and third party plugins
  12. *
  13. * @package symfony
  14. * @subpackage task
  15. * @author Fabian Lange <fabian.lange@symfony-project.com>
  16. * @version SVN: $Id: sfPluginPublishAssetsTask.class.php 7655 2008-02-28 09:52:40Z fabien $
  17. */
  18. class sfPluginPublishAssetsTask extends sfPluginBaseTask
  19. {
  20. /**
  21. * @see sfTask
  22. */
  23. protected function configure()
  24. {
  25. $this->addOptions(array(
  26. new sfCommandOption('core-only', '', sfCommandOption::PARAMETER_NONE, 'If set only core plugins will publish their assets'),
  27. new sfCommandOption('symfony-lib-dir', '', sfCommandOption::PARAMETER_REQUIRED, 'The symfony lib dir'),
  28. ));
  29. $this->aliases = array();
  30. $this->namespace = 'plugin';
  31. $this->name = 'publish-assets';
  32. $this->briefDescription = 'Publishes web assets for all plugins';
  33. $this->detailedDescription = <<<EOF
  34. The [plugin:publish-assets|INFO] task will publish web assets from all plugins.
  35. [./symfony plugin:publish-assets|INFO]
  36. In fact this will send the [plugin.post_install|INFO] event to each plugin.
  37. EOF;
  38. }
  39. /**
  40. * @see sfTask
  41. */
  42. protected function execute($arguments = array(), $options = array())
  43. {
  44. $plugins = $this->configuration->getPlugins();
  45. foreach ($this->configuration->getAllPluginPaths() as $pluginName => $pluginPath)
  46. {
  47. if (!in_array($pluginName, $plugins) || ($options['core-only'] && dirname($pluginPath) != $this->configuration->getSymfonyLibDir().'/plugins'))
  48. {
  49. continue;
  50. }
  51. $this->logSection('plugin', 'Configuring plugin - '.$pluginName);
  52. $this->installPluginAssets($pluginName, $pluginPath);
  53. }
  54. }
  55. /**
  56. * Installs web content for a plugin.
  57. *
  58. * @param string $plugin The plugin name
  59. * @param string $dir The plugin directory
  60. */
  61. protected function installPluginAssets($plugin, $dir)
  62. {
  63. $webDir = $dir.DIRECTORY_SEPARATOR.'web';
  64. if (is_dir($webDir))
  65. {
  66. $filesystem = new sfFilesystem();
  67. $filesystem->relativeSymlink($webDir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin, true);
  68. }
  69. }
  70. }