Assembla home | Assembla project page
 

Changeset 57

Show
Ignore:
Timestamp:
02/12/08 05:39:20 (10 months ago)
Author:
tobias382
Message:

* Removed _ convention from non-public class properties
* Converted static properties in plugins to instance properties
* Modified base event handler class to cache short name
* Removed event parameter in base event handler methods, added setEvent method
to be called by the driver, modified streams driver to use it, and updated
method declarations in existing plugins accordingly
* Moved Event/Handler to Plugin and updated class names accordingly
* Changed Client/Driver interface to Driver/Abstract abstract class and updated
Bot accordingly
* Removed use of reflection API in Bot as it is not longer needed since abstract
plugin classes are not contained in the same directory as concrete plugin
classes
* Moved parseHostmask method from the streams driver to the abstract driver
* Consolidated connect and disconnect into run, removed isConnected, and added
enableDebugging and enableLogging in the streams and abstract driver classes
* Added automatic include_path updating to Bot and removed related instructions
for manually updating it from the README file
* Removed an unneeded argument from Event_Request::getArguments
* Created Plugin/Abstract to store abstract plugin classes (this commit is an
intermediary step to rename contained files)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Bot.php

    r56 r57  
    2828* @const string 
    2929*/ 
    30 define('PHERGIE_VERSION', '1.0.1'); 
     30define('PHERGIE_VERSION', '1.0.2'); 
    3131 
    3232/** 
     
    3737*/ 
    3838define('PHERGIE_INI', 'phergie.ini'); 
    39  
    40 /** 
    41 * @see Phergie_Client 
    42 */ 
    43 require_once 'Phergie/Client.php'; 
    4439 
    4540/** 
     
    10297if (isset($config['driver'])) { 
    10398    $driver = ucfirst(strtolower($config['driver'])); 
    104     require_once 'Phergie/Client/' . $driver . '.php'; 
    105     $class = 'Phergie_Client_' . $driver; 
    106     $client = new Phergie_Client($conn, new $class()); 
    10799} else { 
    108     $client = new Phergie_Client($conn)
     100    $driver = 'Streams'
    109101} 
     102require_once 'Phergie/Driver/' . $driver . '.php'; 
     103$client = new ${'Phergie_Driver_' . $driver}();  
    110104 
    111105foreach ($config as $setting => $value) { 
     
    135129/** 
    136130* Set up event handlers 
    137 * 
    138 * @todo Move abstract classes to a separate directory so reflection does not 
    139 *       have to be used here? 
    140131*/ 
    141 $iterator = new DirectoryIterator('Phergie/Event/Handler'); 
     132$iterator = new DirectoryIterator('Phergie/Plugin'); 
    142133foreach ($iterator as $entry) { 
    143134    if ($iterator->isFile() 
    144135        && substr($entry, -4) == '.php' 
    145136        && ($all xor in_array(substr($entry, 0, -4), $exclude))) { 
    146         require_once 'Phergie/Event/Handler/' . $entry; 
    147         $class = 'Phergie_Event_Handler_' . str_replace('.php', '', $entry); 
    148         $reflector = new ReflectionClass($class); 
    149         if ($reflector->isInstantiable()) { 
    150             $client->addEventHandler(new $class($client)); 
    151         } 
     137        require_once 'Phergie/Plugin/' . $entry; 
     138        $class = 'Phergie_Plugin_' . str_replace('.php', '', $entry); 
    152139    } 
    153140} 
  • trunk/Phergie/Connection.php

    r1 r57  
    1717    * @var string 
    1818    */ 
    19     protected $_server; 
     19    protected $server; 
    2020 
    2121    /** 
     
    2424    * @var int 
    2525    */ 
    26     protected $_port; 
     26    protected $port; 
    2727 
    2828    /** 
     
    3131    * @var string 
    3232    */ 
    33     protected $_username; 
     33    protected $username; 
    3434 
    3535    /** 
     
    3838    * @var string 
    3939    */ 
    40     protected $_realName; 
     40    protected $realName; 
    4141 
    4242    /** 
     
    4545    * @var string 
    4646    */ 
    47     protected $_nick; 
     47    protected $nick; 
    4848 
    4949    /** 
     
    5252    * @var string 
    5353    */ 
    54     protected $_password; 
     54    protected $password; 
    5555 
    5656    /** 
     
    5959    public function __construct() 
    6060    { 
    61         $this->_port = 6667; 
     61        $this->port = 6667; 
    6262    } 
    6363 
     
    6969    public function setServer($server) 
    7070    { 
    71         $this->_server = $server; 
     71        $this->server = $server; 
    7272    } 
    7373 
     
    7979    public function getServer() 
    8080    { 
    81         return $this->_server; 
     81        return $this->server; 
    8282    } 
    8383 
     
    9393        } 
    9494 
    95         $this->_port = $port; 
     95        $this->port = $port; 
    9696    } 
    9797     
     
    103103    public function getPort() 
    104104    { 
    105         return $this->_port; 
     105        return $this->port; 
    106106    } 
    107107 
     
    113113    public function setUsername($username) 
    114114    { 
    115         $this->_username = $username; 
     115        $this->username = $username; 
    116116    } 
    117117 
     
    123123    public function getUsername() 
    124124    { 
    125         return $this->_username; 
     125        return $this->username; 
    126126    } 
    127127 
     
    133133    public function setRealName($realName) 
    134134    { 
    135         $this->_realName = $realName; 
     135        $this->realName = $realName; 
    136136    } 
    137137 
     
    143143    public function getRealName() 
    144144    { 
    145         return $this->_realName; 
     145        return $this->realName; 
    146146    } 
    147147 
     
    153153    public function setNick($nick) 
    154154    { 
    155         $this->_nick = $nick; 
     155        $this->nick = $nick; 
    156156    } 
    157157 
     
    163163    public function getNick() 
    164164    { 
    165         return $this->_nick; 
     165        return $this->nick; 
    166166    } 
    167167 
     
    173173    public function setPassword($password) 
    174174    { 
    175         $this->_password = $password; 
     175        $this->password = $password; 
    176176    } 
    177177 
     
    183183    public function getPassword() 
    184184    { 
    185         return $this->_password; 
     185        return $this->password; 
    186186    } 
    187187} 
  • trunk/Phergie/Driver/Abstract.php

    r31 r57  
    2020* from IRC server. 
    2121*/ 
    22 interface Phergie_Client_Driver 
     22abstract class Phergie_Driver_Abstract 
    2323{ 
    2424    /** 
     25    * Associative array mapping configuration setting names to their 
     26    * respective values 
     27    * 
     28    * @var array 
     29    */ 
     30    protected $config; 
     31 
     32    /** 
     33    * Returns the value associated with a specified configuration setting. 
     34    * 
     35    * @param string $name Name of the setting 
     36    * @return string Value of the setting, or NULL if the setting is not set 
     37    */ 
     38    public final function getIni($name) 
     39    { 
     40        if (!isset($this->config[strtolower($name)])) { 
     41            return null; 
     42        } 
     43        return $this->config[strtolower($name)]; 
     44    } 
     45 
     46    /** 
     47    * Sets the value of a specified configuration setting, overwriting any 
     48    * existing value for that setting. 
     49    * 
     50    * @param string $name Name of the setting 
     51    * @param string $value New value for the setting 
     52    * @return void 
     53    */ 
     54    public final function setIni($name, $value) 
     55    { 
     56        $this->config[strtolower($name)] = $value; 
     57    } 
     58 
     59        /** 
     60         * Parses a IRC hostmask and sets nick, user and host bits 
     61         * 
     62         * @param string $hostmask Hostmask to parse 
     63         * @param string $nick Container for the nick  
     64         * @param string $user Container for the username  
     65         * @param string $host Container for the hostname  
     66         */ 
     67        public function parseHostmask($hostmask, &$nick, &$user, &$host) 
     68        { 
     69        if (preg_match('/^([^!@]+)!([^@]+)@(.*)$/', $hostmask, $match) > 0) { 
     70            list (, $nick, $user, $host) = $match; 
     71        } else { 
     72            $host = $hostmask; 
     73        } 
     74        } 
     75 
     76    /** 
    2577    * Adds a set of callbacks for events received from the server. 
    2678    * 
    2779    * @param Phergie_Event_Handler $handler 
    28     */ 
    29     public function addEventHandler(Phergie_Event_Handler $handler); 
    30  
    31     /** 
    32     * Establishes a connection to the server. 
    33     * 
    34     * @param Phergie_Connection $connection Connection information 
    35     * @throws Phergie_Exception A connectivity issue occurred 
    36     */ 
    37     public function connect(Phergie_Connection $connection); 
    38  
    39     /** 
    40     * Terminates any existing connection to the server. Note that this  
    41     * should never be used by an event handler; doQuit should be called  
    42     * instead. 
    43     */ 
    44     public function disconnect(); 
    45  
    46     /** 
    47     * Returns whether or not the client is currently connected to the server. 
    48     * 
    49     * @return TRUE if the client is connected, FALSE otherwise 
    50     */ 
    51     public function isConnected(); 
     80    * @return void 
     81    */ 
     82    public abstract function addEventHandler(Phergie_Event_Handler $handler); 
    5283 
    5384    /** 
     
    5586    * the server and processes them until the connection is terminated. 
    5687    * 
     88    * @param Phergie_Connection $conn Client connection information 
    5789    * @throws Phergie_Exception A runtime issue occurred 
    58     */ 
    59     public function run(); 
    60  
    61     /** 
    62     * Controls debugging output. 
    63     * 
    64     * @param string $message Debugging message 
    65     */ 
    66         public function debug($message); 
     90    * @return void 
     91    */ 
     92    public abstract function run(Phergie_Connection $conn); 
     93 
     94    /** 
     95    * Sends a debugging message to stdout or a log file depending on  
     96    * debugging settings. 
     97    * 
     98    * @param string $message Message to log 
     99    * @return void 
     100    */ 
     101    public abstract function debug($message); 
     102 
     103    /** 
     104    * Enables sending debugging output to stdout. 
     105    * 
     106    * @return void 
     107    */ 
     108        public abstract function enableDebugging(); 
     109 
     110    /** 
     111    * Enables sending debugging output to a specified file. 
     112    * 
     113    * @param string $path Path to the file 
     114    * @return void 
     115    */ 
     116    public abstract function enableLogging($path); 
    67117 
    68118    /** 
     
    70120    * 
    71121    * @param string $reason Reason for connection termination (optional) 
    72     */ 
    73     public function doQuit($reason = null); 
     122    * @return void 
     123    */ 
     124    public abstract function doQuit($reason = null); 
    74125 
    75126    /** 
     
    78129    * @param string $channel Name of the channel to join 
    79130    * @param string $keys Channel key if needed (optional) 
    80     */ 
    81     public function doJoin($channel, $key = null); 
     131    * @return void 
     132    */ 
     133    public abstract function doJoin($channel, $key = null); 
    82134 
    83135    /** 
     
    85137    * 
    86138    * @param string $channel Name of the channel to leave 
    87     */ 
    88     public function doPart($channel); 
     139    * @return void 
     140    */ 
     141    public abstract function doPart($channel); 
    89142 
    90143    /** 
     
    93146    * @param string $nick Nick of the user to invite 
    94147    * @param string $channel Name of the channel 
    95     */ 
    96     public function doInvite($nick, $channel); 
     148    * @return void 
     149    */ 
     150    public abstract function doInvite($nick, $channel); 
    97151 
    98152    /** 
     
    100154    * 
    101155    * @param string $channels Comma-delimited list of one or more channels 
    102     */ 
    103     public function doNames($channels); 
     156    * @return void 
     157    */ 
     158    public abstract function doNames($channels); 
    104159 
    105160    /** 
     
    109164    *                         to which the response should be restricted 
    110165    *                         (optional) 
    111     */ 
    112     public function doList($channels = null); 
     166    * @return void 
     167    */ 
     168    public abstract function doList($channels = null); 
    113169 
    114170    /** 
     
    117173    * @param string $channel Name of the channel 
    118174    * @param string $topic New topic to assign (optional) 
    119     */ 
    120     public function doTopic($channel, $topic = null); 
     175    * @return void 
     176    */ 
     177    public abstract function doTopic($channel, $topic = null); 
    121178 
    122179    /** 
     
    125182    * @param string $target Channel name or user nick 
    126183    * @param string $mode New mode to assign (optional) 
    127     */ 
    128     public function doMode($target, $mode = null); 
     184    * @return void 
     185    */ 
     186    public abstract function doMode($target, $mode = null); 
    129187 
    130188    /** 
     
    132190    * 
    133191    * @param string $nick New nick to assign 
    134     */ 
    135     public function doNick($nick); 
     192    * @return void 
     193    */ 
     194    public abstract function doNick($nick); 
    136195 
    137196    /** 
     
    139198    * 
    140199    * @param string $nick 
    141     */ 
    142     public function doWhois($nick); 
     200    * @return void 
     201    */ 
     202    public abstract function doWhois($nick); 
    143203 
    144204    /** 
     
    147207    * @param string $target Channel name or user nick 
    148208    * @param string $text Text of the message to send 
    149     */ 
    150     public function doPrivmsg($target, $text); 
     209    * @return void 
     210    */ 
     211    public abstract function doPrivmsg($target, $text); 
    151212 
    152213    /** 
     
    155216    * @param string $target Channel name or user nick 
    156217    * @param string $text Text of the notice to send 
    157     */ 
    158     public function doNotice($target, $text); 
     218    * @return void 
     219    */ 
     220    public abstract function doNotice($target, $text); 
    159221 
    160222    /** 
     
    164226    * @param string $channel Channel name 
    165227    * @param string $reason Reason for the kick (optional) 
    166     */ 
    167     public function doKick($nick, $channel, $reason = null); 
     228    * @return void 
     229    */ 
     230    public abstract function doKick($nick, $channel, $reason = null); 
    168231 
    169232    /** 
     
    171234    * 
    172235    * @param string $daemon Daemon from which the original request originates 
    173     */ 
    174     public function doPong($daemon); 
     236    * @return void 
     237    */ 
     238    public abstract function doPong($daemon); 
    175239 
    176240    /** 
     
    179243    * @param string $target Channel name or user nick 
    180244    * @param string $text Text of the action to perform 
    181     */ 
    182     public function doCtcpAction($target, $text);  
     245    * @return void 
     246    */ 
     247    public abstract function doCtcpAction($target, $text);  
    183248} 
  • trunk/Phergie/Driver/Streams.php

    r42 r57  
    22 
    33/** 
    4 * @see Phergie_Client_Driver 
     4* @see Phergie_Driver_Abstract 
    55*/ 
    6 require_once 'Phergie/Client/Driver.php'; 
     6require_once 'Phergie/Driver/Abstract.php'; 
    77 
    88/** 
    99* Provides a socket-based client driver. 
    1010*/ 
    11 class Phergie_Client_Streams implements Phergie_Client_Driver 
     11class Phergie_Driver_Streams extends Phergie_Driver_Abstract  
    1212{ 
    13     /** 
    14     * Flag to enable debugging mode 
    15     * 
    16     * @var bool 
    17     */ 
    18     protected static $_debug = true; 
    19  
    20         /** 
    21          * Define the logfile, nothing will be logged if set to null 
    22          * 
    23          * @var null|string 
    24          */ 
    25         protected static $_log = null; 
    26  
    2713    /** 
    2814    * Names of commands that can be issued by callbacks ordered by 
     
    3117    * @var array 
    3218    */ 
    33     protected static $_priority = array( 
     19    protected $priority = array( 
    3420        'pass', 
    3521        'nick', 
     
    5945 
    6046    /** 
     47    * Flag to enable debugging mode 
     48    * 
     49    * @var bool 
     50    */ 
     51    protected $debug; 
     52 
     53        /** 
     54         * Define the logfile, nothing will be logged if set to null 
     55         * 
     56         * @var null|string 
     57         */ 
     58        protected $log; 
     59 
     60    /** 
    6161    * Flag indicating whether or not the client is currently connected to 
    6262    * the server 
     
    6464    * @var bool 
    6565    */ 
    66     protected $_connected; 
     66    protected $connected; 
    6767 
    6868    /** 
     
    7171    * @var resource 
    7272    */ 
    73     protected $_socket; 
     73    protected $socket; 
    7474 
    7575    /** 
     
    7878    * @var array 
    7979    */ 
    80     protected $_handlers; 
     80    protected $handlers; 
    8181 
    8282    /** 
     
    8686    * @var bool 
    8787    */ 
    88     protected $_queueing; 
     88    protected $queueing; 
    8989 
    9090    /** 
     
    9494    * @var array 
    9595    */ 
    96     protected $_queue; 
     96    protected $queue; 
    9797 
    9898    /** 
     
    101101    public function __construct() 
    102102    { 
    103         $this->_connected = false; 
    104         $this->_handlers = array(); 
    105         $this->_queueing = false; 
    106         $this->_queue = array(); 
    107     } 
    108  
    109     /** 
    110     * Controls debugging output. 
    111     * 
    112     * @param string $message Debugging message 
     103        $this->debug = false; 
     104        $this->log = null; 
     105        $this->connected = false; 
     106        $this->handlers = array(); 
     107        $this->queueing = false; 
     108        $this->queue = array(); 
     109    } 
     110 
     111    /** 
     112    * Sends a debugging message to stdout or a log file depending on  
     113    * debugging settings. 
     114    * 
     115    * @param string $message Message to log 
     116    * @return void 
    113117    */ 
    114118    public function debug($message) 
    115119    { 
    116         if (self::$_debug) { 
     120        if ($this->debug) { 
    117121            echo $message . "\n"; 
    118122        } 
    119         if (self::$_log) { 
    120                 file_put_contents(self::$_log, $message."\n", FILE_APPEND); 
     123        if ($this->log) { 
     124                file_put_contents($this->log, $message."\n", FILE_APPEND); 
    121125        } 
    122126    } 
    123127 
    124128    /** 
     129    * Enables sending debugging output to stdout. 
     130    * 
     131    * @return void 
     132    */ 
     133        public function enableDebugging() 
     134    { 
     135        $this->debug = true; 
     136    } 
     137 
     138    /** 
     139    * Enables sending debugging output to a specified file. 
     140    * 
     141    * @param string $path Path to the file 
     142    * @return void 
     143    */ 
     144    public function enableLogging($path) 
     145    { 
     146        $this->log = $path; 
     147    } 
     148 
     149    /** 
    125150    * Adds a set of callbacks for events received from the server. 
    126151    * 
     
    131156        $handler->init(); 
    132157 
    133         $this->_handlers[] = $handler; 
    134     } 
    135  
    136     /** 
    137     * Establishes a connection to the server. 
    138     * 
    139     * @param Phergie_Connection $connection 
    140     */ 
    141     public function connect(Phergie_Connection $connection) 
    142     { 
    143         $server = $connection->getServer(); 
    144         $port = $connection->getPort(); 
    145         $username = $connection->getUsername(); 
    146         $realName = $connection->getRealName(); 
    147         $password = $connection->getPassword(); 
    148  
    149         $this->_socket = stream_socket_client('tcp://' . $server . ':' . $port, $errno, $errstr); 
    150  
    151         if ($this->_socket === false) { 
    152             throw new Phergie_Exception('Socket error occurred: ' . $errno . ' ' . $errstr); 
    153         } 
    154  
    155         if ($password !== null) { 
    156             $this->send('PASS', array($password)); 
    157         } 
    158         $this->send('USER', array($username, $server, $server, $realName)); 
    159         $this->doNick($connection->getNick()); 
    160  
    161         $this->_connected = true; 
    162     } 
    163  
    164     /** 
    165     * Terminates any existing connection to the server. 
    166     */ 
    167     public function disconnect() 
    168     { 
    169         if ($this->_connected) { 
    170             fclose($this->_socket); 
    171             $this->_connected = false; 
    172         } 
    173     } 
    174  
    175     /** 
    176     * Returns whether or not the client is currently connected to the server. 
    177     * 
    178     * @return TRUE if the client is connected, FALSE otherwise 
    179     */ 
    180     public function isConnected() 
    181     { 
    182        return $this->_connected; 
     158        $this->handlers[] = $handler; 
    183159    } 
    184160 
     
    186162    * Executes a continuous loop in which the client listens for events from 
    187163    * the server and processes them until the connection is terminated. 
    188     */ 
    189     public function run() 
    190     { 
    191         while($this->isConnected()) { 
    192             $this->_queue = array(); 
    193             $this->_queueing = true; 
     164    * 
     165    * @param Phergie_Connection $conn Client connection information 
     166    * @throws Phergie_Exception A runtime issue occurred 
     167    * @return void 
     168    */ 
     169    public function run(Phergie_Connection $conn) 
     170    { 
     171        $server = $conn->getServer(); 
     172 
     173        $this->socket = stream_socket_client('tcp://' . $server . ':' . $conn->getPort(), $errno, $errstr); 
     174        if ($this->socket === false) { 
     175            throw new Phergie_Exception('Socket error occurred: ' . $errno . ' ' . $errstr); 
     176        } 
     177 
     178        if ($password !== null) { 
     179            $this->send('PASS', array($conn->getPassword())); 
     180        } 
     181 
     182        $this->send('USER', array($conn->getUsername(), $server, $server, $conn->getRealName())); 
     183        $this->doNick($conn->getNick()); 
     184 
     185        $this->connected = true; 
     186        unset($server); 
     187 
     188        while($this->connected) { 
     189            $this->queue = array(); 
     190            $this->queueing = true; 
    194191            $event = $this->receive(); 
    195             if ($event instanceof Phergie_Event_Response) { 
    196                 foreach ($this->_handlers as $handler) { 
    197                     $handler->onResponse($event); 
     192            foreach ($this->handlers as $handler) { 
     193                $handler->setEvent($event); 
     194                if ($event instanceof Phergie_Event_Response) { 
     195                    $handler->onResponse(); 
     196                } else { 
     197                    $handler->${'on' . ucfirst($event->getType())}(); 
    198198                } 
    199             } else { 
    200                 foreach ($this->_handlers as $handler) { 
    201                     $method = 'on' . ucfirst($event->getType()); 
    202                     $handler->$method($event); 
    203                 } 
    204             } 
    205             $this->_queueing = false; 
    206             foreach (self::$_priority as $command) { 
    207                 if (isset($this->_queue[$command])) { 
    208                     foreach ($this->_queue[$command] as $arguments) { 
     199            } 
     200            $this->queueing = false; 
     201            foreach ($this->priority as $command) { 
     202                if (isset($this->queue[$command])) { 
     203                    foreach ($this->queue[$command] as $arguments) { 
    209204                        $this->send($command, $arguments); 
    210205                    } 
    211206                } 
    212207            } 
    213             if (isset($this->_queue['quit'])) { 
    214                 if (count($this->_queue['quit'][0]) > 0) { 
    215                     $reason = $this->_queue['quit'][0][0]; 
     208            if (isset($this->queue['quit'])) { 
     209                if (count($this->queue['quit'][0]) > 0) { 
     210                    $reason = $this->queue['quit'][0][0]; 
    216211                } else { 
    217212                    $reason = null; 
    218213                } 
    219                 foreach ($this->_handlers as $handler) { 
     214                foreach ($this->handlers as $handler) { 
    220215                    $handler->shutdown(); 
    221216                } 
    222217                $this->doQuit($reason); 
    223                 $this->disconnect(); 
    224             } 
    225             unset($this->_queue, $event, $command, $arguments); 
     218                fclose($this->socket); 
     219                $this->connected = false; 
     220            } 
     221            unset($this->queue, $event, $command, $arguments); 
    226222        } 
    227223    } 
     
    250246        $buffer = ''; 
    251247        while (empty ($buffer)) { 
    252             $buffer = rtrim(fgets($this->_socket)); 
     248            $buffer = rtrim(fgets($this->socket)); 
    253249        } 
    254250        $this->debug('server -> ' . $buffer); 
     
    310306    public function send($command, array $arguments = array()) 
    311307    { 
    312         if ($this->_queueing) { 
    313             if (!isset($this->_queue[$command])) { 
    314                 $this->_queue[$command] = array(); 
    315             } 
    316             $this->_queue[$command][] = $arguments; 
     308        if ($this->queueing) { 
     309            if (!isset($this->queue[$command])) { 
     310                $this->queue[$command] = array(); 
     311            } 
     312            $this->queue[$command][] = $arguments; 
    317313        } else { 
    318314            $buffer = strtoupper($command); 
     
    322318                $buffer .= ' ' . implode(' ', $arguments); 
    323319            } 
    324             fwrite($this->_socket, $buffer . "\r\n"); 
     320            fwrite($this->socket, $buffer . "\r\n"); 
    325321            $this->debug('client -> ' . $buffer); 
    326322        } 
    327323    } 
    328  
    329         /** 
    330          * Parses a IRC host mask and sets nick, user and host bits 
    331          * 
    332          * @param string $hostmask Hostmask to parse 
    333          * @param string $nick This variable will be filled with the nick part 
    334          * @param string $user This variable will be filled with the user part 
    335          * @param string $host This variable will be filled with the host part 
    336          */ 
    337         public function parseHostmask($hostmask, &$nick, &$user, &$host) 
    338         { 
    339         if (preg_match('/^([^!@]+)!([^@]+)@(.*)$/', $hostmask, $match) > 0) { 
    340             list (, $nick, $user, $host) = $match; 
    341         } else { 
    342             $host = $hostmask; 
    343         } 
    344         } 
    345324 
    346325    /** 
     
    369348 
    370349        $this->send(Phergie_Event_Request::TYPE_JOIN, $arguments); 
    371  
    372         unset($arguments); 
    373350    } 
    374351 
     
    420397 
    421398        $this->send(Phergie_Event_Request::TYPE_LIST, $arguments); 
    422  
    423         unset($arguments); 
    424399    } 
    425400 
     
    439414 
    440415        $this->send(Phergie_Event_Request::TYPE_TOPIC, $arguments); 
    441  
    442         unset($arguments); 
    443416    } 
    444417 
     
    458431 
    459432        $this->send(Phergie_Event_Request::TYPE_MODE, $arguments); 
    460  
    461         unset($arguments); 
    462433    } 
    463434 
     
    520491 
    521492        $this->send(Phergie_Event_Request::TYPE_KICK, $arguments); 
    522  
    523         unset($arguments); 
    524493    } 
    525494 
  • trunk/Phergie/Event/Handler.php

    r43 r57  
    22 
    33/** 
    4 * @see Phergie_Clien
    5 */ 
    6 require_once 'Phergie/Client.php'; 
     4* @see Phergie_Driver_Abstrac
     5*/ 
     6require_once 'Phergie/Driver/Abstract.php'; 
    77 
    88/** 
     
    2525    * Reference back to the client used to initiate commands 
    2626    * 
    27     * @var Phergie_Client 
    28     */ 
    29     protected $_client; 
     27    * @var Phergie_Driver_Abstract 
     28    */ 
     29    protected $client; 
     30 
     31    /** 
     32    * Short class name 
     33    * 
     34    * @var string 
     35    */ 
     36    protected $name; 
     37 
     38    /** 
     39    * Last intercepted event 
     40    * 
     41    * @var Phergie_Event_Request|Phergie_Event_Response 
     42    */ 
     43    protected $event; 
    3044 
    3145    /** 
    3246    * Sets a reference to the client used to initiate commands. 
    3347    * 
    34     * @param Phergie_Client $client 
    35     */ 
    36     final public function __construct(Phergie_Client $client) 
    37     { 
    38         $this->_client = $client; 
     48    * @param Phergie_Driver_Abstract $client 
     49    * @return void 
     50    */ 
     51    final public function __construct(Phergie_Driver_Abstract $client) 
     52    { 
     53        $this->client = $client; 
     54         
     55        $name = get_class($this); 
     56        $this->name = substr($name, strrpos($name, '_') + 1); 
    3957    } 
    4058 
     
    4664    public function getName() 
    4765    { 
    48         return substr(get_class($this), 22); 
     66        return $this->name;  
    4967    } 
    5068 
     
    5573    * @param string $plugin Name of the plugin, defaults to the current  
    5674    *                       plugin (optional) 
    57     * @return string Value of the setting 
     75    * @return string 
    5876    */ 
    5977    public function getIni($setting, $plugin = null) 
     
    6280            $plugin = $this->getName();  
    6381        } 
    64         $value = $this->_client->getIni($plugin . '.' . $setting); 
     82        $value = $this->client->getIni($plugin . '.' . $setting); 
    6583        if (!$value) { 
    66             $value = $this->_client->getIni($setting); 
     84            $value = $this->client->getIni($setting); 
    6785        } 
    6886        return $value;  
     
    7694    * @param string $plugin Name of the plugin, defaults to the current  
    7795    *                       plugin (optional) 
     96    * @return void 
    7897    */ 
    7998    public function setIni($setting, $value, $plugin = null) 
     
    82101            $plugin = $this->getName(); 
    83102        } 
    84         $this->_client->setIni($plugin . '.' . $setting, $value); 
     103        $this->client->setIni($plugin . '.' . $setting, $value); 
     104    } 
     105 
     106    /** 
     107    * Stores the last intercepted event. Should only be called by drivers. 
     108    * 
     109    * @param Phergie_Event_Request|Phergie_Event_Response $event 
     110    * @return void 
     111    */ 
     112    public function setEvent($event) 
     113    { 
     114        $this->event = $event; 
     115    } 
     116 
     117    /** 
     118    * Returns the channel name or user nick representing the source of the  
     119    * last intercepted event. 
     120    * 
     121&nb