From a9d9e077ba5ddc516836f00e667fc92235bed48d Mon Sep 17 00:00:00 2001 From: Luke Fitzgerald Date: Sat, 7 Aug 2010 16:31:30 -0700 Subject: [PATCH] Merged in Phergie changes --- .../extlib/phergie/Phergie/Plugin/Command.php | 2 +- .../phergie/Phergie/Plugin/Exception.php | 7 +++ .../extlib/phergie/Phergie/Plugin/Handler.php | 45 ++++++++++++------- .../phergie/Phergie/Plugin/Iterator.php | 16 +++++++ .../extlib/phergie/Phergie/Plugin/Karma.php | 2 +- .../Irc/extlib/phergie/Phergie/Plugin/Php.php | 8 ---- 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Command.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Command.php index 5c0a52e916..2058977ed5 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Command.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Command.php @@ -109,7 +109,7 @@ class Phergie_Plugin_Command extends Phergie_Plugin_Abstract // Resolve aliases to their corresponding commands $aliases = $this->getConfig('command.aliases', array()); - $result = preg_grep('/^' . $command . '$/i', array_keys($aliases)); + $result = preg_grep('/^' . preg_quote($command, '/') . '$/i', array_keys($aliases)); if ($result) { $command = $aliases[array_shift($result)]; } diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Exception.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Exception.php index fd07d9d5ea..ca4d53fede 100755 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Exception.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Exception.php @@ -110,4 +110,11 @@ class Phergie_Plugin_Exception extends Phergie_Exception * plugin */ const ERR_FATAL_ERROR = 13; + + /** + * Error indicating that a class specified to be used for iterating + * plugins cannot be found by the autoloader or does not extend + * FilterIterator + */ + const ERR_INVALID_ITERATOR_CLASS = 14; } diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Handler.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Handler.php index 13d2eac8fe..335c10f881 100755 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Handler.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Handler.php @@ -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 @@ -424,25 +424,40 @@ 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 { + $r = new ReflectionClass($class); + $valid = $r->isSubclassOf('FilterIterator'); + } catch (ReflectionException $e) { + $valid = false; + } + + if (!$valid) { + throw new Phergie_Plugin_Exception( + $e->getMessage(), + Phergie_Plugin_Exception::ERR_INVALID_ITERATOR_CLASS + ); + } + + $this->iteratorClass = $class; } /** diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php index 5963300713..d610962986 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php @@ -46,6 +46,22 @@ class Phergie_Plugin_Iterator extends FilterIterator */ protected $methods = array(); + /** + * Overrides the parent constructor to reset the internal iterator's + * pointer to the current item, which the parent class errantly does not + * do. + * + * @param Iterator $iterator Iterator to filter + * + * @return void + * @link http://bugs.php.net/bug.php?id=52560 + */ + public function __construct(Iterator $iterator) + { + parent::__construct($iterator); + $this->rewind(); + } + /** * Adds to a list of plugins to exclude when iterating. * diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php index f55f8d6edf..e6227be4a5 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php @@ -236,7 +236,7 @@ REGEX; $fixedKarma = $this->fetchFixedKarma($canonicalTerm); if ($fixedKarma) { - $message = $nick . ': ' . $term . $fixedKarma . '.'; + $message = $nick . ': ' . $term . ' ' . $fixedKarma . '.'; $this->doPrivmsg($source, $message); return; } diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Php.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Php.php index 94abfb031c..e10d101e73 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Php.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Php.php @@ -53,15 +53,7 @@ class Phergie_Plugin_Php extends Phergie_Plugin_Abstract } $this->getPluginHandler()->getPlugin('Command'); - } - /** - * Initializes the data source. - * - * @return void - */ - public function onConnect() - { $this->source = new Phergie_Plugin_Php_Source_Local; }