<commit_before><?php
/**
 * @package     Koowa_Object
 * @subpackage  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
 */

namespace Nooku\Library;

/**
 * Command Mixin
 * 
 * Class can be used as a mixin in classes that want to implement a chain of responsibility or chain of command pattern.
 *  
 * @author      <NAME> <<EMAIL>>
 * @package     Koowa_Object
 * @subpackage  Mixin
 */
class CommandMixin extends ObjectMixinAbstract
{   
    /**
     * Chain of command object
     *
     * @var CommandChain
     */
    protected $_command_chain;
    
    /**
     * Object constructor
     *
     * @param   object  An optional ObjectConfig object with configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);
        
        if(is_null($config->command_chain)) {
			throw new \InvalidArgumentException('command_chain [CommandChainInterface] config option is required');
		}
            
        //Create a command chain object 
        $this->_command_chain = $config->command_chain;
        
        //Mixin the callback mixer if callbacks have been enabled
        if($config->enable_callbacks)
        {
            $callback = new ObjectMixinCallback($config);

            //Mixin the callback mixin
            $mixin = $this->_mixer->mixin('lib:object.mixin.callback', $config);

            //Enqueue the command in the mixer's command chain
            $this->getCommandChain()->enqueue($mixin, $config->callback_priority);
        }
        
        //Enqueue the event command with a lowest priority to make sure it runs last
        if($config->dispatch_events) 
        { 
            $this->_mixer->mixin('lib:event.mixin', $config);

            $command = $this->getCommandChain()->getObject('lib:command.event', array(
            	'event_dispatcher' => $this->getEventDispatcher()
            ));

            $this->getCommandChain()->enqueue($command, $config->event_priority);
        }
    }
    
    /**
     * Initializes the options for the object
     * 
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional ObjectConfig object with configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'command_chain'     => null,
            'event_dispatcher'  => null,
            'dispatch_events'   => true,
            'event_priority'    => CommandChain::PRIORITY_LOWEST,
            'enable_callbacks'  => false,
            'callback_priority' => CommandChain::PRIORITY_HIGH,
        ));
        
        parent::_initialize($config);
    }
    <commit_msg>Use getMixer() method instead of _mixer property.<commit_after><?php
/**
 * @package     Koowa_Object
 * @subpackage  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
 */

namespace Nooku\Library;

/**
 * Command Mixin
 * 
 * Class can be used as a mixin in classes that want to implement a chain of responsibility or chain of command pattern.
 *  
 * @author      <NAME> <<EMAIL>>
 * @package     Koowa_Object
 * @subpackage  Mixin
 */
class CommandMixin extends ObjectMixinAbstract
{   
    /**
     * Chain of command object
     *
     * @var CommandChain
     */
    protected $_command_chain;
    
    /**
     * Object constructor
     *
     * @param   object  An optional ObjectConfig object with configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);
        
        if(is_null($config->command_chain)) {
			throw new \InvalidArgumentException('command_chain [CommandChainInterface] config option is required');
		}
            
        //Create a command chain object 
        $this->_command_chain = $config->command_chain;
        
        //Mixin the callback mixer if callbacks have been enabled
        if($config->enable_callbacks)
        {
            $callback = new ObjectMixinCallback($config);

            //Mixin the callback mixin
            $mixin = $this->getMixer()->mixin('lib:object.mixin.callback', $config);

            //Enqueue the command in the mixer's command chain
            $this->getCommandChain()->enqueue($mixin, $config->callback_priority);
        }
        
        //Enqueue the event command with a lowest priority to make sure it runs last
        if($config->dispatch_events) 
        {
            $this->getMixer()->mixin('lib:event.mixin', $config);

            $command = $this->getCommandChain()->getObject('lib:command.event', array(
            	'event_dispatcher' => $this->getEventDispatcher()
            ));

            $this->getCommandChain()->enqueue($command, $config->event_priority);
        }
    }
    
    /**
     * Initializes the options for the object
     * 
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   object  An optional ObjectConfig object with configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'command_chain'     => null,
            'event_dispatcher'  => null,
            'dispatch_events'   => true,
            'event_priority'    => CommandChain::PRIORITY_LOWEST,
            'enable_callbacks'  => false,
            'callback_priority' => CommandChain::PRIORITY_HIGH,
        ));
        
        parent::_initialize($config);
    }
    
{'fraction_non_alphanumeric': 0.11053270865868471, 'fraction_numerical': 0.0031233732431025507, 'mean_word_length': 2.2291316526610645, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3796335', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1553, 'n_words': 400}