Assembla home | Assembla project page
 

Changeset 125

Show
Ignore:
Timestamp:
03/05/08 19:07:13 (9 months ago)
Author:
Seldaek
Message:

* Toggle: does not require all plugins to be loaded at init anymore, plugins are loaded on the fly when the enable command is issued.
* Bot: added unset() that hopefully reduces the reconnect memory bump

Files:

Legend:

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

    r106 r125  
    140140                $name = substr($entry, 0, -4); 
    141141                if ($all xor in_array(strtolower($name), $include)) { 
    142                     $plugins[$name] = true; 
    143                 } else { 
    144                         $plugins[$name] = false; 
     142                    $plugins[] = $name; 
    145143                } 
    146144            } 
     
    151149        unset ($iterator, $entry, $name, $all, $include); 
    152150 
    153         foreach ($plugins as $plugin=>$enabled) { 
     151        foreach ($plugins as $plugin) { 
    154152            require_once 'Phergie/Plugin/' . $plugin . '.php'; 
    155153            $class = 'Phergie_Plugin_' . $plugin; 
    156154            if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 
    157155                $instance = new $class($client); 
    158                 $instance->enabled = $enabled; 
    159156                $client->addPlugin($instance); 
    160                $client->debug('Loaded ' . $plugin . ($enabled ? '':' [Disabled]')); 
     157           $client->debug('Loaded ' . $plugin); 
    161158            } else { 
    162159                $client->debug('Unable to load ' . $plugin); 
     
    170167        */ 
    171168        $state = $client->run(); 
     169        unset($client); 
    172170 
    173171        switch($state) 
  • trunk/Phergie/Plugin/Toggle.php

    r124 r125  
    1313    public function onDoDisable($plugin) 
    1414    { 
    15         if ($instance = $this->getPlugin($plugin) && $instance != $this) { 
     15        if (($instance = $this->getPlugin($plugin)) && $instance != $this) { 
    1616                $instance->enabled = false; 
    1717                $this->doPrivmsg($this->event->getSource(), 'Disabled '.$plugin.'.'); 
    1818        } else { 
    19                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not disable.'); 
     19                $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' is not loaded.'); 
    2020        } 
    2121    } 
     
    2323    public function onDoEnable($plugin) 
    2424    { 
     25        // Plugin is loaded already 
    2526        if ($instance = $this->getPlugin($plugin)) { 
    26                 $instance->enabled = true; 
    27                 $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 
     27                // Already enabled 
     28                if ($instance->enabled) { 
     29                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' was already enabled.'); 
     30                // Not yet enabled, enable 
     31                } else { 
     32                        $instance->enabled = true; 
     33                        $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 
     34                } 
     35            // Plugin was not loaded, try to see if we can load it 
    2836        } else { 
    29                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 
     37                        // Build loaded plugin list to pass to the checkDependencies method 
     38                        $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 
     39                        $plugins = array(); 
     40 
     41                        foreach ($iterator as $entry) { 
     42                                if ($iterator->isFile()) { 
     43                                        $plugins[] = basename((string) $entry, '.php'); 
     44                                } 
     45 
     46                                if ($iterator->isFile() && strtolower((string) $entry) == strtolower($plugin).'.php') { 
     47                                        $target = (string) $entry; 
     48                                } 
     49                        } 
     50 
     51                        foreach ($plugins as $k=>$p) { 
     52                                if(!($this->getPlugin($p) instanceof Phergie_Plugin_Abstract_Base)) { 
     53                                        unset($plugins[$k]); 
     54                                } 
     55                        } 
     56 
     57                        // Plugin file was found, check if it can be loaded 
     58                        if (isset($target)) { 
     59                                require_once PHERGIE_DIR.'/Phergie/Plugin/'.$target; 
     60                            $class = 'Phergie_Plugin_'.substr($target, 0, -4); 
     61                            if (call_user_func(array($class, 'checkDependencies'), $this->client, $plugins)) { 
     62                                $instance = new $class($this->client); 
     63                                $this->client->addPlugin($instance); 
     64                                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' loaded.'); 
     65                            } else { 
     66                                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' can not be loaded, missing dependencies.'); 
     67                            } 
     68                        // Plugin file not found 
     69                } else { 
     70                                $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 
     71                } 
    3072        } 
    3173    }