lithium\net\http\Media::_assetOptions()

protected static method

Initialize options for Media::asset().

Parameters

  • string $path

    The path to the asset.

  • string $type

    The asset type.

  • array $options

    Contains setting for finding and handling the path.

Returns

array

The initialized options.

Source

	protected static function _assetOptions($path, $type, $options) {
		$defaults = [
			'base' => null,
			'timestamp' => false,
			'filter' => null,
			'paths' => [],
			'suffix' => null,
			'check' => false,
			'library' => true
		];

		$base = isset($options['base']) ? rtrim($options['base'], '/') : '';
		$options += ['scope' => static::scope()];
		$name = $options['scope'];

		if ($config = static::attached($name)) {
			$base = isset($config['base']) ? '/' . $config['base'] : $base;
			$defaults = array_merge($defaults, $config);

			if (preg_match('/^((?:[a-z0-9-]+:)?\/\/)([^\/]*)/i', $base, $match)) {
				$options = array_merge($defaults, [
					'base' => rtrim($base . '/' . $defaults['prefix'], '/')
				]);
			} else {
				$host = '';

				if ($defaults['absolute']) {
					$host = $defaults['host'];

					if (is_array($host)) {
						$hash = substr(hexdec(md5($path)), 0, 10);
						$index = ((integer) $hash) % count($host);

						if (is_array($defaults['scheme'])) {
							$host = $defaults['scheme'][$index] . $host[$index];
						} else {
							$host = $defaults['scheme'] . $host[$index];
						}
					} else {
						$host = $defaults['scheme'] . $defaults['host'];
					}
					$base = trim($base, '/');
					$base = $base ? '/' . $base : '';
				}
				$options['base'] = rtrim($host . $base . '/' . $defaults['prefix'], '/');
			}
		}

		if (!$paths = static::_assets($type)) {
			$paths = static::_assets('generic');
		}
		return $options + $paths + $defaults;
	}