sfSymfonyPluginManager.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /**
  10. * sfSymfonyPluginManager allows you to manage symfony plugins installation and uninstallation.
  11. *
  12. * @package symfony
  13. * @subpackage plugin
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfSymfonyPluginManager.class.php 9131 2008-05-21 04:12:00Z Carl.Vondrick $
  16. */
  17. class sfSymfonyPluginManager extends sfPluginManager
  18. {
  19. /**
  20. * Initializes this sfPluginManager instance.
  21. *
  22. * Available options:
  23. *
  24. * * web_dir: The directory where to plugins assets (images, stylesheets, javascripts, ...)
  25. *
  26. * See sfPluginManager for other options.
  27. *
  28. * @param sfEventDispatcher $dispatcher An event dispatcher instance
  29. * @param sfPearEnvironment $environment A sfPearEnvironment instance
  30. */
  31. public function initialize(sfEventDispatcher $dispatcher, sfPearEnvironment $environment)
  32. {
  33. parent::initialize($dispatcher, $environment);
  34. if (!$environment->getOption('web_dir'))
  35. {
  36. throw new sfPluginException('You must provide a "web_dir" option.');
  37. }
  38. }
  39. /**
  40. * Configures this plugin manager.
  41. */
  42. public function configure()
  43. {
  44. // register symfony channel
  45. $this->environment->registerChannel('pear.symfony-project.com', true);
  46. // register symfony plugins channel
  47. $this->environment->registerChannel('plugins.symfony-project.org', true);
  48. // register symfony for dependencies
  49. $this->registerSymfonyPackage();
  50. // register callbacks to manage web content
  51. $this->dispatcher->connect('plugin.post_install', array($this, 'ListenToPluginPostInstall'));
  52. $this->dispatcher->connect('plugin.pre_uninstall', array($this, 'ListenToPluginPostUninstall'));
  53. }
  54. /**
  55. * Installs web content for a plugin.
  56. *
  57. * @param string $plugin The plugin name
  58. */
  59. public function installWebContent($plugin)
  60. {
  61. $webDir = $this->environment->getOption('plugin_dir').DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'web';
  62. if (is_dir($webDir))
  63. {
  64. $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Installing web data for plugin')));
  65. $filesystem = new sfFilesystem();
  66. $filesystem->symlink($webDir, $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin, true);
  67. }
  68. }
  69. /**
  70. * Unnstalls web content for a plugin.
  71. *
  72. * @param string $plugin The plugin name
  73. */
  74. public function uninstallWebContent($plugin)
  75. {
  76. $targetDir = $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin;
  77. if (is_dir($targetDir))
  78. {
  79. $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Uninstalling web data for plugin')));
  80. $filesystem = new sfFilesystem();
  81. if (is_link($targetDir))
  82. {
  83. $filesystem->remove($targetDir);
  84. }
  85. else
  86. {
  87. $filesystem->remove(sfFinder::type('any')->in($targetDir));
  88. $filesystem->remove($targetDir);
  89. }
  90. }
  91. }
  92. /**
  93. * Listens to the plugin.post_install event.
  94. *
  95. * @param sfEvent $event An sfEvent instance
  96. */
  97. public function ListenToPluginPostInstall($event)
  98. {
  99. $this->installWebContent($event['plugin']);
  100. }
  101. /**
  102. * Listens to the plugin.post_uninstall event.
  103. *
  104. * @param sfEvent $event An sfEvent instance
  105. */
  106. public function ListenToPluginPostUninstall($event)
  107. {
  108. $this->uninstallWebContent($event['plugin']);
  109. }
  110. /**
  111. * Registers the symfony package for the current version.
  112. */
  113. protected function registerSymfonyPackage()
  114. {
  115. $symfony = new PEAR_PackageFile_v2_rw();
  116. $symfony->setPackage('symfony');
  117. $symfony->setChannel('pear.symfony-project.com');
  118. $symfony->setConfig($this->environment->getConfig());
  119. $symfony->setPackageType('php');
  120. $symfony->setAPIVersion('1.1.0');
  121. $symfony->setAPIStability('stable');
  122. $symfony->setReleaseVersion(preg_replace('/\-\w+$/', '', SYMFONY_VERSION));
  123. $symfony->setReleaseStability(false === strpos(SYMFONY_VERSION, 'DEV') ? 'stable' : 'beta');
  124. $symfony->setDate(date('Y-m-d'));
  125. $symfony->setDescription('symfony');
  126. $symfony->setSummary('symfony');
  127. $symfony->setLicense('MIT License');
  128. $symfony->clearContents();
  129. $symfony->resetFilelist();
  130. $symfony->addMaintainer('lead', 'fabpot', 'Fabien Potencier', 'fabien.potencier@symfony-project.com');
  131. $symfony->setNotes('-');
  132. $symfony->setPearinstallerDep('1.4.3');
  133. $symfony->setPhpDep('5.1.0');
  134. $this->environment->getRegistry()->deletePackage('symfony', 'pear.symfony-project.com');
  135. if (!$this->environment->getRegistry()->addPackage2($symfony))
  136. {
  137. throw new sfPluginException('Unable to register the symfony package');
  138. }
  139. }
  140. /**
  141. * Returns true if the plugin is comptatible with the dependency.
  142. *
  143. * @param array $dependency A dependency array
  144. *
  145. * @return Boolean true if the plugin is compatible, false otherwise
  146. */
  147. protected function isPluginCompatibleWithDependency($dependency)
  148. {
  149. if (isset($dependency['channel']) && 'symfony' == $dependency['name'] && 'pear.symfony-project.com' == $dependency['channel'])
  150. {
  151. return $this->checkDependency($dependency);
  152. }
  153. return true;
  154. }
  155. }