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

protected static method

Helper method for listing registered media types. Returns all types, or a single content type if a specific type is specified.

Parameters

  • string $type

    Type to return.

Returns

mixed

Array of types, or single type requested.

Source

	protected static function _types($type = null) {
		$types = static::$_types + [
			'html'         => ['text/html', 'application/xhtml+xml', '*/*'],
			'htm'          => ['alias' => 'html'],
			'form'         => ['application/x-www-form-urlencoded', 'multipart/form-data'],
			'json'         => ['application/json'],
			'rss'          => ['application/rss+xml'],
			'atom'         => ['application/atom+xml'],
			'css'          => ['text/css'],
			'js'           => ['application/javascript', 'text/javascript'],
			'text'         => ['text/plain'],
			'txt'          => ['alias' => 'text'],
			'xml'          => ['application/xml', 'application/soap+xml', 'text/xml']
		];

		if (!$type) {
			return $types;
		}
		if (strpos($type, '/') === false) {
			return isset($types[$type]) ? $types[$type] : null;
		}
		if (strpos($type, ';')) {
			list($type) = explode(';', $type, 2);
		}
		$result = [];

		foreach ($types as $name => $cTypes) {
			if ($type === $cTypes || (is_array($cTypes) && in_array($type, $cTypes))) {
				$result[] = $name;
			}
		}
		if (count($result) === 1) {
			return reset($result);
		}
		return $result ?: null;
	}