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 drivers which handle issuing client commands to the IRC
24 * server and converting responses into usable data objects.
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 abstract class Phergie_Driver_Abstract
35 * Currently active connection
37 * @var Phergie_Connection
39 protected $connection;
42 * Sets the currently active connection.
44 * @param Phergie_Connection $connection Active connection
46 * @return Phergie_Driver_Abstract Provides a fluent interface
48 public function setConnection(Phergie_Connection $connection)
50 $this->connection = $connection;
56 * Returns the currently active connection.
58 * @return Phergie_Connection
59 * @throws Phergie_Driver_Exception
61 public function getConnection()
63 if (empty($this->connection)) {
64 throw new Phergie_Driver_Exception(
65 'Operation requires an active connection, but none is set',
66 Phergie_Driver_Exception::ERR_NO_ACTIVE_CONNECTION
70 return $this->connection;
74 * Returns an event if one has been received from the server.
76 * @return Phergie_Event_Interface|null Event instance if an event has
77 * been received, NULL otherwise
79 public abstract function getEvent();
82 * Initiates a connection with the server.
86 public abstract function doConnect();
89 * Terminates the connection with the server.
91 * @param string $reason Reason for connection termination (optional)
94 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_1_6
96 public abstract function doQuit($reason = null);
101 * @param string $channels Comma-delimited list of channels to join
102 * @param string $keys Optional comma-delimited list of channel keys
105 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_1
107 public abstract function doJoin($channels, $keys = null);
112 * @param string $channels Comma-delimited list of channels to leave
115 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_2
117 public abstract function doPart($channels);
120 * Invites a user to an invite-only channel.
122 * @param string $nick Nick of the user to invite
123 * @param string $channel Name of the channel
126 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_7
128 public abstract function doInvite($nick, $channel);
131 * Obtains a list of nicks of users in specified channels.
133 * @param string $channels Comma-delimited list of one or more channels
136 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_5
138 public abstract function doNames($channels);
141 * Obtains a list of channel names and topics.
143 * @param string $channels Comma-delimited list of one or more channels
144 * to which the response should be restricted
148 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_6
150 public abstract function doList($channels = null);
153 * Retrieves or changes a channel topic.
155 * @param string $channel Name of the channel
156 * @param string $topic New topic to assign (optional)
159 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_4
161 public abstract function doTopic($channel, $topic = null);
164 * Retrieves or changes a channel or user mode.
166 * @param string $target Channel name or user nick
167 * @param string $mode New mode to assign (optional)
170 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_3
172 public abstract function doMode($target, $mode = null);
175 * Changes the client nick.
177 * @param string $nick New nick to assign
180 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_1_2
182 public abstract function doNick($nick);
185 * Retrieves information about a nick.
187 * @param string $nick Nick
190 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_5_2
192 public abstract function doWhois($nick);
195 * Sends a message to a nick or channel.
197 * @param string $target Channel name or user nick
198 * @param string $text Text of the message to send
201 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_4_1
203 public abstract function doPrivmsg($target, $text);
206 * Sends a notice to a nick or channel.
208 * @param string $target Channel name or user nick
209 * @param string $text Text of the notice to send
212 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_4_2
214 public abstract function doNotice($target, $text);
217 * Kicks a user from a channel.
219 * @param string $nick Nick of the user
220 * @param string $channel Channel name
221 * @param string $reason Reason for the kick (optional)
224 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2_8
226 public abstract function doKick($nick, $channel, $reason = null);
229 * Responds to a server test of client responsiveness.
231 * @param string $daemon Daemon from which the original request originates
234 * @link http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_6_3
236 public abstract function doPong($daemon);
239 * Sends a CTCP ACTION (/me) command to a nick or channel.
241 * @param string $target Channel name or user nick
242 * @param string $text Text of the action to perform
245 * @link http://www.invlogic.com/irc/ctcp.html#4.4
247 public abstract function doAction($target, $text);
250 * Sends a CTCP PING request to a user.
252 * @param string $nick User nick
253 * @param string $hash Hash to use in the handshake
256 * @link http://www.invlogic.com/irc/ctcp.html#4.2
258 public abstract function doPing($nick, $hash);
261 * Sends a CTCP VERSION request or response to a user.
263 * @param string $nick User nick
264 * @param string $version Version string to send for a response
267 * @link http://www.invlogic.com/irc/ctcp.html#4.1
269 public abstract function doVersion($nick, $version = null);
272 * Sends a CTCP TIME request to a user.
274 * @param string $nick User nick
275 * @param string $time Time string to send for a response
278 * @link http://www.invlogic.com/irc/ctcp.html#4.6
280 public abstract function doTime($nick, $time = null);
283 * Sends a CTCP FINGER request to a user.
285 * @param string $nick User nick
286 * @param string $finger Finger string to send for a response
289 * @link http://www.irchelp.org/irchelp/rfc/ctcpspec.html
291 public abstract function doFinger($nick, $finger = null);
294 * Sends a raw command to the server.
296 * @param string $command Command string to send
300 public abstract function doRaw($command);