2013-03-01 17:49:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Intl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gives access to internationalization data.
|
|
|
|
*
|
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
2014-09-15 12:39:24 +01:00
|
|
|
final class Intl
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The number of resource bundles to buffer. Loading the same resource
|
|
|
|
* bundle for n locales takes up n spots in the buffer.
|
|
|
|
*/
|
|
|
|
const BUFFER_SIZE = 10;
|
|
|
|
|
2014-09-15 12:39:24 +01:00
|
|
|
/**
|
|
|
|
* The directory name of the currency data.
|
|
|
|
*/
|
|
|
|
const CURRENCY_DIR = 'currencies';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The directory name of the language data.
|
|
|
|
*/
|
|
|
|
const LANGUAGE_DIR = 'languages';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The directory name of the script data.
|
|
|
|
*/
|
|
|
|
const SCRIPT_DIR = 'scripts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The directory name of the locale data.
|
|
|
|
*/
|
|
|
|
const LOCALE_DIR = 'locales';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The directory name of the region data.
|
|
|
|
*/
|
|
|
|
const REGION_DIR = 'regions';
|
|
|
|
|
2018-10-01 09:53:57 +01:00
|
|
|
/**
|
|
|
|
* The directory name of the zone data.
|
|
|
|
*/
|
|
|
|
public const TIMEZONE_DIR = 'timezones';
|
|
|
|
|
2013-03-01 17:49:04 +00:00
|
|
|
/**
|
2014-04-16 11:30:19 +01:00
|
|
|
* @var string|bool|null
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
|
|
|
private static $icuVersion = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $icuDataVersion = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the intl extension is installed.
|
|
|
|
*
|
2016-06-28 06:50:50 +01:00
|
|
|
* @return bool Returns true if the intl extension is installed, false otherwise
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
2019-06-11 11:13:09 +01:00
|
|
|
public static function isExtensionLoaded(): bool
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
2013-04-04 17:26:59 +01:00
|
|
|
return class_exists('\ResourceBundle');
|
2013-03-01 17:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the version of the installed ICU library.
|
|
|
|
*
|
2018-10-02 04:12:00 +01:00
|
|
|
* @return string|null The ICU version or NULL if it could not be determined
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
2019-06-11 11:13:09 +01:00
|
|
|
public static function getIcuVersion(): ?string
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
|
|
|
if (false === self::$icuVersion) {
|
2013-03-15 12:39:37 +00:00
|
|
|
if (!self::isExtensionLoaded()) {
|
|
|
|
self::$icuVersion = self::getIcuStubVersion();
|
2018-07-05 12:24:53 +01:00
|
|
|
} elseif (\defined('INTL_ICU_VERSION')) {
|
2013-03-01 17:49:04 +00:00
|
|
|
self::$icuVersion = INTL_ICU_VERSION;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$reflector = new \ReflectionExtension('intl');
|
|
|
|
ob_start();
|
|
|
|
$reflector->info();
|
|
|
|
$output = strip_tags(ob_get_clean());
|
|
|
|
preg_match('/^ICU version (?:=>)?(.*)$/m', $output, $matches);
|
|
|
|
|
|
|
|
self::$icuVersion = trim($matches[1]);
|
|
|
|
} catch (\ReflectionException $e) {
|
|
|
|
self::$icuVersion = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$icuVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the version of the installed ICU data.
|
|
|
|
*
|
2016-06-28 06:50:50 +01:00
|
|
|
* @return string The version of the installed ICU data
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
2019-06-11 11:13:09 +01:00
|
|
|
public static function getIcuDataVersion(): string
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
|
|
|
if (false === self::$icuDataVersion) {
|
2014-09-15 12:39:24 +01:00
|
|
|
self::$icuDataVersion = trim(file_get_contents(self::getDataDirectory().'/version.txt'));
|
2013-03-01 17:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self::$icuDataVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ICU version that the stub classes mimic.
|
|
|
|
*
|
2016-06-28 06:50:50 +01:00
|
|
|
* @return string The ICU version of the stub classes
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
2019-06-11 11:13:09 +01:00
|
|
|
public static function getIcuStubVersion(): string
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
2019-10-04 04:55:12 +01:00
|
|
|
return '65.1';
|
2013-03-01 17:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-15 12:39:24 +01:00
|
|
|
* Returns the absolute path to the data directory.
|
2013-03-01 17:49:04 +00:00
|
|
|
*
|
2014-09-15 12:39:24 +01:00
|
|
|
* @return string The absolute path to the data directory
|
2013-03-01 17:49:04 +00:00
|
|
|
*/
|
2019-06-11 11:13:09 +01:00
|
|
|
public static function getDataDirectory(): string
|
2013-03-01 17:49:04 +00:00
|
|
|
{
|
2016-10-25 09:15:38 +01:00
|
|
|
return __DIR__.'/Resources/data';
|
2014-09-15 12:39:24 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 17:49:04 +00:00
|
|
|
/**
|
|
|
|
* This class must not be instantiated.
|
|
|
|
*/
|
2014-09-21 19:53:12 +01:00
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
2013-03-01 17:49:04 +00:00
|
|
|
}
|