Skip to content

Instantly share code, notes, and snippets.

@hartym
Created September 11, 2009 09:00
Show Gist options
  • Save hartym/185169 to your computer and use it in GitHub Desktop.
Save hartym/185169 to your computer and use it in GitHub Desktop.
Index: test/unit/config/sfProjectConfigurationTest.php
===================================================================
--- test/unit/config/sfProjectConfigurationTest.php (revision 21889)
+++ test/unit/config/sfProjectConfigurationTest.php (working copy)
@@ -3,14 +3,14 @@
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
- *
+ *
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
-$t = new lime_test(4);
+$t = new lime_test(9);
class ProjectConfiguration extends sfProjectConfiguration
{
@@ -46,4 +46,35 @@
}
$configuration2 = new ProjectConfiguration2(dirname(__FILE__).'/../../functional/fixtures');
-$t->is_deeply($configuration2->getPlugins(), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->enablePlugins() can enable plugins passed as arguments instead of array');
\ No newline at end of file
+$t->is_deeply($configuration2->getPlugins(), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->enablePlugins() can enable plugins passed as arguments instead of array');
+
+$t->diag('->getPluginPaths(), ->getPluginPath()');
+
+$t->is_deeply(array_values(array_map('basename', $configuration2->getPluginPaths())), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->getPluginPaths() returns a path for each enabled plugin');
+
+try
+{
+ $t->is(basename($configuration2->getPluginPath('sfAutoloadPlugin')), 'sfAutoloadPlugin', '->getPluginPath() works with an enabled plugin.');
+}
+catch (InvalidArgumentException $e)
+{
+ $t->fail('->getPluginPath() works with an enabled plugin.');
+}
+
+try
+{
+ $configuration2->getPluginPath('sfNotExistingPlugin');
+
+ $t->fail('->getPluginPath() does not work with a disabled plugin.');
+}
+catch (InvalidArgumentException $e)
+{
+ $t->pass('->getPluginPath() does not work with a disabled plugin.');
+}
+
+
+$t->diag('->hasPlugin()');
+
+$t->is($configuration2->hasPlugin('sfAutoloadPlugin'), true, '->hasPlugin()');
+$t->is($configuration2->hasPlugin('sfNotAChancePlugin'), false, '->hasPlugin()');
+
Index: WHATS_NEW
===================================================================
--- WHATS_NEW (revision 21885)
+++ WHATS_NEW (working copy)
@@ -861,4 +861,16 @@
[php]
<?php echo get_slot('foo', 'bar') // will output 'bar' if slot 'foo' is not defined ?>
- <?php include_slot('foo', 'bar') // will output 'bar' if slot 'foo' is not defined ?>
\ No newline at end of file
+ <?php include_slot('foo', 'bar') // will output 'bar' if slot 'foo' is not defined ?>
+
+Project configuration
+---------------------
+
+The new ->getPluginPath() and ->hasPlugin() methods in project configuration
+class allows interaction between plugin dependencies. You can use it in your
+plugin's configuration classes to detect presence of other plugins, even if the
+plugin path is non standard.
+
+The ->getPluginPaths() method now returns an associative array, indexed by
+plugin name.
+
Index: lib/config/sfProjectConfiguration.class.php
===================================================================
--- lib/config/sfProjectConfiguration.class.php (revision 21885)
+++ lib/config/sfProjectConfiguration.class.php (working copy)
@@ -296,7 +296,7 @@
* Sets the enabled plugins.
*
* @param array $plugins An array of plugin names
- *
+ *
* @throws LogicException If plugins have already been loaded
*/
public function setPlugins(array $plugins)
@@ -329,7 +329,7 @@
$plugins = array($plugins);
}
}
-
+
$this->setPlugins(array_merge($this->plugins, $plugins));
}
@@ -337,7 +337,7 @@
* Disables a plugin.
*
* @param array|string $plugins A plugin name or a plugin list
- *
+ *
* @throws LogicException If plugins have already been loaded
*/
public function disablePlugins($plugins)
@@ -371,7 +371,7 @@
* Enabled all installed plugins except the one given as argument.
*
* @param array|string $plugins A plugin name or a plugin list
- *
+ *
* @throws LogicException If plugins have already been loaded
*/
public function enableAllPluginsExcept($plugins = array())
@@ -399,6 +399,17 @@
}
/**
+ * Checks if a plugin is enabled.
+ *
+ * @param string $plugin
+ * @return boolean
+ */
+ public function hasPlugin($plugin)
+ {
+ return in_array($plugin, $this->plugins);
+ }
+
+ /**
* Gets the paths plugin sub-directories, minding overloaded plugins.
*
* @param string $subPath The subdirectory to look for
@@ -444,7 +455,7 @@
{
if (isset($pluginPaths[$plugin]))
{
- $this->pluginPaths[''][] = $pluginPaths[$plugin];
+ $this->pluginPaths[''][$plugin] = $pluginPaths[$plugin];
}
else
{
@@ -456,8 +467,26 @@
}
/**
+ * Gets the path to plugin root director.
+ *
+ * @param string $plugin
+ * @return string
+ */
+ public function getPluginPath($plugin)
+ {
+ $pluginPaths = $this->getPluginPaths();
+
+ if (isset($pluginPaths[$plugin]))
+ {
+ return $pluginPaths[$plugin];
+ }
+
+ throw new InvalidArgumentException(sprintf('The plugin "%s" does not exist.', $plugin));
+ }
+
+ /**
* Returns an array of paths for all available plugins.
- *
+ *
* @return array
*/
public function getAllPluginPaths()
@@ -485,11 +514,11 @@
/**
* Manually sets the location of a particular plugin.
- *
+ *
* This method can be used to ease functional testing of plugins. It is not
* intended to support sharing plugins between projects, as many plugins
* save project specific code (to /lib/form/base, for example).
- *
+ *
* @param string $plugin
* @param string $path
*/
@@ -500,9 +529,9 @@
/**
* Returns the configuration for the requested plugin.
- *
+ *
* @param string $name
- *
+ *
* @return sfPluginConfiguration
*/
public function getPluginConfiguration($name)
@@ -552,7 +581,7 @@
/**
* Returns true if these is an active configuration.
- *
+ *
* @return boolean
*/
static public function hasActive()
@@ -562,7 +591,7 @@
/**
* Guesses the project root directory.
- *
+ *
* @return string
*/
static public function guessRootDir()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment