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

/**
 * Controller Discoverable Command Class
 *
 * @author		<NAME> <<EMAIL>>
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorDiscoverable extends KControllerBehaviorAbstract
{
	/**
	 * Get a list of allowed actions
	 *
     * @return  string    The allowed actions; e.g., `GET, POST [add, edit, cancel, save], PUT, DELETE`
	 */
	protected function _actionOptions(KCommandContext $context)
	{
	    $methods = array();

        //Remove GET actions
        $actions = array_diff($this->getActions(), array('browse', 'read', 'display'));

        //Authorize the action
        foreach($actions as $key => $action)
        {
            //Find the mapped action if one exists
            if (isset( $this->_action_map[$action] )) {
                $action = $this->_action_map[$action];
            }

            //Check if the action can be executed
            if($this->getBehavior('executable')->execute('before.'.$action, $context) === false) {
                unset($actions[$key]);
            }
        }

        //Sort the action alphabetically.
        sort($actions);

        //Retrieve HTTP methods
        foreach(array('get', 'put', 'delete', 'post', 'options') as $method)
        {
            if(in_array($method, $actions)) {
                $methods[strtoupper($method)] = $method;
            }
        }

        //Retrieve POST actions
        if(in_array('post', $methods))
        {
            $actions = array_diff($actions, array('get', 'put', 'delete', 'post', 'options'));
            $methods['POST'] = array_diff($actions, $methods);
        }

        //Render to string
        $result = implode(', ', array_keys($methods));

        foreach($methods as $method => $actions)
        {
           if(is_array($actions) && !empty($actions)) {
               $result = str_replace($method, $method.' ['.implode(', ', $actions).']', $result);
           }
        }

        $context->headers = array('Allow' => $result);
	}
}<commit_msg>re #252 : Use $context->response->headers to set the Allow headers<commit_after><?php
/**
 * @version		$Id$
 * @package		Koowa_Controller
 * @subpackage	Command
 * @copyright	Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Controller Discoverable Command Class
 *
 * @author		<NAME> <<EMAIL>>
 * @package     Koowa_Controller
 * @subpackage	Behavior
 */
class KControllerBehaviorDiscoverable extends KControllerBehaviorAbstract
{
	/**
	 * Get a list of allowed actions
	 *
     * @return  string    The allowed actions; e.g., `GET, POST [add, edit, cancel, save], PUT, DELETE`
	 */
	protected function _actionOptions(KCommandContext $context)
	{
	    $methods = array();

        //Remove GET actions
        $actions = array_diff($this->getActions(), array('browse', 'read', 'display'));

        //Authorize the action
        foreach($actions as $key => $action)
        {
            //Find the mapped action if one exists
            if (isset( $this->_action_map[$action] )) {
                $action = $this->_action_map[$action];
            }

            //Check if the action can be executed
            if($this->getBehavior('executable')->execute('before.'.$action, $context) === false) {
                unset($actions[$key]);
            }
        }

        //Sort the action alphabetically.
        sort($actions);

        //Retrieve HTTP methods
        foreach(array('get', 'put', 'delete', 'post', 'options') as $method)
        {
            if(in_array($method, $actions)) {
                $methods[strtoupper($method)] = $method;
            }
        }

        //Retrieve POST actions
        if(in_array('post', $methods))
        {
            $actions = array_diff($actions, array('get', 'put', 'delete', 'post', 'options'));
            $methods['POST'] = array_diff($actions, $methods);
        }

        //Render to string
        $result = implode(', ', array_keys($methods));

        foreach($methods as $method => $actions)
        {
           if(is_array($actions) && !empty($actions)) {
               $result = str_replace($method, $method.' ['.implode(', ', $actions).']', $result);
           }
        }

        $context->response->headers->set('Allow', $result);
	}
}
{'fraction_non_alphanumeric': 0.15840938722294653, 'fraction_numerical': 0.0045632333767926985, 'mean_word_length': 2.2438336856941508, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 34, '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': '6886074', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1305, 'n_words': 319}