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

/**
 * Abstract controller dispatcher
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Dispatcher
 * @uses		KMixinClass
 * @uses        KObject
 * @uses        KFactory
 */
abstract class KDispatcherAbstract extends KControllerAbstract
{
	/**
	 * Controller object or identifier (APP::com.COMPONENT.controller.NAME)
	 *
	 * @var	string|object
	 */
	protected $_controller;
	
	/**
	 * The request persistency
	 * 
	 * @var boolean
	 */
	protected $_request_persistent;

	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 */
	public function __construct(KConfig $config)
	{
		parent::__construct($config);
		
		//Set the request persistency
		$this->_request_persistent = $config->request_persistent;
		
		//Set the controller
		$this->_controller = $config->controller;
		
		if(KRequest::method() != 'GET') {
			$this->registerCallback('after.dispatch' , array($this, 'forward'));
	  	}

	    $this->registerCallback('after.dispatch', array($this, 'render'));
	}

    /**
     * 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(
        	'controller'			=> $this->_identifier->package,
    		'request'				=> KRequest::get('get', 'string'),
    		'request_persistent' 	=> false
        ))->append(array(
            'request' 				=> array('format' => KRequest::format() ? KRequest::format() : 'html')
        ));

        parent::_initialize($config);
    }
    
	/**
	 * Method to get a controller object
	 *
	 * @return	KControllerAbstract
	 */
	public function getController()
	{
		if(!($this->_controller instanceof KControllerAbstract))
		{  
		    //Make sure we have a controller identifier
		    if(!($this->_controller instanceof KIdentifier)) {
		        $this->setController($this->_controller);
			}
		    
		    $config = array(
        		'request' 	   => $this->_request,
        		'persistent'   => $this->_request_persistent,
			    'dispatched'   => true	
        	);
        	
			$this->_controller = KFactory::tmp($this->_controller, $config);
		}
	
		return $this->_controller;
	}

	/**
	 * Method to set a controller object attached to the dispatcher
	 *
	 * @param	mixed	An object that implements KObjectIdentifiable, an object that
	 *                  implements KIdentifierInterface or valid identifier string<commit_msg>- Removed request_persistent class property and config option.  - The controller persistable behavior is now being set in the KDispatcherAbstract::getController() function.<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Dispatcher
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Abstract controller dispatcher
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Dispatcher
 * @uses		KMixinClass
 * @uses        KObject
 * @uses        KFactory
 */
abstract class KDispatcherAbstract extends KControllerAbstract
{
	/**
	 * Controller object or identifier (APP::com.COMPONENT.controller.NAME)
	 *
	 * @var	string|object
	 */
	protected $_controller;

	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 */
	public function __construct(KConfig $config)
	{
		parent::__construct($config);
		
		//Set the controller
		$this->_controller = $config->controller;
		
		if(KRequest::method() != 'GET') {
			$this->registerCallback('after.dispatch' , array($this, 'forward'));
	  	}

	    $this->registerCallback('after.dispatch', array($this, 'render'));
	}

    /**
     * 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(
        	'controller'			=> $this->_identifier->package,
    		'request'				=> KRequest::get('get', 'string'),
        ))->append(array(
            'request' 				=> array('format' => KRequest::format() ? KRequest::format() : 'html')
        ));

        parent::_initialize($config);
    }
    
	/**
	 * Method to get a controller object
	 *
	 * @return	KControllerAbstract
	 */
	public function getController()
	{
		if(!($this->_controller instanceof KControllerAbstract))
		{  
		    //Make sure we have a controller identifier
		    if(!($this->_controller instanceof KIdentifier)) {
		        $this->setController($this->_controller);
			}
			
			/* 
         	 * Disable controller persistency on non-HTTP requests, e.g. AJAX, and requests containing 
         	 * the tmpl variable set to component, e.g. requests using modal boxes. This avoids 
         	 * changing the model state session variable of the requested model, which is often 
         	 * undesirable under these circumstances. 
         	 */  
            $persistable = (KRequest::type() == 'HTTP' && KRequest::get('get.tmpl','cmd') != 'component');
		    
		    $config = array(
        		'request' 	   => $this->_request,
        		'persistable'  => $persistable,
			    'dispatched'   => true	
        	);
        	
			$this->_controller = KFactory::tmp($this->_controller, $config);
		}
	
		return $this->_controller;
	}

	/**
	 * Method to set a controller object attached to the dispatcher
	 *
	 * @param	mixed	An object that implements KObjectIdentifiable, an object that
	 *                  implements KIdentifierInterface or valid identifier string
{'fraction_non_alphanumeric': 0.1286578388098741, 'fraction_numerical': 0.0029426189308484553, 'mean_word_length': 2.804726368159204, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 63, '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': '6261397', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1745, 'n_words': 457}