lithium\net\http\Route::match()

public method

Matches a set of parameters against the route, and returns a URL string if the route matches the parameters.

Parameters

  • array $options

    An array of parameters.

Returns

string|boolean

URL string on success, else false if the route didn't match.

Source

	public function match(array $options = []) {
		$defaults = ['action' => 'index', 'http:method' => 'GET'];
		$query = null;

		if (!$this->_config['continue']) {
			$options += $defaults;

			if (isset($options['?'])) {
				$query = $options['?'];
				$query = '?' . (is_array($query) ? http_build_query($query) : $query);
				unset($options['?']);
			}
		}
		if (!$options = $this->_matchMethod($options)) {
			return false;
		}
		if (!$options = $this->_matchKeys($options)) {
			return false;
		}
		foreach ($options as $key => $value) {
			if (isset($this->_config['formatters'][$key])) {
				$options[$key] = $this->_config['formatters'][$key]($value);
			}
		}
		foreach ($this->_subPatterns as $key => $pattern) {
			if (isset($options[$key]) && !preg_match("/^{$pattern}$/", $options[$key])) {
				return false;
			}
		}
		$defaults = $this->_defaults + $defaults;

		if ($this->_config['continue']) {
			return $this->_write(['args' => '{:args}'] + $options, $this->_defaults);
		}
		return $this->_write($options, $defaults + ['args' => '']) . $query;
	}