<commit_before><commit_msg>Added new KMixinEventlistener to allow any object to expose addEventListener and removeEventListener API's. The mixin contains it's own event dispatcher, or an dispatcher can be injected.<commit_after><?php
/**
 * @version     $Id$
 * @category	Koowa
 * @package     Koowa_Mixin
 * @copyright   Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Event Dispatcher Mixin
 * 
 * Class can be used as a mixin in classes that want to implement a an
 * event dispatcher and allow adding and removing listeners.
 *  
 * @author      <NAME> <<EMAIL>>
 * @category    Koowa
 * @package     Koowa_Mixin
 * @uses        KEventDispatcher
 */
class KMixinEventlistener extends KMixinAbstract
{   
    /**
     * Event dispatcher object
     *
     * @var KEventDispatcher
     */
    protected $_event_dispatcher;
    
    /**
     * Object constructor
     *
     * @param   object  An optional KConfig object with configuration options
     */
    public function __construct(KConfig $config)
    {
        parent::__construct($config);
            
        //Create a event dispatcher object
        $this->_event_dispatcher = $config->event_dispatcher;
    }
    
    /**
     * Initializes the options for the object
     * 
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional KConfig object with configuration options
     * @return  void
     */
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'event_dispatcher' => new KEventDispatcher(),
        ));
        
        parent::_initialize($config);
    }
    
	/**
     * Get the event dispatcher
     *
     * @return  KEventDispatcher
     */
    public function getEventDispatcher()
    {
        return $this->_event_dispatcher;
    }
    
    /**
     * Set the chain of command object
     *
     * @param   object 		An event dispatcher object
     * @return  KObject     The mixer object
     */
    public function setEventDispatcher(KEventDispatcher $dispatcher)
    {
        $this->_event_dispatcher = $dispatcher;
        return $this->_mixer;
    }
    
	/**
     * Add an event listener
     *
     * @param  string  The event name
     * @param  object  An object implementing the KObjectHandlable interface
     * @param  integer The event priority, usually between 1 (high priority) and 5 (lowest), 
     *                 default is 3. If no priority is set, the command priority will be used 
     *                 instead.
     * @return  KObject The mixer objects
     */
    public function addEventListener($event, KObjectHandable $listener, $priority = KEvent::PRIORITY_NORMAL)
    {
        $this->_event_dispatcher->addEventListener($event, $listener, $priority);
        return $this->_mixer;
    }

    /**
     * Remove an event listener
     *
     * @param   string  The event name
     * @param   object  An object implementing the KObjectHandlable interface
     * @return  KObject  The mixer object
     */
    public function removeEventListener($event, KObjectHandable $listener)
    {
        $this->_event_dispatcher->removeEventListener($event, $listener, $priority);
        return $this->_mixer;
    }
}
{'fraction_non_alphanumeric': 0.08988095238095238, 'fraction_numerical': 0.0035714285714285713, 'mean_word_length': 2.3376365441906652, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5926671', 'n_tokens_mistral': 938, 'n_tokens_neox': 910, 'n_words': 283}