]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/Prioritize.php
Merge remote branch 'statusnet/1.0.x' into irc-plugin
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / Prioritize.php
1 <?php
2 /**
3  * Phergie 
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
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
13  *
14  * @category  Phergie 
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
20  */
21
22 /**
23  * Prioritizes events such that they are executed in order from least to most 
24  * destructive.
25  *
26  * @category Phergie 
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
31  */
32 class Phergie_Plugin_Prioritize extends Phergie_Plugin_Abstract
33 {
34     /** 
35      * Event types ordered by priority of execution
36      *
37      * @var array
38      */
39     protected $priority = array(
40         'raw',
41         'pass',
42         'user',
43         'ping',
44         'pong',
45         'notice',
46         'join',
47         'list',
48         'names',
49         'version',
50         'stats',
51         'links',
52         'time',
53         'trace',
54         'admin',
55         'info',
56         'who',
57         'whois',
58         'whowas',
59         'mode',
60         'privmsg',
61         'action',
62         'nick',
63         'topic',
64         'invite',
65         'kill',
66         'part',
67         'quit'
68     );  
69
70     /**
71      * Prioritizes events from least to most destructive. 
72      *
73      * @return void 
74      */
75     public function preDispatch()
76     {
77         $events = $this->getEventHandler();
78
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();
85             }
86             $categorized[$type][] = $event;
87         }
88
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]);
94         }
95
96         // Replace the original events array with the prioritized one
97         $events->replaceEvents($prioritized);
98     }
99 }