Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / EventManager / FilterChain.php
bloba2703602866ec9abb1db096455823bcbcbd568f7
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\EventManager;
12 use Zend\Stdlib\CallbackHandler;
14 /**
15 * FilterChain: intercepting filter manager
17 class FilterChain implements Filter\FilterInterface
19 /**
20 * @var Filter\FilterIterator All filters
22 protected $filters;
24 /**
25 * Constructor
27 * Initializes Filter\FilterIterator in which filters will be aggregated
29 public function __construct()
31 $this->filters = new Filter\FilterIterator();
34 /**
35 * Apply the filters
37 * Begins iteration of the filters.
39 * @param mixed $context Object under observation
40 * @param mixed $argv Associative array of arguments
41 * @return mixed
43 public function run($context, array $argv = array())
45 $chain = clone $this->getFilters();
47 if ($chain->isEmpty()) {
48 return;
51 $next = $chain->extract();
52 if (!$next instanceof CallbackHandler) {
53 return;
56 return call_user_func($next->getCallback(), $context, $argv, $chain);
59 /**
60 * Connect a filter to the chain
62 * @param callable $callback PHP Callback
63 * @param int $priority Priority in the queue at which to execute; defaults to 1 (higher numbers == higher priority)
64 * @return CallbackHandler (to allow later unsubscribe)
65 * @throws Exception\InvalidCallbackException
67 public function attach($callback, $priority = 1)
69 if (empty($callback)) {
70 throw new Exception\InvalidCallbackException('No callback provided');
72 $filter = new CallbackHandler($callback, array('priority' => $priority));
73 $this->filters->insert($filter, $priority);
74 return $filter;
77 /**
78 * Detach a filter from the chain
80 * @param CallbackHandler $filter
81 * @return bool Returns true if filter found and unsubscribed; returns false otherwise
83 public function detach(CallbackHandler $filter)
85 return $this->filters->remove($filter);
88 /**
89 * Retrieve all filters
91 * @return Filter\FilterIterator
93 public function getFilters()
95 return $this->filters;
98 /**
99 * Clear all filters
101 * @return void
103 public function clearFilters()
105 $this->filters = new Filter\FilterIterator();
109 * Return current responses
111 * Only available while the chain is still being iterated. Returns the
112 * current ResponseCollection.
114 * @return null|ResponseCollection
116 public function getResponses()
118 return null;