protected $events;
/**
- * Iterator used for selectively proxying method calls to contained
+ * Name of the class to use for iterating over all currently loaded
* plugins
*
- * @var Iterator
+ * @var string
*/
- protected $iterator;
+ protected $iteratorClass = 'Phergie_Plugin_Iterator';
/**
* Constructor to initialize class properties and add the path for core
$this->paths = array();
$this->autoload = false;
+ if (!empty($config['plugins.paths'])) {
+ foreach ($config['plugins.paths'] as $dir => $prefix) {
+ $this->addPath($dir, $prefix);
+ }
+ }
+
$this->addPath(dirname(__FILE__), 'Phergie_Plugin_');
}
* Returns metadata corresponding to a specified plugin.
*
* @param string $plugin Short name of the plugin class
+ *
* @throws Phergie_Plugin_Exception Class file can't be found
*
* @return array|boolean Associative array containing the path to the
*/
public function getPluginInfo($plugin)
{
- foreach (array_reverse($this->paths) as $path) {
+ foreach (array_reverse($this->paths) as $path) {
$file = $path['path'] . $plugin . '.php';
if (file_exists($file)) {
$path = array(
$plugins = array();
foreach ($names as $name) {
- $plugins[$name] = $this->getPlugin($name);
+ $plugins[strtolower($name)] = $this->getPlugin($name);
}
return $plugins;
}
*/
public function getIterator()
{
- if (empty($this->iterator)) {
- $this->iterator = new Phergie_Plugin_Iterator(
- new ArrayIterator($this->plugins)
- );
- }
- return $this->iterator;
+ return new $this->iteratorClass(
+ new ArrayIterator($this->plugins)
+ );
}
/**
- * Sets the iterator for all currently loaded plugin instances.
+ * Sets the iterator class used for all currently loaded plugin
+ * instances.
*
- * @param Iterator $iterator Plugin iterator
+ * @param string $class Name of a class that extends FilterIterator
*
- * @return Phergie_Plugin_Handler Provides a fluent interface
+ * @return Phergie_Plugin_Handler Provides a fluent API
+ * @throws Phergie_Plugin_Exception Class cannot be found or is not an
+ * FilterIterator-based class
*/
- public function setIterator(Iterator $iterator)
+ public function setIteratorClass($class)
{
- $this->iterator = $iterator;
- return $this;
+ $valid = true;
+
+ try {
+ $error_reporting = error_reporting(0); // ignore autoloader errors
+ $r = new ReflectionClass($class);
+ error_reporting($error_reporting);
+ if (!$r->isSubclassOf('FilterIterator')) {
+ $message = 'Class ' . $class . ' is not a subclass of FilterIterator';
+ $valid = false;
+ }
+ } catch (ReflectionException $e) {
+ $message = $e->getMessage();
+ $valid = false;
+ }
+
+ if (!$valid) {
+ throw new Phergie_Plugin_Exception(
+ $message,
+ Phergie_Plugin_Exception::ERR_INVALID_ITERATOR_CLASS
+ );
+ }
+
+ $this->iteratorClass = $class;
}
/**