Merged in Phergie changes

This commit is contained in:
Luke Fitzgerald 2010-08-07 16:31:30 -07:00
parent 4b12b8f396
commit a9d9e077ba
6 changed files with 55 additions and 25 deletions

View File

@ -109,7 +109,7 @@ class Phergie_Plugin_Command extends Phergie_Plugin_Abstract
// Resolve aliases to their corresponding commands // Resolve aliases to their corresponding commands
$aliases = $this->getConfig('command.aliases', array()); $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) { if ($result) {
$command = $aliases[array_shift($result)]; $command = $aliases[array_shift($result)];
} }

View File

@ -110,4 +110,11 @@ class Phergie_Plugin_Exception extends Phergie_Exception
* plugin * plugin
*/ */
const ERR_FATAL_ERROR = 13; 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;
} }

View File

@ -69,12 +69,12 @@ class Phergie_Plugin_Handler implements IteratorAggregate, Countable
protected $events; protected $events;
/** /**
* Iterator used for selectively proxying method calls to contained * Name of the class to use for iterating over all currently loaded
* plugins * plugins
* *
* @var Iterator * @var string
*/ */
protected $iterator; protected $iteratorClass = 'Phergie_Plugin_Iterator';
/** /**
* Constructor to initialize class properties and add the path for core * 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() public function getIterator()
{ {
if (empty($this->iterator)) { return new $this->iteratorClass(
$this->iterator = new Phergie_Plugin_Iterator(
new ArrayIterator($this->plugins) new ArrayIterator($this->plugins)
); );
} }
return $this->iterator;
}
/** /**
* 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; $valid = true;
return $this;
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;
} }
/** /**

View File

@ -46,6 +46,22 @@ class Phergie_Plugin_Iterator extends FilterIterator
*/ */
protected $methods = array(); 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. * Adds to a list of plugins to exclude when iterating.
* *

View File

@ -236,7 +236,7 @@ REGEX;
$fixedKarma = $this->fetchFixedKarma($canonicalTerm); $fixedKarma = $this->fetchFixedKarma($canonicalTerm);
if ($fixedKarma) { if ($fixedKarma) {
$message = $nick . ': ' . $term . $fixedKarma . '.'; $message = $nick . ': ' . $term . ' ' . $fixedKarma . '.';
$this->doPrivmsg($source, $message); $this->doPrivmsg($source, $message);
return; return;
} }

View File

@ -53,15 +53,7 @@ class Phergie_Plugin_Php extends Phergie_Plugin_Abstract
} }
$this->getPluginHandler()->getPlugin('Command'); $this->getPluginHandler()->getPlugin('Command');
}
/**
* Initializes the data source.
*
* @return void
*/
public function onConnect()
{
$this->source = new Phergie_Plugin_Php_Source_Local; $this->source = new Phergie_Plugin_Php_Source_Local;
} }