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 = [
			'scheme' => null,
			'host' => null,
			'absolute' => false,
			'base' => ''
		];
		if ($context) {
			$defaults = [
				'base' => $context->env('base'),
				'host' => $context->host,
				'scheme' => $context->scheme . ($context->scheme ? '://' : '//')
			] + $defaults;
		}

		$options += ['scope' => static::scope()];
		$vars = [];
		$scope = $options['scope'];
		if (is_array($scope)) {
			$tmp = key($scope);
			$vars = current($scope);

			if (!is_array($vars)) {
				$vars = $scope;
				$scope = static::scope();
			} else {
				$scope = $tmp;
			}
		}
		if ($config = static::attached($scope, $vars)) {
			if (is_array($url) && $config['library'] !== false) {
				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;
	}