Assembla home | Assembla project page
 

Changeset 192

Show
Ignore:
Timestamp:
03/29/08 12:43:25 (8 months ago)
Author:
Slynderdale
Message:

Moved the get and add plugin functions from Streams to the base abstract driver as well as updated the require_once statement to take into account the new constants. Also added some small bug fixes to the files as well.

Files:

Legend:

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

    r178 r192  
    44* @see Phergie_Plugin_Abstract_Base 
    55*/ 
    6 require_once 'Phergie/Plugin/Abstract/Base.php'; 
     6require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 
    77 
    88/** 
     
    3030 
    3131    /** 
     32    * List of plugin instances 
     33    * 
     34    * @var array 
     35    */ 
     36    protected $plugins; 
     37 
     38    /** 
    3239    * Returns the value associated with a specified configuration setting. 
    3340    * 
     
    120127    { 
    121128        if ($this->getIni('debug')) { 
    122             $message = date('H:i:s') . ' ' . $message . PHP_EOL; 
     129            $message = '[' . date('H:i:s') . '] ' . $message . PHP_EOL; 
    123130            echo $message; 
    124             if ($log = $this->getIni('log')) { 
     131            if ($log = $this->getIni('log') and !empty($log)) { 
    125132                file_put_contents($log, $message, FILE_APPEND); 
    126133            } 
     
    132139    * 
    133140    * @param Phergie_Plugin_Abstract_Base $plugin 
    134     * @return void 
    135     */ 
    136     public abstract function addPlugin(Phergie_Plugin_Abstract_Base $plugin); 
     141    */ 
     142    public function addPlugin(Phergie_Plugin_Abstract_Base $plugin) 
     143    { 
     144        $plugin->init(); 
     145 
     146        $this->plugins[strtolower($plugin->getName())] = $plugin; 
     147    } 
    137148 
    138149        /** 
     
    141152        * @return Phergie_Plugin_Abstract_Base 
    142153        */ 
    143         public abstract function getPlugins(); 
     154        public function getPlugins() 
     155        { 
     156            return $this->plugins; 
     157        } 
    144158 
    145159        /** 
    146         * Returns a list of all the plugins 
    147     * 
     160        * Returns a list of all the plugins either currently loaded or within the 
     161        * plugin directory. 
     162        * 
     163        * @param $plugin $dirList If true, scan the Plugin directory for the list 
    148164        * @return array 
    149165        */ 
    150         public abstract function getPluginList(); 
     166        public function getPluginList($dirList = false, $preserveExt = false) 
     167        { 
     168                if (!$dirList) { 
     169                        return array_keys($this->plugins); 
     170                } else { 
     171                        $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 
     172                        $plugins = array(); 
     173 
     174                        foreach ($iterator as $filename) { 
     175                                if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 
     176                                        $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php')); 
     177                                } 
     178                        } 
     179                        unset($iterator, $filename, $dirList); 
     180 
     181                        return $plugins; 
     182                } 
     183        } 
    151184 
    152185        /** 
    153         * Returns a plugin instance 
    154        
     186        * Returns a plugin instance. 
     187   
    155188        * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
    156189        * @return Phergie_Plugin_Abstract_Base 
    157190        */ 
    158         public abstract function getPlugin($plugin); 
     191        public function getPlugin($plugin) 
     192        { 
     193                $plugin = strtolower($plugin); 
     194                if (isset($this->plugins[$plugin])) 
     195                        return $this->plugins[$plugin]; 
     196                return false; 
     197        } 
    159198 
    160199    /** 
  • trunk/Phergie/Driver/Streams.php

    r178 r192  
    44* @see Phergie_Driver_Abstract 
    55*/ 
    6 require_once 'Phergie/Driver/Abstract.php'; 
     6require_once PHERGIE_DRIVER_DIR.'Abstract.php'; 
    77 
    88/** 
     
    3737        'whowas', 
    3838        'mode', 
     39        'nick', 
    3940        'privmsg', 
    40         'nick', 
    4141        'topic', 
    4242        'invite', 
     
    5353 
    5454    /** 
    55     * List of plugin instances 
    56     * 
    57     * @var array 
    58     */ 
    59     protected $plugins; 
    60  
    61     /** 
    6255    * Flag to indicate whether or not the callbacks are currently being 
    6356    * queued for execution rather than executed outright 
     
    9184        $this->queue = array(); 
    9285    } 
    93  
    94     /** 
    95     * Adds a set of callbacks for events received from the server. 
    96     * 
    97     * @param Phergie_Plugin_Abstract_Base $plugin 
    98     */ 
    99     public function addPlugin(Phergie_Plugin_Abstract_Base $plugin) 
    100     { 
    101         $plugin->init(); 
    102  
    103         $this->plugins[strtolower($plugin->getName())] = $plugin; 
    104     } 
    105  
    106         /** 
    107         * Returns all the plugins. 
    108     * 
    109         * @return Phergie_Plugin_Abstract_Base 
    110         */ 
    111         public function getPlugins() 
    112         { 
    113             return $this->plugins; 
    114         } 
    115  
    116         /** 
    117         * Returns a list of all the plugins either currently loaded or within the 
    118         * plugin directory. 
    119         * 
    120         * @param $plugin $dirList If true, scan the Plugin directory for the list 
    121         * @return array 
    122         */ 
    123         public function getPluginList($dirList = false, $preserveExt = false) 
    124         { 
    125                 if (!$dirList) { 
    126                         return array_keys($this->plugins); 
    127                 } else { 
    128                         $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 
    129                         $plugins = array(); 
    130  
    131                         foreach ($iterator as $filename) { 
    132                                 if ($iterator->isFile()) { 
    133                                         $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php')); 
    134                                 } 
    135                         } 
    136                         unset($iterator, $filename, $dirList); 
    137  
    138                         return $plugins; 
    139                 } 
    140         } 
    141  
    142         /** 
    143         * Returns a plugin instance. 
    144     * 
    145         * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
    146         * @return Phergie_Plugin_Abstract_Base 
    147         */ 
    148         public function getPlugin($plugin) 
    149         { 
    150                 if (isset($this->plugins[strtolower($plugin)])) 
    151                         return $this->plugins[strtolower($plugin)]; 
    152                 return false; 
    153         } 
    15486 
    15587    /** 
     
    217149        ); 
    218150 
    219         unset($server); 
    220  
    221151        $this->send('USER', $params); 
    222152        $this->doNick($this->getIni('nick')); 
    223  
    224         unset($params); 
     153        unset($server, $params); 
    225154 
    226155        $ignore = $this->hostmasksToRegex($this->getIni('ignore')); 
     
    251180            } 
    252181            $buffer = rtrim($buffer); 
    253             $this->debug('server -> ' . $buffer); 
     182            $this->debug('<- ' . $buffer); 
    254183 
    255184            if ($buffer[0] == ':') { 
     
    261190 
    262191            $cmd = strtolower($cmd); 
    263  
    264192            switch ($cmd) { 
    265193                case 'names': 
     
    268196                case 'ping': 
    269197                case 'join': 
     198                case 'error': 
    270199                    $args = array(ltrim($args, ':')); 
    271200                    break; 
     
    300229                    break; 
    301230                case 'part': 
     231                case 'kill': 
    302232                    $args = preg_split('/ :?/', $args, 2); 
    303233                    break; 
     
    360290                } 
    361291                $plugin->setEvent($event); 
     292                // onRaw Handlers 
     293                $plugin->onRaw(); 
    362294                if ($event instanceof Phergie_Event_Response) { 
    363295                    $plugin->onResponse(); 
     
    366298                    call_user_func(array($plugin, 'on' . ucfirst($event->getType()))); 
    367299                } 
    368                 // onRaw Handler 
    369                 $plugin->onRaw(); 
    370300            } 
    371301            $this->queueing = false; 
     
    417347            $this->queue[$command][] = $arguments; 
    418348        } else { 
    419                 if ($command == 'raw') { 
     349                if ($command == Phergie_Event_Request::TYPE_RAW) { 
    420350                $buffer = (count($arguments) > 0 ? implode(' ', $arguments) : ''); 
    421351                } else { 
     
    429359            if (!empty($buffer)) { 
    430360                fwrite($this->socket, $buffer . "\r\n"); 
    431                 $this->debug('client -> ' . $buffer); 
     361                $this->debug('-> ' . $buffer); 
    432362            } 
    433363        } 
     
    471401    * @param string $channel Name of the channel to leave 
    472402    */ 
    473     public function doPart($channel
    474     { 
    475         $this->send(Phergie_Event_Request::TYPE_PART, array($channel)); 
     403    public function doPart($channel, $reason = null
     404    { 
     405        $this->send(Phergie_Event_Request::TYPE_PART, array($channel, $reason)); 
    476406    } 
    477407 
     
    663593    * @param string $version The version to send 
    664594    */ 
    665     public function doVersionReply($target, $version='') 
     595    public function doVersionReply($target, $version = '') 
    666596    { 
    667597        $version = trim($version); 
     
    678608    * @param string $time The time to send 
    679609    */ 
    680     public function doTimeReply($target, $time='') 
     610    public function doTimeReply($target, $time = '') 
    681611    { 
    682612        $time = trim($time); 
     
    694624    * @param string $reply The CTCP reply to send 
    695625    */ 
    696     public function doCtcpReply($target, $command, $reply='') 
     626    public function doCtcpReply($target, $command, $reply = '') 
    697627    { 
    698628        $command = trim($command);