<commit_before><?php
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');

/**
 * Permit component class
 *
 * Manages user access to a given route
 *
 * @package       sanction
 * @subpackage    sanction.controller.components
 */
class PermitComponent extends Component {

/**
 * Other components utilized by PermitComponent
 *
 * @public array
 * @access public
 */
	public $components = array('Session');

/**
 * Parameter data from Controller::$params
 *
 * @public array
 * @access public
 */
	public $settings = array(
		'path' => 'Auth.User',
		'check' => 'id',
		'isTest' => false,
	);

/**
 * Array of routes connected with PermitComponent::access()
 *
 * @public array
 * @access public
 */
	public $routes = array();

/**
 * Array containing executed route
 *
 * @public array
 * @access public
 */
	public $executed = null;

/**
 * Maintains current logged in user.
 *
 * @public boolean
 * @access protected
 */
	public $_user = null;

/**
 * Current request parameters
 *
 * @public array
 */
	public $_requestParams = array();

/**
 * Constructor.
 *
 * @param ComponentCollection $collection
 * @param array $settings
 */
	public function __construct(ComponentCollection $collection, $settings = array()) {
		$settings = array_merge($this->settings, $settings);

		if (!$settings['isTest']) {
			if (!include(APP . 'Config' . DS . 'permit.php')) {
				trigger_error("File containing permissions not found.  It should be located at " . APP_PATH . DS . 'config' . DS . "permit.php", E_USER_ERROR);
			}
		}

		parent::__construct($collection, $settings);
		Permit::$settings = $this->settings;
	}

/**
 * Initializes SanctionComponent for use in the controller
 *
 * @param object $controller A reference to the instantiating controller object
 * @return void
 * @access public
 */
	public function initialize($controller) {
		if ($this->settings['isTest']) {
			return;
		}

		$this->_user = $this->Session->read("{$this->settings['path']}");

		$this->routes = Permit::$routes;
		Permit::$user = $this->_user;

		$this->request = $controller->request;

		foreach (array('controller', 'plugin') as $inflected) {
			if (isset($this->request->params[$inflected])) {
				$this->request->params[$inflected] = strtolower(Inflector::underscore($this->request->params[$inflected]));
			}
		}
	}


/**
 * Main execution method.  Handles redirecting of invalid users, and saving
 * of request url as Sanction.referer
 *
 * @param object $controller A reference to the instantiating controller object
 * @return boolean
 * @access public
 */
	function startup(&$controller) {
		if ($this->settings['isTest']) {
			return;
		}

		foreach ($this->routes as $route) {
			if ($this->_parse($route['route'])) {
				if ($this->_execute($route)) {
					if (isset($this->request->params['url']['url'])) {
						$url = $this->request->params['url']['url'];
					} else {
						$url = $this->request->params;
					}

					$url = Router::normalize($url);
					if (!empty($this->request->params['url']) && count($this->request->params['url']) >= 2) {
						$query = $this->request->params['url'];
						unset($query['url'], $query['ext']);
						$url .= Router::queryString($query, array());
					}
					$this->Session->write('Sanction.referer', $url);
					$this->redirect($controller, $route);
				}
				break;
			}
		}
	}

/**
 * Parses a given Permit route to see if it matches the current request
 *
 * @param object $controller A reference to the instantiating controller object
 * @param array $route A Permit Route
 * @return boolean true if current request matches Permit route, false otherwise
 * @access protected
 */
	function _parse($route) {
		$count = count($route);
		if ($count == 0) {
			return false;
		}

		foreach ($route as $key => $value) {
			if (isset($this->request->params[$key])) {
				$values = (array) $value;
				$check = (array) $this->request->params[$key];

				if (!count($values) && in_array(null, $check)) {
					$count--;
					continue;
				}

				if (in_array($key, array('controller', 'plugin'))) {
					foreach ($check as $k => $_check) {
						$check[$k] = Inflector::underscore(strtolower($_check));
					}
				} else {
					foreach ($check as $k => $_check) {
						$check[$k] = strtolower($_check);
					}
				}

				foreach ($values as $k => $v) {
					if (in_array(strtolower($v), $check)) {
						$count--;
					}
				}
			}
		}
		return ($count == 0);
	}
<commit_msg>properly reference CakeRequest::$query in 2.0<commit_after><?php
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');

/**
 * Permit component class
 *
 * Manages user access to a given route
 *
 * @package       sanction
 * @subpackage    sanction.controller.components
 */
class PermitComponent extends Component {

/**
 * Other components utilized by PermitComponent
 *
 * @public array
 * @access public
 */
	public $components = array('Session');

/**
 * Parameter data from Controller::$params
 *
 * @public array
 * @access public
 */
	public $settings = array(
		'path' => 'Auth.User',
		'check' => 'id',
		'isTest' => false,
	);

/**
 * Array of routes connected with PermitComponent::access()
 *
 * @public array
 * @access public
 */
	public $routes = array();

/**
 * Array containing executed route
 *
 * @public array
 * @access public
 */
	public $executed = null;

/**
 * Maintains current logged in user.
 *
 * @public boolean
 * @access protected
 */
	public $_user = null;

/**
 * Current request parameters
 *
 * @public array
 */
	public $_requestParams = array();

/**
 * Constructor.
 *
 * @param ComponentCollection $collection
 * @param array $settings
 */
	public function __construct(ComponentCollection $collection, $settings = array()) {
		$settings = array_merge($this->settings, $settings);

		if (!$settings['isTest']) {
			if (!include(APP . 'Config' . DS . 'permit.php')) {
				trigger_error("File containing permissions not found.  It should be located at " . APP_PATH . DS . 'config' . DS . "permit.php", E_USER_ERROR);
			}
		}

		parent::__construct($collection, $settings);
		Permit::$settings = $this->settings;
	}

/**
 * Initializes SanctionComponent for use in the controller
 *
 * @param object $controller A reference to the instantiating controller object
 * @return void
 * @access public
 */
	public function initialize($controller) {
		if ($this->settings['isTest']) {
			return;
		}

		$this->_user = $this->Session->read("{$this->settings['path']}");

		$this->routes = Permit::$routes;
		Permit::$user = $this->_user;

		$this->request = $controller->request;

		foreach (array('controller', 'plugin') as $inflected) {
			if (isset($this->request->params[$inflected])) {
				$this->request->params[$inflected] = strtolower(Inflector::underscore($this->request->params[$inflected]));
			}
		}
	}


/**
 * Main execution method.  Handles redirecting of invalid users, and saving
 * of request url as Sanction.referer
 *
 * @param object $controller A reference to the instantiating controller object
 * @return boolean
 * @access public
 */
	function startup(&$controller) {
		if ($this->settings['isTest']) {
			return;
		}

		foreach ($this->routes as $route) {
			if (!$this->_parse($route['route'])) {
				continue;
			}

			if (!$this->_execute($route)) {
				break;
			}

			$url = Router::normalize($this->request->params);
			if (!empty($this->request->query)) {
				$url .= Router::queryString($this->request->query, array());
			}

			$this->Session->write('Sanction.referer', $url);
			return $this->redirect($controller, $route);
		}
	}

/**
 * Parses a given Permit route to see if it matches the current request
 *
 * @param object $controller A reference to the instantiating controller object
 * @param array $route A Permit Route
 * @return boolean true if current request matches Permit route, false otherwise
 * @access protected
 */
	function _parse($route) {
		$count = count($route);
		if ($count == 0) {
			return false;
		}

		foreach ($route as $key => $value) {
			if (isset($this->request->params[$key])) {
				$values = (array) $value;
				$check = (array) $this->request->params[$key];

				if (!count($values) && in_array(null, $check)) {
					$count--;
					continue;
				}

				if (in_array($key, array('controller', 'plugin'))) {
					foreach ($check as $k => $_check) {
						$check[$k] = Inflector::underscore(strtolower($_check));
					}
				} else {
					foreach ($check as $k => $_check) {
						$check[$k] = strtolower($_check);
					}
				}

				foreach ($values as $k => $v) {
					if (in_array(strtolower($v), $check)) {
						$count--;
					}
				}
			}
		}

		return ($count == 0);
	}

{'fraction_non_alphanumeric': 0.17200185571793086, 'fraction_numerical': 0.0008118765947575968, 'mean_word_length': 3.5146596858638746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1546344', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2647, 'n_words': 695}