]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Irc/extlib/phergie/Phergie/Plugin/Handler.php
MINOR: Please don't set a+x on files which are not being executed as shell script...
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / Handler.php
old mode 100755 (executable)
new mode 100644 (file)
index 4304bef..c308658
@@ -69,12 +69,12 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
     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
@@ -98,6 +98,12 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
         $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_');
     }
 
@@ -134,6 +140,7 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
      * 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
@@ -142,7 +149,7 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
      */
     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(
@@ -336,7 +343,7 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
 
         $plugins = array();
         foreach ($names as $name) {
-            $plugins[$name] = $this->getPlugin($name);
+            $plugins[strtolower($name)] = $this->getPlugin($name);
         }
         return $plugins;
     }
@@ -424,25 +431,46 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
      */
     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;
     }
 
     /**