<commit_before><?php
class PHPFrame_PluginHandler
{
    private static $_instance = null;
    private $_plugins = null;
    private $_events = array(
        "routeStartup", 
        "routeShutdown", 
        "dispatchLoopStartup",
        "dispatchLoopShutdown",
        "preDispatch",
        "postDispatch"
    );
    
    public function __construct()
    {
        $this->_plugins = new SplObjectStorage();
        
        $plugins_path  = PHPFRAME_INSTALL_DIR;
        $plugins_path .= DIRECTORY_SEPARATOR."src";
        $plugins_path .= DIRECTORY_SEPARATOR."plugins";
        set_include_path($plugins_path.PATH_SEPARATOR.get_include_path());
        
        /**
         * Register MVC autoload function
         */
        spl_autoload_register(array("PHPFrame_PluginHandler", "__autoload"));
    }
    
    public static function __autoload($class_name)
    {
        require strtolower(trim($class_name)).".php";
    }
    
    public function registerPlugin(PHPFrame_Plugin $plugin)
    {
        $this->_plugins->attach($plugin);
    }
    
    public function unregisterPlugin(PHPFrame_Plugin $plugin)
    {
        $this->_plugins->detach($plugin);
    }
    
    public function handle($event)
    {
        $event = trim((string) $event);
        if (!in_array($event, $this->_events)) {
            $msg  = "Plugin event not supported. The plugin handler supports ";
            $msg .= "'".implode("', '", $this->_events)."'";
            throw new LogicException($msg);
        }
        
        foreach ($this->_plugins as $plugin) {
            $plugin->$event();
        }
    }<commit_msg>Javadoc comments added to PluginHandler class.<commit_after><?php
/**
 * PHPFrame/Ext/PluginHandler.php
 * 
 * PHP version 5
 * 
 * @category  PHPFrame
 * @package   Ext
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009 E-noise.com Limited
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/phpframe/source/browse/#svn/PHPFrame
 * @ignore
 */

/**
 * This class handles the plugin hooks and allows plugins to register to 
 * listen for the hook events.
 * 
 * This class is instantiated and used by the FrontController.
 * 
 * @category PHPFrame
 * @package  Ext
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://code.google.com/p/phpframe/source/browse/#svn/PHPFrame
 * @since    1.0
 * @see      PHPFrame_FrontController
 */
class PHPFrame_PluginHandler
{
    /**
     * This property holds an instance of SplObjectStorage used to store 
     * instances of the registered plugins.
     * 
     * @var SplObjectStorage
     */
    private $_plugins = null;
    /**
     * An array defining the support events or hooks
     * 
     * @var array
     */
    private $_events = array(
        "routeStartup", 
        "routeShutdown", 
        "dispatchLoopStartup",
        "dispatchLoopShutdown",
        "preDispatch",
        "postDispatch"
    );
    
    /**
     * Constructor
     * 
     * @access public
     * @return void
     * @since  1.0
     */
    public function __construct()
    {
        // Acquire instance of SplObjectStorage
        $this->_plugins = new SplObjectStorage();
        
        /**
         * Register plugins autoload function
         */
        spl_autoload_register(array("PHPFrame_PluginHandler", "__autoload"));
    }
    
    /**
     * Plugins autoloader method
     * 
     * @param string $class_name The class name to load
     * 
     * @static
     * @access public
     * @return void
     * @since  1.0
     */
    public static function __autoload($class_name)
    {
        $plugins_path  = PHPFRAME_INSTALL_DIR.DS."src".DS."plugins";
        $file_name     = $plugins_path.DS.strtolower(trim($class_name)).".php";
        
        if (is_file($file_name)) {
            require $file_name;
        }
    }
    
    /**
     * Register a plugin with the plugin handler
     * 
     * @param PHPFrame_Plugin $plugin Instance of the plugin object we want to 
     *                                register.
     * 
     * @access public
     * @return void
     * @since  1.0
     */
    public function registerPlugin(PHPFrame_Plugin $plugin)
    {
        $this->_plugins->attach($plugin);
    }
    
    /**
     * Unregister a plugin from the plugin handler
     * 
     * @param PHPFrame_Plugin $plugin Instance of the plugin object we want to 
     *                                unregister.
     *                                
     * @access public
     * @return void
     * @since  1.0
     */
    public function unregisterPlugin(PHPFrame_Plugin $plugin)
    {
        $this->_plugins->detach($plugin);
    }
    
    /**
     * Handle plugin events (hooks)
     * 
     * @param string $event The plugin handler supports the following events or 
     *                      hooks: routeStartup, routeShutdown, 
     *                      dispatchLoopStartup, dispatchLoopShutdown, 
     *                      preDispatch, postDispatch
     * 
     * @access public
     * @return void
     * @since  1.0
     */
    public function handle($event)
    {
        $event = trim((string) $event);
        if (!in_array($event, $this->_events)) {
            $msg  = "Plugin event not supported. The plugin handler supports ";
            $msg .= "'".implode("', '", $this->_events)."'";
            throw new LogicException($msg);
        }
        
        foreach ($this->_plugins as $plugin) {
            $plugin->$event();
        }
    }
{'fraction_non_alphanumeric': 0.11450518042157913, 'fraction_numerical': 0.003036798856734548, 'mean_word_length': 1.9207094418362023, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '346228', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1578, 'n_words': 370}