]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Process/Abstract.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Process / Abstract.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
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
20  */
21
22 /**
23  * Base class for obtaining and processing incoming events.
24  *
25  * @category Phergie
26  * @package  Phergie
27  * @author   Phergie Development Team <team@phergie.org>
28  * @license  http://phergie.org/license New BSD License
29  * @link     http://pear.phergie.org/package/Phergie
30  */
31 abstract class Phergie_Process_Abstract
32 {
33     /**
34      * Current driver instance
35      *
36      * @var Phergie_Driver_Abstract
37      */
38     protected $driver;
39
40     /**
41      * Current connection handler instance
42      *
43      * @var Phergie_Connection_Handler
44      */
45     protected $connections;
46
47     /**
48      * Current plugin handler instance
49      *
50      * @var Phergie_Plugin_Handler
51      */
52     protected $plugins;
53
54     /**
55      * Current event handler instance
56      *
57      * @var Phergie_Event_Handler
58      */
59     protected $events;
60
61     /**
62      * Current end-user interface instance
63      *
64      * @var Phergie_Ui_Abstract
65      */
66     protected $ui;
67
68     /**
69      * List of arguments for use within the instance
70      *
71      * @var array
72      */
73     protected $options = array();
74
75     /**
76      * Gets the required class refences from Phergie_Bot.
77      *
78      * @param Phergie_Bot $bot     Current bot instance in use
79      * @param array       $options Optional processor arguments
80      *
81      * @return void
82      */
83     public function __construct(Phergie_Bot $bot, array $options = array())
84     {
85         $this->driver = $bot->getDriver();
86         $this->plugins = $bot->getPluginHandler();
87         $this->connections = $bot->getConnectionHandler();
88         $this->events = $bot->getEventHandler();
89         $this->ui = $bot->getUi();
90         $this->options = $options;
91     }
92
93     /**
94      * Sends resulting outgoing events from ealier processing in handleEvents.
95      *
96      * @param Phergie_Connection $connection Active connection
97      *
98      * @return void
99      */
100     protected function processEvents(Phergie_Connection $connection)
101     {
102         $this->plugins->preDispatch();
103         if (count($this->events)) {
104             foreach ($this->events as $event) {
105                 $this->ui->onCommand($event, $connection);
106
107                 $method = 'do' . ucfirst(strtolower($event->getType()));
108                 call_user_func_array(
109                     array($this->driver, $method),
110                     $event->getArguments()
111                 );
112             }
113         }
114         $this->plugins->postDispatch();
115
116         if ($this->events->hasEventOfType(Phergie_Event_Request::TYPE_QUIT)) {
117             $this->ui->onQuit($connection);
118             $this->connections->removeConnection($connection);
119         }
120
121         $this->events->clearEvents();
122     }
123
124     /**
125      * Obtains and processes incoming events.
126      *
127      * @return void
128      */
129     public abstract function handleEvents();
130 }