<commit_before><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Controller
 * @subpackage	Command
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Commandable Controller Behavior Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorCommandable extends KControllerBehaviorAbstract
{  
	/**
	 * Toolbar object or identifier (com://APP/COMPONENT.model.NAME)
	 *
	 * @var	string|object
	 */
	protected $_toolbar;
	
	/**
	 * Constructor
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 */
	public function __construct(KConfig $config)
	{
		parent::__construct($config);

		$this->_toolbar = $config->toolbar;
	}
	
	/**
     * Initializes the default configuration 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(
    		'toolbar'	=> null,
        ));
 
        parent::_initialize($config);
    }
      	
	/**
	 * Get the view object attached to the controller
	 *
	 * @throws  KControllerException if the view cannot be found.
	 * @return	KControllerToolbarAbstract 
	 */
    public function getToolbar()
    { 
        if(!$this->_toolbar instanceof KControllerToolbarAbstract)
		{	   
		    //Make sure we have a view identifier
		    if(!($this->_toolbar instanceof KIdentifier)) {
		        $this->setToolbar($this->_toolbar);
			}
		
			$config = array(
			    'controller' => $this->getMixer()
			);
			
			$this->_toolbar = KFactory::get($this->_toolbar, $config);
		}    
         
        return $this->_toolbar;
    }
	
	/**
	 * Method to set a toolbar object attached to the controller
	 *
	 * @param	mixed	An object that implements KObjectIdentifiable, an object that
	 *                  implements KIdentifierInterface or valid identifier string
	 * @throws	KControllerBehaviorException	If the identifier is not a view identifier
	 * @return	KControllerToolbarAbstract 
	 */
    public function setToolbar($toolbar)
    {
        if(!($toolbar instanceof KControllerToolbarAbstract))
		{
			if(is_string($toolbar) && strpos($toolbar, '.') === false ) 
		    {
			    $identifier         = clone $this->_identifier;
                $identifier->path   = array('controller', 'toolbar');
                $identifier->name   = $toolbar;
			}
			else $identifier = KIdentifier::identify($toolbar);
			
			if($identifier->path[1] != 'toolbar') {
				throw new KControllerBehaviorException('Identifier: '.$identifier.' is not a toolbar identifier');
			}

			$toolbar = $identifier;
		}
		
		$this->_toolbar = $toolbar;
        
        return $this;
    }
    
    /**
	 * Add default toolbar commands
	 * .
	 * @param	KCommandContext	A command context object
	 */
    protected function _beforeGet(KCommandContext $context)
    {
        if(!$this->_toolbar) {
            $this->setToolbar($this->getView()->getName());
        }<commit_msg>re #135 : Use KObject->getService() instead of KFactory::get() and KObject->getIdentifier() instead of KIdentifier::identify().<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Controller
 * @subpackage	Command
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Commandable Controller Behavior Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorCommandable extends KControllerBehaviorAbstract
{  
	/**
	 * Toolbar object or identifier (com://APP/COMPONENT.model.NAME)
	 *
	 * @var	string|object
	 */
	protected $_toolbar;
	
	/**
	 * Constructor
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 */
	public function __construct(KConfig $config)
	{
		parent::__construct($config);

		$this->_toolbar = $config->toolbar;
	}
	
	/**
     * Initializes the default configuration 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(
    		'toolbar'	=> null,
        ));
 
        parent::_initialize($config);
    }
      	
	/**
	 * Get the view object attached to the controller
	 *
	 * @throws  KControllerException if the view cannot be found.
	 * @return	KControllerToolbarAbstract 
	 */
    public function getToolbar()
    { 
        if(!$this->_toolbar instanceof KControllerToolbarAbstract)
		{	   
		    //Make sure we have a view identifier
		    if(!($this->_toolbar instanceof KServiceIdentifier)) {
		        $this->setToolbar($this->_toolbar);
			}
		
			$config = array(
			    'controller' => $this->getMixer()
			);
			
			$this->_toolbar = $this->getService($this->_toolbar, $config);
		}    
         
        return $this->_toolbar;
    }
	
	/**
	 * Method to set a toolbar object attached to the controller
	 *
	 * @param	mixed	An object that implements KObjectServiceable, KServiceIdentifier object 
	 * 					or valid identifier string
	 * @throws	KControllerBehaviorException	If the identifier is not a view identifier
	 * @return	KControllerToolbarAbstract 
	 */
    public function setToolbar($toolbar)
    {
        if(!($toolbar instanceof KControllerToolbarAbstract))
		{
			if(is_string($toolbar) && strpos($toolbar, '.') === false ) 
		    {
			    $identifier         = clone $this->getIdentifier();
                $identifier->path   = array('controller', 'toolbar');
                $identifier->name   = $toolbar;
			}
			else $identifier = $this->getIdentifier($toolbar);
			
			if($identifier->path[1] != 'toolbar') {
				throw new KControllerBehaviorException('Identifier: '.$identifier.' is not a toolbar identifier');
			}

			$toolbar = $identifier;
		}
		
		$this->_toolbar = $toolbar;
        
        return $this;
    }
    
    /**
	 * Add default toolbar commands
	 * .
	 * @param	KCommandContext	A command context object
	 */
    protected function _beforeGet(KCommandContext $context)
    {
        if(!$this->_toolbar) {
            $this->setToolbar($this->getView()->getName());
        }
{'fraction_non_alphanumeric': 0.12170110088976022, 'fraction_numerical': 0.0034685567787664, 'mean_word_length': 2.755379388448471, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 61, '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': '5213798', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1856, 'n_words': 488}