['formatter' => 'strtolower'], 'script' => ['formatter' => ['strtolower', 'ucfirst']], 'territory' => ['formatter' => 'strtoupper'], 'variant' => ['formatter' => 'strtoupper'] ]; /** * Magic method enabling `language`, `script`, `territory` and `variant` * methods to parse and retrieve individual tags from a locale. * * ``` * Locale::language('en_US'); // returns 'en' * Locale::territory('en_US'); // returns 'US' * ``` * * @see lithium\g11n\Locale::$_tags * @see lithium\g11n\Locale::decompose() * @param string $method * @param array $params * @return mixed */ public static function __callStatic($method, $params = []) { $tags = static::decompose(current($params)); if (!isset(static::$_tags[$method])) { throw new BadMethodCallException("Invalid locale tag `{$method}`."); } return isset($tags[$method]) ? $tags[$method] : null; } /** * Determines if a given method can be called. * * @deprecated * @param string $method Name of the method. * @param boolean $internal Provide `true` to perform check from inside the * class/object. When `false` checks also for public visibility; * defaults to `false`. * @return boolean Returns `true` if the method can be called, `false` otherwise. */ public static function respondsTo($method, $internal = false) { $message = '`' . __METHOD__ . '()` has been deprecated. '; $message .= "Use `is_callable('::')` instead."; trigger_error($message, E_USER_DEPRECATED); return isset(static::$_tags[$method]) || parent::respondsTo($method, $internal); } /** * Composes a locale from locale tags. This is the pendant to `Locale::decompose()`. * * @param array $tags An array as obtained from `Locale::decompose()`. * @return string A locale with tags separated by underscores or `null` * if none of the passed tags could be used to compose a locale. */ public static function compose($tags) { $result = []; foreach (static::$_tags as $name => $tag) { if (isset($tags[$name])) { $result[] = $tags[$name]; } } if ($result) { return implode('_', $result); } } /** * Parses a locale into locale tags. This is the pendant to `Locale::compose()``. * * @param string $locale A locale in an arbitrary form (i.e. `'en_US'` or `'EN-US'`). * @return array Parsed language, script, territory and variant tags. * @throws InvalidArgumentException */ public static function decompose($locale) { $regex = '(?P[a-z]{2,3})'; $regex .= '(?:[_-](?P