Merged in Phergie changes
This commit is contained in:
parent
4b12b8f396
commit
a9d9e077ba
|
@ -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)];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -236,7 +236,7 @@ REGEX;
|
|||
|
||||
$fixedKarma = $this->fetchFixedKarma($canonicalTerm);
|
||||
if ($fixedKarma) {
|
||||
$message = $nick . ': ' . $term . $fixedKarma . '.';
|
||||
$message = $nick . ': ' . $term . ' ' . $fixedKarma . '.';
|
||||
$this->doPrivmsg($source, $message);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user