<commit_before><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Command
 * @copyright	Copyright (C) 2007 - 2010 <NAME> and <NAME>. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.koowa.org
 */

/**
 * Command handler
 * 
 * The command handler will translate the command name into a function format and 
 * call it for the object class to handle it if the method exists.
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Command
 * @uses 		KInflector
 */
class KCommand extends KObject implements KCommandInterface 
{
	/**
	 * Priority levels
	 */
	const PRIORITY_HIGHEST = 1;
	const PRIORITY_HIGH    = 2;
	const PRIORITY_NORMAL  = 3;
	const PRIORITY_LOW     = 4;
	const PRIORITY_LOWEST  = 5;
	
	/**
	 * Command handler
	 * 
	 * @param 	string  	The command name
	 * @param 	object   	The command context
	 * @return 	boolean		Can return both true or false.  
	 */
	final public function execute( $name, KCommandContext $context) 
	{
		$type = '';
		
		if($context->caller)
		{
			$identifier = clone $context->caller->getIdentifier();
			
			if($identifier->path) {
				$type = array_shift($identifier->path);
			} else {
				$type = $identifier->name;
			}
		}
		
		$parts  = explode('.', $name);	
		$method = '_'.$type.ucfirst(KInflector::implode($parts));
	
		if(in_array($method, $this->getMethods())) {
			return $this->$method($context);
		}
		
		return true;
	}
}<commit_msg>re #99 : Re-merged from branches/99-toolbar<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Command
 * @copyright	Copyright (C) 2007 - 2010 <NAME> and <NAME>. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.koowa.org
 */

/**
 * Command handler
 * 
 * The command handler will translate the command name into a function format and 
 * call it for the object class to handle it if the method exists.
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Command
 * @uses 		KInflector
 */
class KCommand extends KObject implements KCommandInterface 
{
	/**
	 * Priority levels
	 */
	const PRIORITY_HIGHEST = 1;
	const PRIORITY_HIGH    = 2;
	const PRIORITY_NORMAL  = 3;
	const PRIORITY_LOW     = 4;
	const PRIORITY_LOWEST  = 5;
	
	/**
	 * The command priority
	 *
	 * @var KIdentifierInterface
	 */
	protected $_priority;
	
	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options
	 */
	public function __construct( KConfig $config = null) 
	{ 
		//If no config is passed create it
		if(!isset($config)) $config = new KConfig();
		
		parent::__construct($config);
		
		$this->_priority = $config->priority;
	}
	
	/**
     * 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(
			'priority'   => KCommand::PRIORITY_NORMAL,
	  	));

    	parent::_initialize($config);
   	}
	
	/**
	 * Command handler
	 * 
	 * @param 	string  	The command name
	 * @param 	object   	The command context
	 * @return 	boolean		Can return both true or false.  
	 */
	public function execute( $name, KCommandContext $context) 
	{
		$type = '';
				
		if($context->caller)
		{
			$identifier = clone $context->caller->getIdentifier();
			
			if($identifier->path) {
				$type = array_shift($identifier->path);
			} else {
				$type = $identifier->name;
			}
		}
		
		$parts  = explode('.', $name);	
		$method = !empty($type) ? '_'.$type.ucfirst(KInflector::implode($parts)) : '_'.lcfirst(KInflector::implode($parts));
		
		if(in_array($method, $this->getMethods())) {
			return $this->$method($context);
		}
		
		return true;
	}
	
	/**
	 * Get the priority of a behavior
	 *
	 * @return	integer The command priority
	 */
  	public function getPriority()
  	{
  		return $this->_priority;
  	}
}
{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.008763388510223954, 'mean_word_length': 2.9893203883495145, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 36, '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': '6706339', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1344, 'n_words': 360}