9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie
23 * Implements a filtering iterator for limiting executing of methods across
28 * @author Phergie Development Team <team@phergie.org>
29 * @license http://phergie.org/license New BSD License
30 * @link http://pear.phergie.org/package/Phergie
32 class Phergie_Plugin_Iterator extends FilterIterator
35 * List of short names of plugins to exclude when iterating
39 protected $plugins = array();
42 * List of method names where plugins with these methods will be
43 * excluded when iterating
47 protected $methods = array();
50 * Overrides the parent constructor to reset the internal iterator's
51 * pointer to the current item, which the parent class errantly does not
54 * @param Iterator $iterator Iterator to filter
57 * @link http://bugs.php.net/bug.php?id=52560
59 public function __construct(Iterator $iterator)
61 parent::__construct($iterator);
66 * Adds to a list of plugins to exclude when iterating.
68 * @param mixed $plugins String containing the short name of a single
69 * plugin to exclude or an array of short names of multiple
72 * @return Phergie_Plugin_Iterator Provides a fluent interface
74 public function addPluginFilter($plugins)
76 if (is_array($plugins)) {
77 $this->plugins = array_unique(
78 array_merge($this->plugins, $plugins)
81 $this->plugins[] = $plugins;
87 * Adds to a list of method names where plugins defining these methods
88 * will be excluded when iterating.
90 * @param mixed $methods String containing the name of a single method
91 * or an array containing the name of multiple methods
93 * @return Phergie_Plugin_Iterator Provides a fluent interface
95 public function addMethodFilter($methods)
97 if (is_array($methods)) {
98 $this->methods = array_merge($this->methods, $methods);
100 $this->methods[]= $methods;
106 * Clears any existing plugin and methods filters.
108 * @return Phergie_Plugin_Iterator Provides a fluent interface
110 public function clearFilters()
112 $this->plugins = array();
113 $this->methods = array();
117 * Implements FilterIterator::accept().
119 * @return boolean TRUE to include the current item in those by returned
120 * during iteration, FALSE otherwise
122 public function accept()
124 if (!$this->plugins && !$this->methods) {
128 $current = $this->current();
130 if (in_array($current->getName(), $this->plugins)) {
134 foreach ($this->methods as $method) {
135 if (method_exists($current, $method)) {