Assembla home | Assembla project page
 

Changeset 82

Show
Ignore:
Timestamp:
02/27/08 05:40:00 (9 months ago)
Author:
Seldaek
Message:

+ Adds Toggle module that allows to mute and or disable other plugins (excepted itself for disable)
- Base: Removed the static $instance and getInstance functions as they did not work (you can't have a single var for all classes, they just override each other's static var and we ended up with getInstance always returning the Users instance)
+ Streams/Abstract: Added a getInstance($plugin) method so plugins can do $this->getInstance('MyBuddyPlugin?') to reach them
* Bot: All plugins are loaded now but those that are disabled in the .ini are marked as disabled - That way they can be enabled during runtime
* Nickserv: Fix to use the new getInstance model

Files:

Legend:

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

    r78 r82  
    133133        $name = substr($entry, 0, -4); 
    134134        if ($all xor in_array(strtolower($name), $include)) { 
    135             $plugins[] = $name; 
     135            $plugins[$name] = true; 
     136        } else { 
     137                $plugins[$name] = false; 
    136138        } 
    137139    } 
    138140} 
    139 sort($plugins); 
     141 
     142ksort($plugins); 
    140143 
    141144unset ($iterator, $entry, $name, $all, $include); 
    142145 
    143 foreach ($plugins as $plugin) { 
     146foreach ($plugins as $plugin=>$enabled) { 
    144147    require_once 'Phergie/Plugin/' . $plugin . '.php'; 
    145     $class = 'Phergie_Plugin_' . $plugin;  
     148    $class = 'Phergie_Plugin_' . $plugin; 
    146149    if (call_user_func(array($class, 'checkDependencies'), $plugins)) { 
    147150        $instance = new $class($client); 
     151        $instance->enabled = $enabled; 
    148152        $client->addPlugin($instance); 
    149         $client->debug('Loaded ' . $plugin);  
     153        $client->debug('Loaded ' . $plugin . ($enabled ? '':' [Disabled]')); 
    150154    } else { 
    151155        $client->debug('Unable to load ' . $plugin); 
  • trunk/Phergie/Driver/Abstract.php

    r68 r82  
    8888    public abstract function addPlugin(Phergie_Plugin_Abstract_Base $plugin); 
    8989 
     90        /** 
     91         * Returns a plugin instance 
     92         * 
     93         * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
     94         * @return Phergie_Plugin_Abstract_Base 
     95         */ 
     96        public abstract function getInstance($plugin); 
     97 
    9098    /** 
    9199    * Executes a continuous loop in which the client listens for events from 
  • trunk/Phergie/Driver/Streams.php

    r76 r82  
    9393        $plugin->init(); 
    9494 
    95         $this->plugins[] = $plugin; 
    96     } 
     95        $this->plugins[strtolower($plugin->getName())] = $plugin; 
     96    } 
     97 
     98        /** 
     99         * Returns a plugin instance 
     100         * 
     101         * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 
     102         * @return Phergie_Plugin_Abstract_Base 
     103         */ 
     104        public function getInstance($plugin) 
     105        { 
     106                if (isset($this->plugins[strtolower($plugin)])) 
     107                        return $this->plugins[strtolower($plugin)]; 
     108                return false; 
     109        } 
    97110 
    98111    /** 
     
    220233 
    221234            foreach ($this->plugins as $plugin) { 
     235                if ($plugin->enabled === false) { // Skip disabled plugins 
     236                        continue; 
     237                } 
    222238                $plugin->setEvent($event); 
    223239                if ($event instanceof Phergie_Event_Response) { 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r79 r82  
    4646 
    4747    /** 
    48     * Reference to the current instance of the plugin, used to make its 
    49     * non-static methods accessible to other plugins 
    50     * 
    51     * @var Phergie_Plugin_Abstract_Base 
    52     */ 
    53     protected static $instance; 
    54  
    55     /** 
    5648    * Short class name 
    5749    * 
     
    6860 
    6961    /** 
     62     * Flag indicating whether or not the plugin is enabled and receives events 
     63     * 
     64     * @var bool 
     65     */ 
     66    public $enabled = true; 
     67 
     68    /** 
     69     * Flag indicating whether or not the plugin is muted and can output events 
     70     * 
     71     * @var bool 
     72     */ 
     73    public $muted = false; 
     74 
     75    /** 
    7076    * Sets a reference to the client used to initiate commands. 
    7177    * 
     
    7581    final public function __construct(Phergie_Driver_Abstract $client) 
    7682    { 
    77         self::$instance = $this; 
    78  
    7983        $this->client = $client; 
    8084 
     
    210214 
    211215    /** 
    212     * Returns a reference to the instance of the current plugin. 
    213     * 
    214     * @return Phergie_Plugin_Abstract_Base 
    215     */ 
    216     public static function getInstance() 
    217     { 
    218         return self::$instance; 
    219     } 
    220  
    221     /** 
    222216    * Returns whether or not the current environment meets the requirements 
    223217    * of the plugin in order for it to be run, including the PHP version, 
     
    354348    public function __call($method, $arguments) 
    355349    { 
     350        if ($this->muted && substr($method, 0, 2) === 'do') { // Silence output calls if the plugin is muted 
     351                return false; 
     352        } 
    356353        return call_user_func_array(array($this->client, $method), $arguments); 
    357354    } 
  • trunk/Phergie/Plugin/Nickserv.php

    r78 r82  
    4242    * Returns whether or not the plugin's dependencies are met. 
    4343    * 
    44     * @param array $plugins List of short names for plugins that the  
     44    * @param array $plugins List of short names for plugins that the 
    4545    *                       bootstrap file intends to instantiate 
    4646    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     
    9595    public function onDoGhostbust() 
    9696    { 
    97         if (Phergie_Plugin_Users::getInstance() === null) { 
     97        if ($this->getInstance('Users') === null) { 
    9898            $password = $this->getPluginIni('password'); 
    9999            $this->debug('password = ' . $password);