lithium\net\http\Router::_matchOptions()

protected static method

Initialize options for Router::match().

Parameters

  • string|array $url

    Options to match to a URL. Optionally, this can be a string containing a manually generated URL.

  • \lithium\action\Request $context
  • array $options

    Options for the generation of the matched URL.

Returns

array

The initialized options.

Source

	protected static function _matchOptions(&$url, $context, $options) {
		$defaults = array(
			'scheme' => null,
			'host' => null,
			'absolute' => false,
			'base' => ''
		);
		if ($context) {
			$defaults = array(
				'base' => $context->env('base'),
				'host' => $context->host,
				'scheme' => $context->scheme . ($context->scheme ? '://' : '//')
			) + $defaults;
		}

		$options += array('scope' => static::scope());
		$vars = array();
		$scope = $options['scope'];
		if (is_array($scope)) {
			list($tmp, $vars) = each($scope);
			if (!is_array($vars)) {
				$vars = $scope;
				$scope = static::scope();
			} else {
				$scope = $tmp;
			}
		}
		if ($config = static::attached($scope, $vars)) {
			if (is_array($url)) {
				unset($url['library']);
			}
			$config['host'] = $config['host'] ? : $defaults['host'];
			if ($config['scheme'] === false) {
				$config['scheme'] = '//';
			} else {
				$config['scheme'] .= ($config['scheme'] ? '://' : $defaults['scheme']);
			}
			$config['scheme'] = $config['scheme'] ? : 'http://';

			$base = isset($config['base']) ? '/' . $config['base'] : $defaults['base'];
			$base = $base . ($config['prefix'] ? '/' . $config['prefix'] : '');
			$config['base'] = rtrim($config['absolute'] ? '/' . trim($base, '/') : $base, '/');
			$defaults = $config + $defaults;
		}
		return $options + $defaults;
	}