diff options
author | Luke Fitzgerald <lw.fitzgerald@googlemail.com> | 2010-08-07 16:31:30 -0700 |
---|---|---|
committer | Luke Fitzgerald <lw.fitzgerald@googlemail.com> | 2010-08-07 16:31:30 -0700 |
commit | a9d9e077ba5ddc516836f00e667fc92235bed48d (patch) | |
tree | ea07022094917113f27881c94e71a614bc93740b /plugins/Irc/extlib/phergie | |
parent | 4b12b8f396182cbd073429a7bfc2e6213a65a17a (diff) |
Merged in Phergie changes
Diffstat (limited to 'plugins/Irc/extlib/phergie')
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 5c0a52e91..2058977ed 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 fd07d9d5e..ca4d53fed 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 13d2eac8f..335c10f88 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 596330071..d61096298 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Iterator.php @@ -47,6 +47,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. * * @param mixed $plugins String containing the short name of a single diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Karma.php index f55f8d6ed..e6227be4a 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 94abfb031..e10d101e7 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; } |