filters = new Zend_EventManager_Filter_FilterIterator(); } /** * Apply the filters * * Begins iteration of the filters. * * @param mixed $context Object under observation * @param mixed $argv Associative array of arguments * @return mixed */ public function run($context, array $argv = array()) { $chain = clone $this->getFilters(); if ($chain->isEmpty()) { return; } $next = $chain->extract(); if (!$next instanceof Zend_Stdlib_CallbackHandler) { return; } return call_user_func($next->getCallback(), $context, $argv, $chain); } /** * Connect a filter to the chain * * @param callback $callback PHP Callback * @param int $priority Priority in the queue at which to execute; defaults to 1 (higher numbers == higher priority) * @throws Zend_Stdlib_Exception_InvalidCallbackException * @return Zend_Stdlib_CallbackHandler (to allow later unsubscribe) */ public function attach($callback, $priority = 1) { if (empty($callback)) { #require_once 'Zend/Stdlib/Exception/InvalidCallbackException.php'; throw new Zend_Stdlib_Exception_InvalidCallbackException('No callback provided'); } $filter = new Zend_Stdlib_CallbackHandler($callback, array('priority' => $priority)); $this->filters->insert($filter, $priority); return $filter; } /** * Detach a filter from the chain * * @param Zend_Stdlib_CallbackHandler $filter * @return bool Returns true if filter found and unsubscribed; returns false otherwise */ public function detach(Zend_Stdlib_CallbackHandler $filter) { return $this->filters->remove($filter); } /** * Retrieve all filters * * @return Zend_EventManager_Filter_FilterIterator */ public function getFilters() { return $this->filters; } /** * Clear all filters * * @return void */ public function clearFilters() { $this->filters = new Zend_EventManager_Filter_FilterIterator(); } /** * Return current responses * * Only available while the chain is still being iterated. Returns the * current ResponseCollection. * * @return null|Zend_EventManager_ResponseCollection */ public function getResponses() { return $this->responses; } }