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 * Adds to a list of plugins to exclude when iterating.
52 * @param mixed $plugins String containing the short name of a single
53 * plugin to exclude or an array of short names of multiple
56 * @return Phergie_Plugin_Iterator Provides a fluent interface
58 public function addPluginFilter($plugins)
60 if (is_array($plugins)) {
61 $this->plugins = array_unique(
62 array_merge($this->plugins, $plugins)
65 $this->plugins[] = $plugins;
71 * Adds to a list of method names where plugins defining these methods
72 * will be excluded when iterating.
74 * @param mixed $methods String containing the name of a single method
75 * or an array containing the name of multiple methods
77 * @return Phergie_Plugin_Iterator Provides a fluent interface
79 public function addMethodFilter($methods)
81 if (is_array($methods)) {
82 $this->methods = array_merge($this->methods, $methods);
84 $this->methods[]= $methods;
90 * Clears any existing plugin and methods filters.
92 * @return Phergie_Plugin_Iterator Provides a fluent interface
94 public function clearFilters()
96 $this->plugins = array();
97 $this->methods = array();
101 * Implements FilterIterator::accept().
103 * @return boolean TRUE to include the current item in those by returned
104 * during iteration, FALSE otherwise
106 public function accept()
108 if (!$this->plugins && !$this->methods) {
112 $current = $this->current();
114 if (in_array($current->getName(), $this->plugins)) {
118 foreach ($this->methods as $method) {
119 if (method_exists($current, $method)) {