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 * Base class for obtaining and processing incoming events.
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
31 abstract class Phergie_Process_Abstract
34 * Current driver instance
36 * @var Phergie_Driver_Abstract
41 * Current connection handler instance
43 * @var Phergie_Connection_Handler
45 protected $connections;
48 * Current plugin handler instance
50 * @var Phergie_Plugin_Handler
55 * Current event handler instance
57 * @var Phergie_Event_Handler
62 * Current end-user interface instance
64 * @var Phergie_Ui_Abstract
69 * List of arguments for use within the instance
73 protected $options = array();
76 * Gets the required class refences from Phergie_Bot.
78 * @param Phergie_Bot $bot Current bot instance in use
79 * @param array $options Optional processor arguments
83 public function __construct(Phergie_Bot $bot, array $options = array())
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;
94 * Sends resulting outgoing events from ealier processing in handleEvents.
96 * @param Phergie_Connection $connection Active connection
100 protected function processEvents(Phergie_Connection $connection)
102 if (count($this->events)) {
103 $this->plugins->preDispatch();
104 foreach ($this->events as $event) {
105 $this->ui->onCommand($event, $connection);
107 $method = 'do' . ucfirst(strtolower($event->getType()));
108 call_user_func_array(
109 array($this->driver, $method),
110 $event->getArguments()
113 $this->plugins->postDispatch();
115 if ($this->events->hasEventOfType(Phergie_Event_Request::TYPE_QUIT)) {
116 $this->ui->onQuit($connection);
117 $this->connections->removeConnection($connection);
120 $this->events->clearEvents();
125 * Obtains and processes incoming events.
129 public abstract function handleEvents();