<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
 */

/**
 * Controller Executable Behavior Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorExecutable extends KControllerBehaviorAbstract
{  
	/**
	 * The read-only state of the behavior
	 *
	 * @var boolean
	 */
	protected $_readonly;
		
	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options
	 */
	public function __construct( KConfig $config) 
	{
		parent::__construct($config);
		
		$this->_readonly = (bool) $config->readonly;
	}
    
    /**
     * 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(
            'priority'   => KCommand::PRIORITY_HIGH,
            'readonly'   => false,
            'auto_mixin' => true
        ));

        parent::_initialize($config);
    }
	
	/**
     * Command handler
     * 
     * Only handles before.action commands to check ACL rules.
     * 
     * @param   string      The command name
     * @param   object      The command context
     * @return  boolean     Can return both true or false.  
     * @throws  KControllerException
     */
    public function execute( $name, KCommandContext $context) 
    { 
        $parts = explode('.', $name); 
        
        if($parts[0] == 'before') 
        {
            $action = $parts[1];
            
            //Check if the action exists
            if(!in_array($action, $context->caller->getActions()))
            {
                $context->setError(new KControllerException(
            		'Action '.ucfirst($action).' Not Implemented', KHttpResponse::NOT_IMPLEMENTED
                ));
                
                $context->header = array('Allow' =>  $context->caller->execute('options', $context));
                return false;
            }
               
            //Check if the action can be executed
            $method = 'can'.ucfirst($action);
            
            if(method_exists($this, $method)) 
            {
		        if($this->$method() === false) 
		        {
		            if($context->action != 'options') 
		            {
		                $context->setError(new KControllerException(
		        			'Action '.ucfirst($action).' Not Allowed', KHttpResponse::METHOD_NOT_ALLOWED
		                ));
		        
		                $context->header = array('Allow' =>  $context->caller->execute('options', $context));  
		            }
                    
		            return false;
		        }
            }
        } 
            
        return true; 
    }
    
 	/**
     * Get an object handle
     * 
     * @return string A string that is unique, or NULL
     * @see execute()
     */
    public function getHandle()
    {
       return spl_object_hash( $this );
    }
    
    /**
     * Set the readonly state of the behavior
     * 
     * @param boolean
     * @return KControllerBehaviorExecutable
     */
    public function setReadOnly($readonly)
    {
         $this->_readonly = (bool) $readonly; 
         return $this;  
    }
    
    /**
     * Get the readonly state of the behavior
     *
     * @return boolean
     */
    public function isReadOnly()
    {
        return $this->readonly;
    }
    
	/**
     * Generic authorize handler for controller browse actions
     * 
     * @return  boolean     Can return both true or false.  
     */
    public function canBrowse()
    {
        return true;
    }
    
	/**
     * Generic authorize handler for controller read actions
     * 
     * @return  boolean     Can return both true or false.  <commit_msg>Cleanup<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
 */

/**
 * Controller Executable Behavior Class
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorExecutable extends KControllerBehaviorAbstract
{  
	/**
	 * The read-only state of the behavior
	 *
	 * @var boolean
	 */
	protected $_readonly;
		
	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options
	 */
	public function __construct( KConfig $config) 
	{
		parent::__construct($config);
		
		$this->_readonly = (bool) $config->readonly;
	}
    
    /**
     * 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(
            'priority'   => KCommand::PRIORITY_HIGH,
            'readonly'   => false,
            'auto_mixin' => true
        ));

        parent::_initialize($config);
    }
	
	/**
     * Command handler
     * 
     * Only handles before.action commands to check ACL rules.
     * 
     * @param   string      The command name
     * @param   object      The command context
     * @return  boolean     Can return both true or false.  
     * @throws  KControllerException
     */
    public function execute( $name, KCommandContext $context) 
    { 
        $parts = explode('.', $name); 
        
        if($parts[0] == 'before') 
        {
            $action = $parts[1];
            
            //Check if the action exists
            if(!in_array($action, $context->caller->getActions()))
            {
                $context->setError(new KControllerException(
            		'Action '.ucfirst($action).' Not Implemented', KHttpResponse::NOT_IMPLEMENTED
                ));
                
                $context->header = array('Allow' =>  $context->caller->execute('options', $context));
                return false;
            }
               
            //Check if the action can be executed
            $method = 'can'.ucfirst($action);
            
            if(method_exists($this, $method)) 
            {
		        if($this->$method() === false) 
		        {
		            if($context->action != 'options') 
		            {
		                $context->setError(new KControllerException(
		        			'Action '.ucfirst($action).' Not Allowed', KHttpResponse::METHOD_NOT_ALLOWED
		                ));
		        
		                $context->header = array('Allow' =>  $context->caller->execute('options', $context));  
		            }
                    
		            return false;
		        }
            }
        } 
            
        return true; 
    }
    
 	/**
     * Get an object handle
     * 
     * @return string A string that is unique, or NULL
     * @see execute()
     */
    public function getHandle()
    {
        return KMixinAbstract::getHandle();
    }
    
    /**
     * Set the readonly state of the behavior
     * 
     * @param boolean
     * @return KControllerBehaviorExecutable
     */
    public function setReadOnly($readonly)
    {
         $this->_readonly = (bool) $readonly; 
         return $this;  
    }
    
    /**
     * Get the readonly state of the behavior
     *
     * @return boolean
     */
    public function isReadOnly()
    {
        return $this->readonly;
    }
    
	/**
     * Generic authorize handler for controller browse actions
     * 
     * @return  boolean     Can return both true or false.  
     */
    public function canBrowse()
    {
        return false;
    }
    
	/**
     * Generic authorize handler for controller read actions
     * 
     * @return  boolean     Can return both true or false.  
{'fraction_non_alphanumeric': 0.11103056663042166, 'fraction_numerical': 0.002657967862752205, 'mean_word_length': 1.7194480946123523, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 57, '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': '3867855', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2228, 'n_words': 585}