Assembla home | Assembla project page
 

Changeset 215

Show
Ignore:
Timestamp:
04/08/08 01:18:52 (8 months ago)
Author:
Slynderdale
Message:

Cleaned up the code and beautified it. Fixed all the indentation and went with a unified code format.

Files:

Legend:

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

    r212 r215  
    22 
    33/** 
    4 * This file functions as a daemon process used to bootstrap and execute the 
    5 * client by loading its configuration file, instantiating it and event 
    6 * handlers for it, configuring it, and executing its event handling loop. 
    7 */ 
    8  
    9 /** 
    10 * Check to see if the version of PHP meets the minimum requirement 
    11 */ 
     4 * This file functions as a daemon process used to bootstrap and execute the 
     5 * client by loading its configuration file, instantiating it and event 
     6 * handlers for it, configuring it, and executing its event handling loop. 
     7 */ 
     8 
     9/** 
     10 * Check to see if the version of PHP meets the minimum requirement 
     11 */ 
    1212if (version_compare('5.1.2', PHP_VERSION, '>')) { 
    1313    trigger_error('Fatal error: PHP 5.1.2+ is required, current version: ' . PHP_VERSION, E_USER_ERROR); 
    1414 
    15 /** 
    16 * Backwards compatibility check to see if the PHP version is lower than 5.2 
    17 */ 
     15    /** 
     16     * Backwards compatibility check to see if the PHP version is lower than 5.2 
     17     */ 
    1818} elseif (version_compare('5.2', PHP_VERSION, '>')) { 
    1919    trigger_error('Warning: PHP 5.2+ is recommended, current version: ' . PHP_VERSION, E_USER_WARNING); 
     
    2121 
    2222/** 
    23 * Code base version 
    24 
    25 * @const string 
    26 */ 
     23 * Code base version 
     24
     25 * @const string 
     26 */ 
    2727define('PHERGIE_VERSION', '1.0.3'); 
    2828 
    2929/** 
    30 * Path to the configuration file used by default when one is not specified or 
    31 * register_argc_argv is disabled in php.ini 
    32 
    33 * @const string 
    34 */ 
     30 * Path to the configuration file used by default when one is not specified or 
     31 * register_argc_argv is disabled in php.ini 
     32
     33 * @const string 
     34 */ 
    3535define('PHERGIE_DEFAULT_INI', 'phergie.ini'); 
    3636 
    3737/** 
    38 * Path to the directory containing the Phergie directory 
    39 
    40 * @const string 
    41 */ 
     38 * Path to the directory containing the Phergie directory 
     39
     40 * @const string 
     41 */ 
    4242define('PHERGIE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); 
    4343 
    4444/** 
    45 * Path to the directory containing the plugins 
    46 
    47 * @const string 
    48 */ 
     45 * Path to the directory containing the plugins 
     46
     47 * @const string 
     48 */ 
    4949define('PHERGIE_PLUGIN_DIR', PHERGIE_DIR . 'Plugin' . DIRECTORY_SEPARATOR); 
    5050 
    5151/** 
    52 * Add the Phergie directory to the include path 
    53 */ 
    54 set_include_path( 
    55     get_include_path() 
    56     . PATH_SEPARATOR . 
    57     dirname(PHERGIE_DIR) 
    58 ); 
    59  
    60 /** 
    61 * Check to make sure the CLI SAPI is being used 
    62 */ 
     52 * Add the Phergie directory to the include path 
     53 */ 
     54set_include_path(get_include_path() . PATH_SEPARATOR . dirname(PHERGIE_DIR)); 
     55 
     56/** 
     57 * Check to make sure the CLI SAPI is being used 
     58 */ 
    6359if (strtolower(php_sapi_name()) != 'cli') { 
    6460    trigger_error('Phergie requires the CLI SAPI in order to run', E_USER_ERROR); 
     
    6662 
    6763/** 
    68 * Allow the bot to run indefinitely 
    69 */ 
     64 * Allow the bot to run indefinitely 
     65 */ 
    7066set_time_limit(0); 
    7167 
    7268/** 
    73 * Determine what configuration file should be used 
    74 */ 
     69 * Determine what configuration file should be used 
     70 */ 
    7571if (!ini_get('register_argc_argv')) { 
    7672    echo 'The register_argc_argv setting in php.ini is disabled, defaulting to ' . PHERGIE_DEFAULT_INI . PHP_EOL; 
     
    8884 
    8985/** 
    90 * Name of the configuration file currently in use 
    91 
    92 * @const string 
    93 */ 
     86 * Name of the configuration file currently in use 
     87
     88 * @const string 
     89 */ 
    9490define('PHERGIE_INI', basename($ini)); 
    9591 
    9692/** 
    97 * Path to the configuration file 
    98 
    99 * @const string 
    100 */ 
     93 * Path to the configuration file 
     94
     95 * @const string 
     96 */ 
    10197define('PHERGIE_INI_PATH', realpath($ini)); 
    10298 
    10399/** 
    104 * Loader to automate inclusion of classes based on directory structure and 
    105 * class naming conventions. 
    106 
    107 * @param string $class Class name to check and attempt to load 
    108 * @return void 
    109 */ 
    110 function phergieAutoLoader($class) { 
     100 * Loader to automate inclusion of classes based on directory structure and 
     101 * class naming conventions. 
     102 * 
     103 * @param string $class Class name to check and attempt to load 
     104 * @return void 
     105 */ 
     106function phergieAutoLoader($class) 
     107
    111108    $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; 
    112     require_once($file); 
     109    require_once ($file); 
    113110    if (class_exists($class)) { 
    114111        return; 
     
    120117 
    121118/** 
    122 * Start a runtime loop that will reload all settings from the configuration 
    123 * file if the bot disconnects and reconnects, allowing for flushing of the 
    124 * configuration without a full shutdown of the bot 
    125 */ 
     119 * Start a runtime loop that will reload all settings from the configuration 
     120 * file if the bot disconnects and reconnects, allowing for flushing of the 
     121 * configuration without a full shutdown of the bot 
     122 */ 
    126123while (true) { 
    127124    /** 
    128     * Obtain and validate the contents of the configuration file 
    129     */ 
     125    * Obtain and validate the contents of the configuration file 
     126    */ 
    130127    $required = array('server', 'username', 'nick'); 
    131128    $config = parse_ini_file(PHERGIE_INI_PATH); 
     
    136133 
    137134    $missing = array(); 
    138     foreach ($required as $value) { 
     135    foreach($required as $value) { 
    139136        if (empty($config[$value])) { 
    140137            $missing[] = $value; 
     
    147144 
    148145    /** 
    149     * Set error reporting to display errors if debug mode is enabled 
    150     */ 
     146    * Set error reporting to display errors if debug mode is enabled 
     147    */ 
    151148    if ($config['debug']) { 
    152         error_reporting(E_ALL | E_STRICT); 
     149        error_reporting(E_ALL|E_STRICT); 
    153150        ini_set('display_errors', true); 
    154151        ini_set('ignore_repeated_errors', true); 
     
    156153 
    157154    /** 
    158     * Configure the client 
    159     */ 
     155    * Configure the client 
     156    */ 
    160157    if (isset($config['driver'])) { 
    161158        $driver = ucfirst(strtolower($config['driver'])); 
     
    168165    $client = new $class(); 
    169166 
    170     foreach ($config as $setting => $value) { 
     167    foreach($config as $setting => $value) { 
    171168        $client->setIni($setting, $value); 
    172169    } 
    173  
    174     unset ($setting, $value, $driver, $class); 
    175  
    176     /** 
    177     * Determine which plugins should be loaded 
    178     */ 
     170    unset($setting, $value, $driver, $class); 
     171 
     172    /** 
     173     * Determine which plugins should be loaded 
     174     */ 
    179175    $all = true; 
    180176    $include = array(); 
    181     if (!empty($config['plugins']) 
    182         && preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) { 
     177    if (!empty($config['plugins']) && 
     178        preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) { 
    183179        $all = trim(strtolower($match[1])) != 'none'; 
    184180        if (!empty($match[2])) { 
     
    186182        } 
    187183    } 
    188  
    189     unset ($config, $match); 
    190  
    191     /** 
    192     * Set up plugins 
    193     */ 
     184    unset($config, $match); 
     185 
     186    /** 
     187     * Set up plugins 
     188     */ 
    194189    $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 
    195190    $plugins = array(); 
    196     foreach ($iterator as $entry) { 
     191    foreach($iterator as $entry) { 
    197192        if ($iterator->isFile() && pathinfo($entry, PATHINFO_EXTENSION) == 'php') { 
    198193            $name = basename($entry, '.php'); 
     
    202197        } 
    203198    } 
    204  
    205199    ksort($plugins); 
    206200 
    207     unset ($iterator, $entry, $name, $all, $include); 
    208  
    209     foreach ($plugins as $plugin) { 
     201    unset($iterator, $entry, $name, $all, $include); 
     202 
     203    foreach($plugins as $plugin) { 
    210204        $class = 'Phergie_Plugin_' . $plugin; 
    211205        /** 
    212         * @todo When PHP 5.3 is a stable release, change this to 
    213         *       $class::checkDependencies($client, $plugins); 
    214         */ 
     206        * @todo When PHP 5.3 is a stable release, change this to 
     207        *       $class::checkDependencies($client, $plugins); 
     208        */ 
    215209        if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 
    216210            $instance = new $class($client); 
     
    221215        } 
    222216    } 
    223  
    224     unset ($plugins, $plugin, $class, $instance); 
    225  
    226     /** 
    227     * Execute the event handling loop for the client 
    228     */ 
     217    unset($plugins, $plugin, $class, $instance); 
     218 
     219    /** 
     220     * Execute the event handling loop for the client 
     221     */ 
    229222    $state = $client->run(); 
    230223    unset($client); 
    231224 
    232     switch($state) 
    233     { 
     225    switch ($state) { 
    234226        case Phergie_Driver_Abstract::RETURN_RECONNECT: 
    235227            sleep(1); 
    236             break; 
     228        break; 
    237229        case Phergie_Driver_Abstract::RETURN_KEEPALIVE: 
    238230            sleep(15); 
    239             break; 
     231        break; 
    240232        case Phergie_Driver_Abstract::RETURN_END: 
    241             break 2; 
    242     } 
    243 } 
     233        break 2; 
     234    } 
     235} 
  • trunk/Phergie/Driver/Abstract.php

    r213 r215  
    22 
    33/** 
    4 * Handles reception, transmission, and processing of data sent to and 
    5 * from IRC server. 
    6 */ 
     4 * Handles reception, transmission, and processing of data sent to and 
     5 * from IRC server. 
     6 */ 
    77abstract class Phergie_Driver_Abstract 
    88{ 
    9     /**#@+ 
     9    /** 
    1010     * Return codes for the run function, that tells the Bot script whether 
    1111     * it should re-run or not 
     
    1414    const RETURN_KEEPALIVE = "keepalive"; 
    1515    const RETURN_END = "end"; 
    16     /**#@-*/ 
    17  
    18     /** 
    19     * Associative array mapping configuration setting names to their 
    20     * respective values 
    21    
    22     * @var array 
    23     */ 
     16    /** 
     17 
     18    /** 
     19    * Associative array mapping configuration setting names to their 
     20    * respective values 
     21   
     22    * @var array 
     23    */ 
    2424    protected $config = array(); 
    2525 
    2626    /** 
    27     * List of plugin instances 
    28    
    29     * @var array 
    30     */ 
     27    * List of plugin instances 
     28   
     29    * @var array 
     30    */ 
    3131    protected $plugins; 
    3232 
    3333    /** 
    34     * Returns the value associated with a specified configuration setting. 
    35    
    36     * @param string $name Name of the setting 
    37     * @return string Value of the setting, or NULL if the setting is not set 
    38     */ 
     34    * Returns the value associated with a specified configuration setting. 
     35   
     36    * @param string $name Name of the setting 
     37    * @return string Value of the setting, or NULL if the setting is not set 
     38    */ 
    3939    public final function getIni($name) 
    4040    { 
    4141        $name = strtolower($name); 
    42         if (!isset ($this->config[$name])) { 
     42        if (!isset($this->config[$name])) { 
    4343            return null; 
    4444        } 
     
    4747 
    4848    /** 
    49     * Sets the value of a specified configuration setting, overwriting any 
    50     * existing value for that setting. 
    51    
    52     * @param string $name Name of the setting 
    53     * @param string $value New value for the setting 
    54     * @return void 
    55     */ 
     49    * Sets the value of a specified configuration setting, overwriting any 
     50    * existing value for that setting. 
     51   
     52    * @param string $name Name of the setting 
     53    * @param string $value New value for the setting 
     54    * @return void 
     55    */ 
    5656    public final function setIni($name, $value) 
    5757    { 
    58         $this->config[strtolower($name)] = $value; 
    59     } 
    60  
    61     /** 
    62     * Parses a IRC hostmask and sets nick, user and host bits. 
    63    
    64     * @param string $hostmask Hostmask to parse 
    65     * @param string $nick Container for the nick 
    66     * @param string $user Container for the username 
    67     * @param string $host Container for the hostname 
    68     * @return void 
    69     */ 
     58        $this->config[strtolower($name) ] = $value; 
     59    } 
     60 
     61    /** 
     62    * Parses a IRC hostmask and sets nick, user and host bits. 
     63   
     64    * @param string $hostmask Hostmask to parse 
     65    * @param string $nick Container for the nick 
     66    * @param string $user Container for the username 
     67    * @param string $host Container for the hostname 
     68    * @return void 
     69    */ 
    7070    public function parseHostmask($hostmask, &$nick, &$user, &$host) 
    7171    { 
    7272        if (preg_match('/^([^!@]+)!([^@]+)@(.*)$/', $hostmask, $match) > 0) { 
    73             list (, $nick, $user, $host) = array_pad($match, 4, null); 
     73            list(, $nick, $user, $host) = array_pad($match, 4, null); 
    7474        } else { 
    7575            $host = $hostmask; 
     
    7878 
    7979    /** 
    80     * Converts a delimited string of hostmasks into a regular expression 
    81     * that will match any hostmask in the original string. 
    82    
    83     * @param string $list Delimited string of hostmasks 
    84     * @return string Regular expression 
    85     */ 
     80    * Converts a delimited string of hostmasks into a regular expression 
     81    * that will match any hostmask in the original string. 
     82   
     83    * @param string $list Delimited string of hostmasks 
     84    * @return string Regular expression 
     85    */ 
    8686    public function hostmasksToRegex($list) 
    8787    { 
    8888        $patterns = array(); 
    8989 
    90         foreach (preg_split('#[\s\r\n,]+#', $list) as $hostmask) { 
     90        foreach(preg_split('#[\s\r\n,]+#', $list) as $hostmask) { 
    9191            // Find out which chars are present in the config mask and exclude them from the regex match 
    9292            $excluded = ''; 
    93             if (strpos($hostmask, '!')!==false) { 
    94                 $excluded .= '!'; 
     93            if (strpos($hostmask, '!') !== false) { 
     94                $excluded.= '!'; 
    9595            } 
    96             if (strpos($hostmask, '@')!==false) { 
    97                 $excluded .= '@'; 
     96            if (strpos($hostmask, '@') !== false) { 
     97                $excluded.= '@'; 
    9898            } 
    9999 
    100100            // Escape regex meta characters 
    101101            $hostmask = str_replace( 
    102                 array('\\',   '^',   '$',   '.',   '[',   ']',   '|',   '(',   ')',   '?',   '+',   '{',   '}'), 
    103                 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 
    104                 $hostmask 
     102            array('\\',   '^',   '$',   '.',   '[',   ']',   '|',   '(',   ')',   '?',   '+',   '{',   '}'), 
     103            array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 
     104            $hostmask 
    105105            ); 
    106106 
    107107            // Replace * so that they match correctly in a regex 
    108             $patterns[] = str_replace('*', ($excluded === '' ? '.*' : '[^'.$excluded.']*'), $hostmask); 
     108            $patterns[] = str_replace('*', ($excluded === '' ? '.*' : '[^' . $excluded . ']*'), $hostmask); 
    109109        } 
    110110 
     
    113113 
    114114    /** 
    115     * Sends a debugging message to stdout if the debug configuration setting 
    116     * is enabled. 
    117    
    118     * @param string $message Debugging message 
    119     * @return void 
    120     */ 
     115    * Sends a debugging message to stdout if the debug configuration setting 
     116    * is enabled. 
     117   
     118    * @param string $message Debugging message 
     119    * @return void 
     120    */ 
    121121    public function debug($message) 
    122122    { 
     
    131131 
    132132    /** 
    133     * Adds a set of callbacks for events received from the server. 
    134    
    135     * @param Phergie_Plugin_Abstract_Base $plugin 
    136     */ 
     133    * Adds a set of callbacks for events received from the server. 
     134   
     135    * @param Phergie_Plugin_Abstract_Base $plugin 
     136    */ 
    137137    public function addPlugin(Phergie_Plugin_Abstract_Base $plugin) 
    138138    { 
    139         $this->plugins[strtolower($plugin->getName())] = $plugin; 
    140     } 
    141  
    142     /** 
    143     * Returns all the plugins. 
    144    
    145     * @return Phergie_Plugin_Abstract_Base 
    146     */ 
     139        $this->plugins[strtolower($plugin->getName()) ] = $plugin; 
     140    } 
     141 
     142    /** 
     143    * Returns all the plugins. 
     144   
     145    * @return Phergie_Plugin_Abstract_Base 
     146    */ 
    147147    public function getPlugins() 
    148148    { 
     
    151151 
    152152    /** 
    153     * Returns a list of all the plugins either currently loaded or within the 
    154     * plugin directory. 
    155    
    156     * @param $plugin $dirList If true, scan the Plugin directory for the list 
    157     * @return array 
    158     */ 
     153    * Returns a list of all the plugins either currently loaded or within the 
     154    * plugin directory. 
     155   
     156    * @param $plugin $dirList If true, scan the Plugin directory for the list 
     157    * @return array 
     158    */ 
    159159    public function getPluginList($dirList = false, $preserveExt = false) 
    160160    { 
     
    165165            $plugins = array(); 
    166166 
    167             foreach ($iterator as $filename) { 
     167            foreach($iterator as $filename) { 
    168168                if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 
    169                     $plugins[] = ($preserveExt ? (string) $filename : basename($filename, '.php')); 
     169                    $plugins[] = ($preserveExt ? (string)$filename : basename($filename, '.php')); 
    170170                } 
    171171            } 
     
    177177 
    178178    /** 
    179     * Returns a plugin instance. 
    180    
    181     * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
    182     * @return Phergie_Plugin_Abstract_Base 
    183     */ 
     179    * Returns a plugin instance. 
     180   
     181    * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
     182    * @return Phergie_Plugin_Abstract_Base 
     183    */ 
    184184    public function getPlugin($plugin) 
    185185    { 
    186186        $plugin = strtolower($plugin); 
    187         if (isset($this->plugins[$plugin])) 
     187        if (isset($this->plugins[$plugin])) { 
    188188            return $this->plugins[$plugin]; 
     189        } 
    189190        return false; 
    190191    } 
    191192 
    192193    /** 
    193     * Executes a continuous loop in which the client listens for events from 
    194     * the server and processes them until the connection is terminated. 
    195    
    196     * @return void 
    197     */ 
     194    * Executes a continuous loop in which the client listens for events from 
     195    * the server and processes them until the connection is terminated. 
     196   
     197    * @return void 
     198    */ 
    198199    public abstract function run(); 
    199200 
    200201    /** 
    201     * Terminates the connection with the server. 
    202    
    203     * @param string $reason Reason for connection termination (optional) 
    204     * @param bool $reconnect if true, the bot will reconnect to the server 
    205     * @return void 
    206     */ 
     202    * Terminates the connection with the server. 
     203   
     204    * @param string $reason Reason for connection termination (optional) 
     205    * @param bool $reconnect if true, the bot will reconnect to the server 
     206    * @return void 
     207    */ 
    207208    public abstract function doQuit($reason = null, $reconnect = false); 
    208209 
    209210    /** 
    210     * Joins a channel. 
    211    
    212     * @param string $channel Name of the channel to join 
    213     * @param string $keys Channel key if needed (optional) 
    214     * @return void 
    215     */ 
     211    * Joins a channel. 
     212   
     213    * @param string $channel Name of the channel to join 
     214    * @param string $keys Channel key if needed (optional) 
     215    * @return void 
     216    */ 
    216217    public abstract function doJoin($channel, $key = null); 
    217218 
    218219    /** 
    219     * Leaves a channel. 
    220    
    221     * @param string $channel Name of the channel to leave 
    222     * @return void 
    223     */ 
     220    * Leaves a channel. 
     221   
     222    * @param string $channel Name of the channel to leave 
     223    * @return void 
     224    */ 
    224225    public abstract function doPart($channel); 
    225226 
    226227    /** 
    227     * Invites a user to an invite-only channel. 
    228    
    229     * @param string $nick Nick of the user to invite 
    230     * @param string $channel Name of the channel 
    231     * @return void 
    232     */ 
     228    * Invites a user to an invite-only channel. 
     229   
     230    * @param string $nick Nick of the user to invite 
     231    * @param string $channel Name of the channel 
     232    * @return void 
     233    */ 
    233234    public abstract function doInvite($nick, $channel); 
    234235 
    235236    /** 
    236     * Obtains a list of nicks of usrs in currently joined channels. 
    237    
    238     * @param string $channels Comma-delimited list of one or more channels 
    239     * @return void 
    240     */ 
     237    * Obtains a list of nicks of usrs in currently joined channels. 
     238   
     239    * @param string $channels Comma-delimited list of one or more channels 
     240    * @return void 
     241    */ 
    241242    public abstract function doNames($channels); 
    242243 
    243244    /** 
    244     * Obtains a list of channel names and topics. 
    245    
    246     * @param string $channels Comma-delimited list of one or more channels 
    247     *                         to which the response should be restricted 
    248     *                         (optional) 
    249     * @return void 
    250     */ 
     245    * Obtains a list of channel names and topics. 
     246   
     247    * @param string $channels Comma-delimited list of one or more channels 
     248    *                         to which the response should be restricted 
     249    *                         (optional) 
     250    * @return void 
     251    */ 
    251252    public abstract function doList($channels = null); 
    252253 
    253254    /** 
    254     * Retrieves or changes a channel topic. 
    255    
    256     * @param string $channel Name of the channel 
    257     * @param string $topic New topic to assign (optional) 
    258     * @return void 
    259     */ 
     255    * Retrieves or changes a channel topic. 
     256   
     257    * @param string $channel Name of the channel 
     258    * @param string $topic New topic to assign (optional) 
     259    * @return void 
     260    */ 
    260261    public abstract function doTopic($channel, $topic = null); 
    261262 
    262263    /** 
    263     * Retrieves or changes a channel or user mode. 
    264    
    265     * @param string $target Channel name or user nick 
    266     * @param string $mode New mode to assign (optional) 
    267     * @return void 
    268     */ 
     264    * Retrieves or changes a channel or user mode. 
     265   
     266    * @param string $target Channel name or user nick 
     267    * @param string $mode New mode to assign (optional) 
     268    * @return void 
     269    */ 
    269270    public abstract function doMode($target, $mode = null); 
    270271 
    271272    /** 
    272     * Changes the client nick. 
    273    
    274     * @param string $nick New nick to assign 
    275     * @return void 
    276     */ 
     273    * Changes the client nick. 
     274   
     275    * @param string $nick New nick to assign 
     276    * @return void 
     277    */ 
    277278    public abstract function doNick($nick); 
    278279 
    279280    /** 
    280     * Retrieves information about a nick. 
    281    
    282     * @param string $nick 
    283     * @return void 
    284     */ 
     281    * Retrieves information about a nick. 
     282   
     283    * @param string $nick 
     284    * @return void 
     285    */ 
    285286    public abstract function doWhois($nick); 
    286287 
    287288    /** 
    288     * Sends a message to a nick or channel. 
    289    
    290     * @param string $target Channel name or user nick 
    291     * @param string $text Text of the message to send 
    292     * @return void 
    293     */ 
     289    * Sends a message to a nick or channel. 
     290   
     291    * @param string $target Channel name or user nick 
     292    * @param string $text Text of the message to send 
     293    * @return void 
     294    */ 
    294295    public abstract function doPrivmsg($target, $text); 
    295296 
    296297    /** 
    297     * Sends a notice to a nick or channel. 
    298    
    299     * @param string $target Channel name or user nick 
    300     * @param string $text Text of the notice to send 
    301     * @return void 
    302     */ 
     298    * Sends a notice to a nick or channel. 
     299   
     300    * @param string $target Channel name or user nick 
     301    * @param string $text Text of the notice to send 
     302    * @return void 
     303    */ 
    303304    public abstract function doNotice($target, $text); 
    304305 
    305306    /** 
    306     * Kicks a user from a channel. 
    307    
    308     * @param string $nick Nick of the user 
    309     * @param string $channel Channel name 
    310     * @param string $reason Reason for the kick (optional) 
    311     * @return void 
    312     */ 
     307    * Kicks a user from a channel. 
     308   
     309    * @param string $nick Nick of the user 
     310    * @param string $channel Channel name 
     311    * @param string $reason Reason for the kick (optional) 
     312    * @return void 
     313    */ 
    313314    public abstract function doKick($nick, $channel, $reason = null); 
    314315 
    315316    /** 
    316     * Responds to a server test of client responsiveness. 
    317    
    318     * @param string $daemon Daemon from which the original request originates 
    319     * @return void 
    320     */ 
     317    * Responds to a server test of client responsiveness. 
     318   
     319    * @param string $daemon Daemon from which the original request originates 
     320    * @return void 
     321    */ 
    321322    public abstract function doPong($daemon); 
    322323 
    323324    /** 
    324     * Sends a CTCP ACTION (/me) command to a nick or channel. 
    325    
    326     * @param string $target Channel name or user nick 
    327     * @param string $text Text of the action to perform 
    328     * @return void 
    329     */ 
     325    * Sends a CTCP ACTION (/me) command to a nick or channel. 
     326   
     327    * @param string $target Channel name or user nick 
     328    * @param string $text Text of the action to perform 
     329    * @return void 
     330    */ 
    330331    public abstract function doAction($target, $text); 
    331332} 
  • trunk/Phergie/Driver/Streams.php

    r214 r215  
    11<?php 
    2  
    32/** 
    4 * Provides a socket-based client driver. 
    5 */ 
     3 * Provides a socket-based client driver. 
     4 */ 
    65class Phergie_Driver_Streams extends Phergie_Driver_Abstract 
    76{ 
    87    /** 
    9     * Names of commands that can be issued by callbacks ordered by 
    10     * priority of execution 
    11    
    12     * @var array 
    13     */ 
     8    * Names of commands that can be issued by callbacks ordered by 
     9    * priority of execution 
     10   
     11    * @var array 
     12    */ 
    1413    protected $priority = array( 
    1514        'raw', 
     
    4140 
    4241    /** 
    43     * Names of destructive commands that get queued up last 
    44    
    45     * @var array 
    46     */ 
     42    * Names of destructive commands that get queued up last 
     43   
     44    * @var array 
     45    */ 
    4746    protected $destuctive = array( 
    4847        'nick', 
     
    5352 
    5453    /** 
    55     * Socket handler 
    56    
    57     * @var resource 
    58     */ 
     54    * Socket handler 
     55   
     56    * @var resource 
     57    */ 
    5958    protected $socket; 
    6059 
    6160    /** 
    62     * Flag to indicate whether or not the callbacks are currently being 
    63     * queued for execution rather than executed outright 
    64    
    65     * @var bool 
    66     */ 
     61    * Flag to indicate whether or not the callbacks are currently being 
     62    * queued for execution rather than executed outright 
     63   
     64    * @var bool 
     65    */ 
    6766    protected $queueing; 
    6867 
    6968    /** 
    70     * Associative array mapping command names to queued sets of arguments 
    71     * from commands queued by callbacks 
    72    
    73     * @var array 
    74     */ 
     69    * Associative array mapping command names to queued sets of arguments 
     70    * from commands queued by callbacks 
     71   
     72    * @var array 
     73    */ 
    7574    protected $queue; 
    7675 
    7776    /** 
    78     * The time the bot started 
    79    
    80     * @var int 
    81     */ 
     77    * The time the bot started 
     78   
     79    * @var int 
     80    */ 
    8281    protected $startTime; 
    8382 
    8483    /** 
    85     * Constructor to initialize instance properties. 
    86     */ 
     84    * Constructor to initialize instance properties. 
     85    */ 
    8786    public function __construct() 
    8887    { 
     
    9392 
    9493    /** 
    95     * Returns the start time. 
    96    
    97     * @return int 
    98     */ 
     94    * Returns the start time. 
     95   
     96    * @return int 
     97    */ 
    9998    public function getStartTime() 
    10099    { 
     
    103102 
    104103    /** 
    105     * Executes a continuous loop in which the client listens for events from 
    106     * the server and processes them until the connection is terminated. 
    107    
    108     * @return void 
    109     */ 
     104    * Executes a continuous loop in which the client listens for events from 
     105    * the server and processes them until the connection is terminated. 
     106   
     107    * @return void 
     108    */ 
    110109    public function run() 
    111110    { 
     
    118117        } 
    119118 
    120         $this->socket = @stream_socket_client( 
    121             'tcp://' . $server . ':' . $port, 
    122             $errno, 
    123             $errstr 
    124         ); 
    125  
     119        $this->socket = @stream_socket_client('tcp://' . $server . ':' . $port, $errno, $errstr); 
    126120        if (!$this->socket) { 
    127121            $this->debug(rtrim('Unable to connect to server: socket error ' . $errno . ' ' . $errstr)); 
     
    165159 
    166160        // Run the onConnect handler since we successfully connected to the server 
    167         foreach ($this->plugins as $plugin) { 
     161        foreach($this->plugins as $plugin) { 
    168162            $plugin->onConnect(); 
    169163        } 
    170164 
    171         while(true) { 
     165        while (true) { 
    172166            $this->queue = array(); 
    173167            $this->queueing = true; 
    174168 
    175169            // Clear the old event handler for every plugin 
    176             foreach ($this->plugins as $plugin) { 
     170            foreach($this->plugins as $plugin) { 
    177171                $plugin->setEvent(NULL); 
    178172            }