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