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
15 * @package Phergie_Plugin_Prioritize
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_Plugin_Prioritize
23 * Prioritizes events such that they are executed in order from least to most
27 * @package Phergie_Plugin_Prioritize
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_Plugin_Prioritize
32 class Phergie_Plugin_Prioritize extends Phergie_Plugin_Abstract
35 * Event types ordered by priority of execution
39 protected $priority = array(
71 * Prioritizes events from least to most destructive.
75 public function preDispatch()
77 $events = $this->getEventHandler();
79 // Categorize events by type
80 $categorized = array();
81 foreach ($events as $event) {
82 $type = $event->getType();
83 if (!isset($categorized[$type])) {
84 $categorized[$type] = array();
86 $categorized[$type][] = $event;
89 // Order events by type from least to most destructive
90 $types = array_intersect($this->priority, array_keys($categorized));
91 $prioritized = array();
92 foreach ($types as $type) {
93 $prioritized = array_merge($prioritized, $categorized[$type]);
96 // Replace the original events array with the prioritized one
97 $events->replaceEvents($prioritized);