From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Intl/ResourceBundle/AbstractBundle.php | 71 ++++++ .../ResourceBundle/Compiler/BundleCompiler.php | 71 ++++++ .../Compiler/BundleCompilerInterface.php | 29 +++ .../Intl/ResourceBundle/CurrencyBundle.php | 94 ++++++++ .../ResourceBundle/CurrencyBundleInterface.php | 74 ++++++ .../Intl/ResourceBundle/LanguageBundle.php | 115 ++++++++++ .../ResourceBundle/LanguageBundleInterface.php | 64 ++++++ .../Component/Intl/ResourceBundle/LocaleBundle.php | 52 +++++ .../Intl/ResourceBundle/LocaleBundleInterface.php | 41 ++++ .../ResourceBundle/Reader/AbstractBundleReader.php | 42 ++++ .../ResourceBundle/Reader/BinaryBundleReader.php | 51 +++++ .../ResourceBundle/Reader/BufferedBundleReader.php | 62 +++++ .../Reader/BundleReaderInterface.php | 40 ++++ .../Intl/ResourceBundle/Reader/PhpBundleReader.php | 61 +++++ .../Reader/StructuredBundleReader.php | 113 ++++++++++ .../Reader/StructuredBundleReaderInterface.php | 50 ++++ .../Component/Intl/ResourceBundle/RegionBundle.php | 52 +++++ .../Intl/ResourceBundle/RegionBundleInterface.php | 41 ++++ .../ResourceBundle/ResourceBundleInterface.php | 27 +++ .../Transformer/BundleTransformer.php | 96 ++++++++ .../Transformer/CompilationContext.php | 97 ++++++++ .../Transformer/CompilationContextInterface.php | 56 +++++ .../Rule/CurrencyBundleTransformationRule.php | 94 ++++++++ .../Rule/LanguageBundleTransformationRule.php | 71 ++++++ .../Rule/LocaleBundleTransformationRule.php | 251 +++++++++++++++++++++ .../Rule/RegionBundleTransformationRule.php | 70 ++++++ .../Rule/TransformationRuleInterface.php | 70 ++++++ .../ResourceBundle/Transformer/StubbingContext.php | 80 +++++++ .../Transformer/StubbingContextInterface.php | 46 ++++ .../Util/ArrayAccessibleResourceBundle.php | 79 +++++++ .../ResourceBundle/Util/RecursiveArrayAccess.php | 33 +++ .../Intl/ResourceBundle/Util/RingBuffer.php | 88 ++++++++ .../Writer/BundleWriterInterface.php | 29 +++ .../Intl/ResourceBundle/Writer/PhpBundleWriter.php | 50 ++++ .../ResourceBundle/Writer/TextBundleWriter.php | 202 +++++++++++++++++ 35 files changed, 2562 insertions(+) create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/AbstractBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/ResourceBundleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LanguageBundleTransformationRule.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/RegionBundleTransformationRule.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/TransformationRuleInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContext.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContextInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/ArrayAccessibleResourceBundle.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RecursiveArrayAccess.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RingBuffer.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/TextBundleWriter.php (limited to 'vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle') diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/AbstractBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/AbstractBundle.php new file mode 100644 index 00000000..d1d523c4 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/AbstractBundle.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface; + +/** + * Base class for {@link ResourceBundleInterface} implementations. + * + * @author Bernhard Schussek + */ +abstract class AbstractBundle implements ResourceBundleInterface +{ + /** + * @var string + */ + private $path; + + /** + * @var StructuredBundleReaderInterface + */ + private $reader; + + /** + * Creates a bundle at the given path using the given reader for reading + * bundle entries. + * + * @param string $path The path to the bundle. + * @param StructuredBundleReaderInterface $reader The reader for reading + * the bundle. + */ + public function __construct($path, StructuredBundleReaderInterface $reader) + { + $this->path = $path; + $this->reader = $reader; + } + + /** + * {@inheritdoc} + */ + public function getLocales() + { + return $this->reader->getLocales($this->path); + } + + /** + * Proxy method for {@link StructuredBundleReaderInterface#read}. + */ + protected function read($locale) + { + return $this->reader->read($this->path, $locale); + } + + /** + * Proxy method for {@link StructuredBundleReaderInterface#readEntry}. + */ + protected function readEntry($locale, array $indices, $mergeFallback = false) + { + return $this->reader->readEntry($this->path, $locale, $indices, $mergeFallback); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php new file mode 100644 index 00000000..174aa179 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Compiler; + +use Symfony\Component\Intl\Exception\RuntimeException; + +/** + * Compiles .txt resource bundles to binary .res files. + * + * @author Bernhard Schussek + */ +class BundleCompiler implements BundleCompilerInterface +{ + /** + * @var string The path to the "genrb" executable. + */ + private $genrb; + + /** + * Creates a new compiler based on the "genrb" executable. + * + * @param string $genrb Optional. The path to the "genrb" executable. + * @param string $envVars Optional. Environment variables to be loaded when + * running "genrb". + * + * @throws RuntimeException If the "genrb" cannot be found. + */ + public function __construct($genrb = 'genrb', $envVars = '') + { + exec('which ' . $genrb, $output, $status); + + if (0 !== $status) { + throw new RuntimeException(sprintf( + 'The command "%s" is not installed', + $genrb + )); + } + + $this->genrb = ($envVars ? $envVars . ' ' : '') . $genrb; + } + + /** + * {@inheritdoc} + */ + public function compile($sourcePath, $targetDir) + { + if (is_dir($sourcePath)) { + $sourcePath .= '/*.txt'; + } + + exec($this->genrb.' --quiet -e UTF-8 -d '.$targetDir.' '.$sourcePath, $output, $status); + + if ($status !== 0) { + throw new RuntimeException(sprintf( + 'genrb failed with status %d while compiling %s to %s.', + $status, + $sourcePath, + $targetDir + )); + } + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php new file mode 100644 index 00000000..6184ea3e --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Compiler; + +/** + * Compiles a resource bundle. + * + * @author Bernhard Schussek + */ +interface BundleCompilerInterface +{ + /** + * Compiles a resource bundle at the given source to the given target + * directory. + * + * @param string $sourcePath + * @param string $targetDir + */ + public function compile($sourcePath, $targetDir); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php new file mode 100644 index 00000000..6f2a0ed3 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Default implementation of {@link CurrencyBundleInterface}. + * + * @author Bernhard Schussek + */ +class CurrencyBundle extends AbstractBundle implements CurrencyBundleInterface +{ + const INDEX_NAME = 0; + + const INDEX_SYMBOL = 1; + + const INDEX_FRACTION_DIGITS = 2; + + const INDEX_ROUNDING_INCREMENT = 3; + + /** + * {@inheritdoc} + */ + public function getCurrencySymbol($currency, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_SYMBOL)); + } + + /** + * {@inheritdoc} + */ + public function getCurrencyName($currency, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_NAME)); + } + + /** + * {@inheritdoc} + */ + public function getCurrencyNames($locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($currencies = $this->readEntry($locale, array('Currencies')))) { + return array(); + } + + if ($currencies instanceof \Traversable) { + $currencies = iterator_to_array($currencies); + } + + $index = static::INDEX_NAME; + + array_walk($currencies, function (&$value) use ($index) { + $value = $value[$index]; + }); + + return $currencies; + } + + /** + * {@inheritdoc} + */ + public function getFractionDigits($currency) + { + return $this->readEntry('en', array('Currencies', $currency, static::INDEX_FRACTION_DIGITS)); + } + + /** + * {@inheritdoc} + */ + public function getRoundingIncrement($currency) + { + return $this->readEntry('en', array('Currencies', $currency, static::INDEX_ROUNDING_INCREMENT)); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php new file mode 100644 index 00000000..1a88e937 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Gives access to currency-related ICU data. + * + * @author Bernhard Schussek + */ +interface CurrencyBundleInterface extends ResourceBundleInterface +{ + /** + * Returns the symbol used for a currency. + * + * @param string $currency A currency code (e.g. "EUR"). + * @param string $locale Optional. The locale to return the result in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The currency symbol or NULL if not found. + */ + public function getCurrencySymbol($currency, $locale = null); + + /** + * Returns the name of a currency. + * + * @param string $currency A currency code (e.g. "EUR"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The name of the currency or NULL if not found. + */ + public function getCurrencyName($currency, $locale = null); + + /** + * Returns the names of all known currencies. + * + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string[] A list of currency names indexed by currency codes. + */ + public function getCurrencyNames($locale = null); + + /** + * Returns the number of digits after the comma of a currency. + * + * @param string $currency A currency code (e.g. "EUR"). + * + * @return integer|null The number of digits after the comma or NULL if not found. + */ + public function getFractionDigits($currency); + + /** + * Returns the rounding increment of a currency. + * + * The rounding increment indicates to which number a currency is rounded. + * For example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the + * nearest 0.65 is 1.3. + * + * @param string $currency A currency code (e.g. "EUR"). + * + * @return float|integer|null The rounding increment or NULL if not found. + */ + public function getRoundingIncrement($currency); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php new file mode 100644 index 00000000..c449f9c1 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Default implementation of {@link LanguageBundleInterface}. + * + * @author Bernhard Schussek + */ +class LanguageBundle extends AbstractBundle implements LanguageBundleInterface +{ + /** + * {@inheritdoc} + */ + public function getLanguageName($lang, $region = null, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($languages = $this->readEntry($locale, array('Languages')))) { + return null; + } + + // Some languages are translated together with their region, + // i.e. "en_GB" is translated as "British English" + if (null !== $region && isset($languages[$lang.'_'.$region])) { + return $languages[$lang.'_'.$region]; + } + + return $languages[$lang]; + } + + /** + * {@inheritdoc} + */ + public function getLanguageNames($locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($languages = $this->readEntry($locale, array('Languages')))) { + return array(); + } + + if ($languages instanceof \Traversable) { + $languages = iterator_to_array($languages); + } + + return $languages; + } + + /** + * {@inheritdoc} + */ + public function getScriptName($script, $lang = null, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + $data = $this->read($locale); + + // Some languages are translated together with their script, + // e.g. "zh_Hans" is translated as "Simplified Chinese" + if (null !== $lang && isset($data['Languages'][$lang.'_'.$script])) { + $langName = $data['Languages'][$lang.'_'.$script]; + + // If the script is appended in braces, extract it, e.g. "zh_Hans" + // is translated as "Chinesisch (vereinfacht)" in locale "de" + if (strpos($langName, '(') !== false) { + list($langName, $scriptName) = preg_split('/[\s()]/', $langName, null, PREG_SPLIT_NO_EMPTY); + + return $scriptName; + } + } + + // "af" (Afrikaans) has no "Scripts" block + if (!isset($data['Scripts'][$script])) { + return null; + } + + return $data['Scripts'][$script]; + } + + /** + * {@inheritdoc} + */ + public function getScriptNames($locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) { + return array(); + } + + if ($scripts instanceof \Traversable) { + $scripts = iterator_to_array($scripts); + } + + return $scripts; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php new file mode 100644 index 00000000..de50bda0 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Gives access to language-related ICU data. + * + * @author Bernhard Schussek + */ +interface LanguageBundleInterface extends ResourceBundleInterface +{ + /** + * Returns the name of a language. + * + * @param string $lang A language code (e.g. "en"). + * @param string|null $region Optional. A region code (e.g. "US"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The name of the language or NULL if not found. + */ + public function getLanguageName($lang, $region = null, $locale = null); + + /** + * Returns the names of all known languages. + * + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string[] A list of language names indexed by language codes. + */ + public function getLanguageNames($locale = null); + + /** + * Returns the name of a script. + * + * @param string $script A script code (e.g. "Hans"). + * @param string $lang Optional. A language code (e.g. "zh"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The name of the script or NULL if not found. + */ + public function getScriptName($script, $lang = null, $locale = null); + + /** + * Returns the names of all known scripts. + * + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string[] A list of script names indexed by script codes. + */ + public function getScriptNames($locale = null); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php new file mode 100644 index 00000000..6f6cdfcb --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Default implementation of {@link LocaleBundleInterface}. + * + * @author Bernhard Schussek + */ +class LocaleBundle extends AbstractBundle implements LocaleBundleInterface +{ + /** + * {@inheritdoc} + */ + public function getLocaleName($ofLocale, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + return $this->readEntry($locale, array('Locales', $ofLocale)); + } + + /** + * {@inheritdoc} + */ + public function getLocaleNames($locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($locales = $this->readEntry($locale, array('Locales')))) { + return array(); + } + + if ($locales instanceof \Traversable) { + $locales = iterator_to_array($locales); + } + + return $locales; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php new file mode 100644 index 00000000..daf5be68 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Gives access to locale-related ICU data. + * + * @author Bernhard Schussek + */ +interface LocaleBundleInterface extends ResourceBundleInterface +{ + /** + * Returns the name of a locale. + * + * @param string $ofLocale The locale to return the name of (e.g. "de_AT"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The name of the locale or NULL if not found. + */ + public function getLocaleName($ofLocale, $locale = null); + + /** + * Returns the names of all known locales. + * + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string[] A list of locale names indexed by locale codes. + */ + public function getLocaleNames($locale = null); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php new file mode 100644 index 00000000..c30693ac --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/AbstractBundleReader.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +/** + * Base class for {@link BundleReaderInterface} implementations. + * + * @author Bernhard Schussek + */ +abstract class AbstractBundleReader implements BundleReaderInterface +{ + /** + * {@inheritdoc} + */ + public function getLocales($path) + { + $extension = '.' . $this->getFileExtension(); + $locales = glob($path . '/*' . $extension); + + // Remove file extension and sort + array_walk($locales, function (&$locale) use ($extension) { $locale = basename($locale, $extension); }); + sort($locales); + + return $locales; + } + + /** + * Returns the extension of locale files in this bundle. + * + * @return string The file extension (without leading dot). + */ + abstract protected function getFileExtension(); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php new file mode 100644 index 00000000..56cef806 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +use Symfony\Component\Intl\Exception\RuntimeException; +use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle; + +/** + * Reads binary .res resource bundles. + * + * @author Bernhard Schussek + */ +class BinaryBundleReader extends AbstractBundleReader implements BundleReaderInterface +{ + /** + * {@inheritdoc} + */ + public function read($path, $locale) + { + // Point for future extension: Modify this class so that it works also + // if the \ResourceBundle class is not available. + $bundle = new \ResourceBundle($locale, $path); + + if (null === $bundle) { + throw new RuntimeException(sprintf( + 'Could not load the resource bundle "%s/%s.res".', + $path, + $locale + )); + } + + return new ArrayAccessibleResourceBundle($bundle); + } + + /** + * {@inheritdoc} + */ + protected function getFileExtension() + { + return 'res'; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php new file mode 100644 index 00000000..e44074b1 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer; + +/** + * @author Bernhard Schussek + */ +class BufferedBundleReader implements BundleReaderInterface +{ + /** + * @var BundleReaderInterface + */ + private $reader; + + private $buffer; + + /** + * Buffers a given reader. + * + * @param BundleReaderInterface $reader The reader to buffer. + * @param integer $bufferSize The number of entries to store + * in the buffer. + */ + public function __construct(BundleReaderInterface $reader, $bufferSize) + { + $this->reader = $reader; + $this->buffer = new RingBuffer($bufferSize); + } + + /** + * {@inheritdoc} + */ + public function read($path, $locale) + { + $hash = $path . '//' . $locale; + + if (!isset($this->buffer[$hash])) { + $this->buffer[$hash] = $this->reader->read($path, $locale); + } + + return $this->buffer[$hash]; + } + + /** + * {@inheritdoc} + */ + public function getLocales($path) + { + return $this->reader->getLocales($path); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php new file mode 100644 index 00000000..bc485cd5 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +/** + * Reads resource bundle files. + * + * @author Bernhard Schussek + */ +interface BundleReaderInterface +{ + /** + * Reads a resource bundle. + * + * @param string $path The path to the resource bundle. + * @param string $locale The locale to read. + * + * @return mixed Returns an array or {@link \ArrayAccess} instance for + * complex data, a scalar value otherwise. + */ + public function read($path, $locale); + + /** + * Reads the available locales of a resource bundle. + * + * @param string $path The path to the resource bundle. + * + * @return string[] A list of supported locale codes. + */ + public function getLocales($path); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php new file mode 100644 index 00000000..663bcc9d --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +use Symfony\Component\Intl\Exception\InvalidArgumentException; +use Symfony\Component\Intl\Exception\RuntimeException; + +/** + * Reads .php resource bundles. + * + * @author Bernhard Schussek + */ +class PhpBundleReader extends AbstractBundleReader implements BundleReaderInterface +{ + /** + * {@inheritdoc} + */ + public function read($path, $locale) + { + if ('en' !== $locale) { + throw new InvalidArgumentException('Only the locale "en" is supported.'); + } + + $fileName = $path . '/' . $locale . '.php'; + + if (!file_exists($fileName)) { + throw new RuntimeException(sprintf( + 'The resource bundle "%s/%s.php" does not exist.', + $path, + $locale + )); + } + + if (!is_file($fileName)) { + throw new RuntimeException(sprintf( + 'The resource bundle "%s/%s.php" is not a file.', + $path, + $locale + )); + } + + return include $fileName; + } + + /** + * {@inheritdoc} + */ + protected function getFileExtension() + { + return 'php'; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php new file mode 100644 index 00000000..e3656fe2 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php @@ -0,0 +1,113 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +use Symfony\Component\Intl\ResourceBundle\Util\RecursiveArrayAccess; + +/** + * A structured reader wrapping an existing resource bundle reader. + * + * @author Bernhard Schussek + * + * @see StructuredResourceBundleBundleReaderInterface + */ +class StructuredBundleReader implements StructuredBundleReaderInterface +{ + /** + * @var BundleReaderInterface + */ + private $reader; + + /** + * Creates an entry reader based on the given resource bundle reader. + * + * @param BundleReaderInterface $reader A resource bundle reader to use. + */ + public function __construct(BundleReaderInterface $reader) + { + $this->reader = $reader; + } + + /** + * {@inheritdoc} + */ + public function read($path, $locale) + { + return $this->reader->read($path, $locale); + } + + /** + * {@inheritdoc} + */ + public function getLocales($path) + { + return $this->reader->getLocales($path); + } + + /** + * {@inheritdoc} + */ + public function readEntry($path, $locale, array $indices, $fallback = true) + { + $data = $this->reader->read($path, $locale); + + $entry = RecursiveArrayAccess::get($data, $indices); + $multivalued = is_array($entry) || $entry instanceof \Traversable; + + if (!($fallback && (null === $entry || $multivalued))) { + return $entry; + } + + if (null !== ($fallbackLocale = $this->getFallbackLocale($locale))) { + $parentEntry = $this->readEntry($path, $fallbackLocale, $indices, true); + + if ($entry || $parentEntry) { + $multivalued = $multivalued || is_array($parentEntry) || $parentEntry instanceof \Traversable; + + if ($multivalued) { + if ($entry instanceof \Traversable) { + $entry = iterator_to_array($entry); + } + + if ($parentEntry instanceof \Traversable) { + $parentEntry = iterator_to_array($parentEntry); + } + + $entry = array_merge( + $parentEntry ?: array(), + $entry ?: array() + ); + } else { + $entry = null === $entry ? $parentEntry : $entry; + } + } + } + + return $entry; + } + + /** + * Returns the fallback locale for a given locale, if any + * + * @param string $locale The locale to find the fallback for. + * + * @return string|null The fallback locale, or null if no parent exists + */ + private function getFallbackLocale($locale) + { + if (false === $pos = strrpos($locale, '_')) { + return null; + } + + return substr($locale, 0, $pos); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php new file mode 100644 index 00000000..c22ad93b --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Reader; + +/** + * Reads individual entries of a resource file. + * + * @author Bernhard Schussek + */ +interface StructuredBundleReaderInterface extends BundleReaderInterface +{ + /** + * Reads an entry from a resource bundle. + * + * An entry can be selected from the resource bundle by passing the path + * to that entry in the bundle. For example, if the bundle is structured + * like this: + * + * TopLevel + * NestedLevel + * Entry: Value + * + * Then the value can be read by calling: + * + * $reader->readEntry('...', 'en', array('TopLevel', 'NestedLevel', 'Entry')); + * + * @param string $path The path to the resource bundle. + * @param string $locale The locale to read. + * @param string[] $indices The indices to read from the bundle. + * @param Boolean $fallback Whether to merge the value with the value from + * the fallback locale (e.g. "en" for "en_GB"). + * Only applicable if the result is multivalued + * (i.e. array or \ArrayAccess) or cannot be found + * in the requested locale. + * + * @return mixed Returns an array or {@link \ArrayAccess} instance for + * complex data, a scalar value for simple data and NULL + * if the given path could not be accessed. + */ + public function readEntry($path, $locale, array $indices, $fallback = true); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundle.php new file mode 100644 index 00000000..a3cd9bd3 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundle.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Default implementation of {@link RegionBundleInterface}. + * + * @author Bernhard Schussek + */ +class RegionBundle extends AbstractBundle implements RegionBundleInterface +{ + /** + * {@inheritdoc} + */ + public function getCountryName($country, $locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + return $this->readEntry($locale, array('Countries', $country)); + } + + /** + * {@inheritdoc} + */ + public function getCountryNames($locale = null) + { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + + if (null === ($countries = $this->readEntry($locale, array('Countries')))) { + return array(); + } + + if ($countries instanceof \Traversable) { + $countries = iterator_to_array($countries); + } + + return $countries; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php new file mode 100644 index 00000000..4e55f2dc --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Gives access to region-related ICU data. + * + * @author Bernhard Schussek + */ +interface RegionBundleInterface extends ResourceBundleInterface +{ + /** + * Returns the name of a country. + * + * @param string $country A country code (e.g. "US"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string|null The name of the country or NULL if not found. + */ + public function getCountryName($country, $locale = null); + + /** + * Returns the names of all known countries. + * + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getDefault()}. + * + * @return string[] A list of country names indexed by country codes. + */ + public function getCountryNames($locale = null); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/ResourceBundleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/ResourceBundleInterface.php new file mode 100644 index 00000000..497a66a3 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/ResourceBundleInterface.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle; + +/** + * Gives access to ICU data. + * + * @author Bernhard Schussek + */ +interface ResourceBundleInterface +{ + /** + * Returns the list of locales that this bundle supports. + * + * @return string[] A list of locale codes. + */ + public function getLocales(); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php new file mode 100644 index 00000000..0692d6fe --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer; + +use Symfony\Component\Intl\Exception\RuntimeException; +use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\TransformationRuleInterface; +use Symfony\Component\Intl\ResourceBundle\Writer\PhpBundleWriter; + +/** + * Compiles a number of resource bundles based on predefined compilation rules. + * + * @author Bernhard Schussek + */ +class BundleTransformer +{ + /** + * @var TransformationRuleInterface[] + */ + private $rules = array(); + + /** + * Adds a new compilation rule. + * + * @param TransformationRuleInterface $rule The compilation rule. + */ + public function addRule(TransformationRuleInterface $rule) + { + $this->rules[] = $rule; + } + + /** + * Runs the compilation with the given compilation context. + * + * @param CompilationContextInterface $context The context storing information + * needed to run the compilation. + * + * @throws RuntimeException If any of the files to be compiled by the loaded + * compilation rules does not exist. + */ + public function compileBundles(CompilationContextInterface $context) + { + $filesystem = $context->getFilesystem(); + $compiler = $context->getCompiler(); + + $filesystem->remove($context->getBinaryDir()); + $filesystem->mkdir($context->getBinaryDir()); + + foreach ($this->rules as $rule) { + $filesystem->mkdir($context->getBinaryDir() . '/' . $rule->getBundleName()); + + $resources = (array) $rule->beforeCompile($context); + + foreach ($resources as $resource) { + if (!file_exists($resource)) { + throw new RuntimeException(sprintf( + 'The file "%s" to be compiled by %s does not exist.', + $resource, + get_class($rule) + )); + } + + $compiler->compile($resource, $context->getBinaryDir() . '/' . $rule->getBundleName()); + } + + $rule->afterCompile($context); + } + } + + public function createStubs(StubbingContextInterface $context) + { + $filesystem = $context->getFilesystem(); + $phpWriter = new PhpBundleWriter(); + + $filesystem->remove($context->getStubDir()); + $filesystem->mkdir($context->getStubDir()); + + foreach ($this->rules as $rule) { + $filesystem->mkdir($context->getStubDir() . '/' . $rule->getBundleName()); + + $data = $rule->beforeCreateStub($context); + + $phpWriter->write($context->getStubDir() . '/' . $rule->getBundleName(), 'en', $data); + + $rule->afterCreateStub($context); + } + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php new file mode 100644 index 00000000..cdc1951b --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php @@ -0,0 +1,97 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer; + +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompilerInterface; + +/** + * Default implementation of {@link CompilationContextInterface}. + * + * @author Bernhard Schussek + */ +class CompilationContext implements CompilationContextInterface +{ + /** + * @var string + */ + private $sourceDir; + + /** + * @var string + */ + private $binaryDir; + + /** + * @var FileSystem + */ + private $filesystem; + + /** + * @var BundleCompilerInterface + */ + private $compiler; + + /** + * @var string + */ + private $icuVersion; + + public function __construct($sourceDir, $binaryDir, Filesystem $filesystem, BundleCompilerInterface $compiler, $icuVersion) + { + $this->sourceDir = $sourceDir; + $this->binaryDir = $binaryDir; + $this->filesystem = $filesystem; + $this->compiler = $compiler; + $this->icuVersion = $icuVersion; + } + + /** + * {@inheritdoc} + */ + public function getSourceDir() + { + return $this->sourceDir; + } + + /** + * {@inheritdoc} + */ + public function getBinaryDir() + { + return $this->binaryDir; + } + + /** + * {@inheritdoc} + */ + public function getFilesystem() + { + return $this->filesystem; + } + + /** + * {@inheritdoc} + */ + public function getCompiler() + { + return $this->compiler; + } + + /** + * {@inheritdoc} + */ + public function getIcuVersion() + { + return $this->icuVersion; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php new file mode 100644 index 00000000..f05c2807 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer; + +/** + * Stores contextual information for resource bundle compilation. + * + * @author Bernhard Schussek + */ +interface CompilationContextInterface +{ + /** + * Returns the directory where the source versions of the resource bundles + * are stored. + * + * @return string An absolute path to a directory. + */ + public function getSourceDir(); + + /** + * Returns the directory where the binary resource bundles are stored. + * + * @return string An absolute path to a directory. + */ + public function getBinaryDir(); + + /** + * Returns a tool for manipulating the filesystem. + * + * @return \Symfony\Component\Filesystem\Filesystem The filesystem manipulator. + */ + public function getFilesystem(); + + /** + * Returns a resource bundle compiler. + * + * @return \Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompilerInterface The loaded resource bundle compiler. + */ + public function getCompiler(); + + /** + * Returns the ICU version of the bundles being converted. + * + * @return string The ICU version string. + */ + public function getIcuVersion(); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php new file mode 100644 index 00000000..95783b3b --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule; + +use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\ResourceBundle\CurrencyBundle; +use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface; +use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface; +use Symfony\Component\Intl\Util\IcuVersion; + +/** + * The rule for compiling the currency bundle. + * + * @author Bernhard Schussek + */ +class CurrencyBundleTransformationRule implements TransformationRuleInterface +{ + /** + * {@inheritdoc} + */ + public function getBundleName() + { + return 'curr'; + } + + /** + * {@inheritdoc} + */ + public function beforeCompile(CompilationContextInterface $context) + { + // The currency data is contained in the locales and misc bundles + // in ICU <= 4.2 + if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) { + return array( + $context->getSourceDir() . '/misc/supplementalData.txt', + $context->getSourceDir() . '/locales' + ); + } + + return $context->getSourceDir() . '/curr'; + } + + /** + * {@inheritdoc} + */ + public function afterCompile(CompilationContextInterface $context) + { + // \ResourceBundle does not like locale names with uppercase chars, so rename + // the resource file + // See: http://bugs.php.net/bug.php?id=54025 + $fileName = $context->getBinaryDir() . '/curr/supplementalData.res'; + $fileNameLower = $context->getBinaryDir() . '/curr/supplementaldata.res'; + + $context->getFilesystem()->rename($fileName, $fileNameLower); + } + + /** + * {@inheritdoc} + */ + public function beforeCreateStub(StubbingContextInterface $context) + { + $currencies = array(); + $currencyBundle = Intl::getCurrencyBundle(); + + foreach ($currencyBundle->getCurrencyNames('en') as $code => $name) { + $currencies[$code] = array( + CurrencyBundle::INDEX_NAME => $name, + CurrencyBundle::INDEX_SYMBOL => $currencyBundle->getCurrencySymbol($code, 'en'), + CurrencyBundle::INDEX_FRACTION_DIGITS => $currencyBundle->getFractionDigits($code), + CurrencyBundle::INDEX_ROUNDING_INCREMENT => $currencyBundle->getRoundingIncrement($code), + ); + } + + return array( + 'Currencies' => $currencies, + ); + } + + /** + * {@inheritdoc} + */ + public function afterCreateStub(StubbingContextInterface $context) + { + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LanguageBundleTransformationRule.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LanguageBundleTransformationRule.php new file mode 100644 index 00000000..5e6f9018 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LanguageBundleTransformationRule.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule; + +use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface; +use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface; +use Symfony\Component\Intl\Util\IcuVersion; + +/** + * The rule for compiling the language bundle. + * + * @author Bernhard Schussek + */ +class LanguageBundleTransformationRule implements TransformationRuleInterface +{ + /** + * {@inheritdoc} + */ + public function getBundleName() + { + return 'lang'; + } + + /** + * {@inheritdoc} + */ + public function beforeCompile(CompilationContextInterface $context) + { + // The language data is contained in the locales bundle in ICU <= 4.2 + if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) { + return $context->getSourceDir() . '/locales'; + } + + return $context->getSourceDir() . '/lang'; + } + + /** + * {@inheritdoc} + */ + public function afterCompile(CompilationContextInterface $context) + { + } + + /** + * {@inheritdoc} + */ + public function beforeCreateStub(StubbingContextInterface $context) + { + return array( + 'Languages' => Intl::getLanguageBundle()->getLanguageNames('en'), + 'Scripts' => Intl::getLanguageBundle()->getScriptNames('en'), + ); + } + + /** + * {@inheritdoc} + */ + public function afterCreateStub(StubbingContextInterface $context) + { + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php new file mode 100644 index 00000000..b2576d6e --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php @@ -0,0 +1,251 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule; + +use Symfony\Component\Intl\Exception\RuntimeException; +use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface; +use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface; +use Symfony\Component\Intl\ResourceBundle\Writer\TextBundleWriter; + +/** + * The rule for compiling the locale bundle. + * + * @author Bernhard Schussek + */ +class LocaleBundleTransformationRule implements TransformationRuleInterface +{ + /** + * @var \Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface + */ + private $languageBundle; + + /** + * @var \Symfony\Component\Intl\ResourceBundle\RegionBundleInterface + */ + private $regionBundle; + + public function __construct() + { + $this->languageBundle = Intl::getLanguageBundle(); + $this->regionBundle = Intl::getRegionBundle(); + } + + /** + * {@inheritdoc} + */ + public function getBundleName() + { + return 'locales'; + } + + /** + * {@inheritdoc} + */ + public function beforeCompile(CompilationContextInterface $context) + { + $tempDir = sys_get_temp_dir() . '/icu-data-locales'; + + $context->getFilesystem()->remove($tempDir); + $context->getFilesystem()->mkdir($tempDir); + + $this->generateTextFiles($tempDir, $this->scanLocales($context)); + + return $tempDir; + } + + /** + * {@inheritdoc} + */ + public function afterCompile(CompilationContextInterface $context) + { + $context->getFilesystem()->remove(sys_get_temp_dir() . '/icu-data-locales'); + } + + /** + * {@inheritdoc} + */ + public function beforeCreateStub(StubbingContextInterface $context) + { + return array( + 'Locales' => Intl::getLocaleBundle()->getLocaleNames('en'), + ); + } + + /** + * {@inheritdoc} + */ + public function afterCreateStub(StubbingContextInterface $context) + { + } + + private function scanLocales(CompilationContextInterface $context) + { + $tempDir = sys_get_temp_dir() . '/icu-data-locales-source'; + + $context->getFilesystem()->remove($tempDir); + $context->getFilesystem()->mkdir($tempDir); + + // Temporarily generate the resource bundles + $context->getCompiler()->compile($context->getSourceDir() . '/locales', $tempDir); + + // Discover the list of supported locales, which are the names of the resource + // bundles in the "locales" directory + $locales = glob($tempDir . '/*.res'); + + // Remove file extension and sort + array_walk($locales, function (&$locale) { $locale = basename($locale, '.res'); }); + sort($locales); + + // Delete unneeded locales + foreach ($locales as $key => $locale) { + // Delete all aliases from the list + // i.e., "az_AZ" is an alias for "az_Latn_AZ" + $content = file_get_contents($context->getSourceDir() . '/locales/' . $locale . '.txt'); + + // The key "%%ALIAS" is not accessible through the \ResourceBundle class, + // so look in the original .txt file instead + if (strpos($content, '%%ALIAS') !== false) { + unset($locales[$key]); + } + + // Delete locales that have no content (i.e. only "Version" key) + $bundle = new \ResourceBundle($locale, $tempDir); + + if (null === $bundle) { + throw new RuntimeException('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $tempDir); + } + + // There seems to be no other way for identifying all keys in this specific + // resource bundle + if (array_keys(iterator_to_array($bundle)) === array('Version')) { + unset($locales[$key]); + } + } + + $context->getFilesystem()->remove($tempDir); + + return $locales; + } + + private function generateTextFiles($targetDirectory, array $locales) + { + $displayLocales = array_unique(array_merge( + $this->languageBundle->getLocales(), + $this->regionBundle->getLocales() + )); + + $txtWriter = new TextBundleWriter(); + + // Generate a list of locale names in the language of each display locale + // Each locale name has the form: "Language (Script, Region, Variant1, ...) + // Script, Region and Variants are optional. If none of them is available, + // the braces are not printed. + foreach ($displayLocales as $displayLocale) { + // Don't include ICU's root resource bundle + if ('root' === $displayLocale) { + continue; + } + + $names = array(); + + foreach ($locales as $locale) { + // Don't include ICU's root resource bundle + if ($locale === 'root') { + continue; + } + + if (null !== ($name = $this->generateLocaleName($locale, $displayLocale))) { + $names[$locale] = $name; + } + } + + // If no names could be generated for the current locale, skip it + if (0 === count($names)) { + continue; + } + + $txtWriter->write($targetDirectory, $displayLocale, array('Locales' => $names)); + } + } + + private function generateLocaleName($locale, $displayLocale) + { + $name = null; + + $lang = \Locale::getPrimaryLanguage($locale); + $script = \Locale::getScript($locale); + $region = \Locale::getRegion($locale); + $variants = \Locale::getAllVariants($locale); + + // Currently the only available variant is POSIX, which we don't want + // to include in the list + if (count($variants) > 0) { + return null; + } + + // Some languages are translated together with their region, + // i.e. "en_GB" is translated as "British English" + // we don't include these languages though because they mess up + // the name sorting + // $name = $this->langBundle->getLanguageName($displayLocale, $lang, $region); + + // Some languages are simply not translated + // Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans) + if (null === ($name = $this->languageBundle->getLanguageName($lang, null, $displayLocale))) { + return null; + } + + // "as" (Assamese) has no "Variants" block + //if (!$langBundle->get('Variants')) { + // continue; + //} + + $extras = array(); + + // Discover the name of the script part of the locale + // i.e. in zh_Hans_MO, "Hans" is the script + if ($script) { + // Some scripts are not translated into every language + if (null === ($scriptName = $this->languageBundle->getScriptName($script, $lang, $displayLocale))) { + return null; + } + + $extras[] = $scriptName; + } + + // Discover the name of the region part of the locale + // i.e. in de_AT, "AT" is the region + if ($region) { + // Some regions are not translated into every language + if (null === ($regionName = $this->regionBundle->getCountryName($region, $displayLocale))) { + return null; + } + + $extras[] = $regionName; + } + + if (count($extras) > 0) { + // Remove any existing extras + // For example, in German, zh_Hans is "Chinesisch (vereinfacht)". + // The latter is the script part which is already included in the + // extras and will be appended again with the other extras. + if (preg_match('/^(.+)\s+\([^\)]+\)$/', $name, $matches)) { + $name = $matches[1]; + } + + $name .= ' ('.implode(', ', $extras).')'; + } + + return $name; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/RegionBundleTransformationRule.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/RegionBundleTransformationRule.php new file mode 100644 index 00000000..52fdbed8 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/RegionBundleTransformationRule.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule; + +use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface; +use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface; +use Symfony\Component\Intl\Util\IcuVersion; + +/** + * The rule for compiling the region bundle. + * + * @author Bernhard Schussek + */ +class RegionBundleTransformationRule implements TransformationRuleInterface +{ + /** + * {@inheritdoc} + */ + public function getBundleName() + { + return 'region'; + } + + /** + * {@inheritdoc} + */ + public function beforeCompile(CompilationContextInterface $context) + { + // The region data is contained in the locales bundle in ICU <= 4.2 + if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) { + return $context->getSourceDir() . '/locales'; + } + + return $context->getSourceDir() . '/region'; + } + + /** + * {@inheritdoc} + */ + public function afterCompile(CompilationContextInterface $context) + { + } + + /** + * {@inheritdoc} + */ + public function beforeCreateStub(StubbingContextInterface $context) + { + return array( + 'Countries' => Intl::getRegionBundle()->getCountryNames('en'), + ); + } + + /** + * {@inheritdoc} + */ + public function afterCreateStub(StubbingContextInterface $context) + { + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/TransformationRuleInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/TransformationRuleInterface.php new file mode 100644 index 00000000..3965e0d2 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/TransformationRuleInterface.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule; + +use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface; +use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface; + +/** + * Contains instruction for compiling a resource bundle. + * + * @author Bernhard Schussek + */ +interface TransformationRuleInterface +{ + /** + * Returns the name of the compiled resource bundle. + * + * @return string The name of the bundle. + */ + public function getBundleName(); + + /** + * Runs instructions to be executed before compiling the sources of the + * resource bundle. + * + * @param CompilationContextInterface $context The contextual information of + * the compilation. + * + * @return string[] The source directories/files of the bundle. + */ + public function beforeCompile(CompilationContextInterface $context); + + /** + * Runs instructions to be executed after compiling the sources of the + * resource bundle. + * + * @param CompilationContextInterface $context The contextual information of + * the compilation. + */ + public function afterCompile(CompilationContextInterface $context); + + /** + * Runs instructions to be executed before creating the stub version of the + * resource bundle. + * + * @param StubbingContextInterface $context The contextual information of + * the compilation. + * + * @return mixed The data to include in the stub version. + */ + public function beforeCreateStub(StubbingContextInterface $context); + + /** + * Runs instructions to be executed after creating the stub version of the + * resource bundle. + * + * @param StubbingContextInterface $context The contextual information of + * the compilation. + */ + public function afterCreateStub(StubbingContextInterface $context); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContext.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContext.php new file mode 100644 index 00000000..25ab68db --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContext.php @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer; + +use Symfony\Component\Filesystem\Filesystem; + +/** + * @author Bernhard Schussek + */ +class StubbingContext implements StubbingContextInterface +{ + /** + * @var string + */ + private $binaryDir; + + /** + * @var string + */ + private $stubDir; + + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var string + */ + private $icuVersion; + + public function __construct($binaryDir, $stubDir, Filesystem $filesystem, $icuVersion) + { + $this->binaryDir = $binaryDir; + $this->stubDir = $stubDir; + $this->filesystem = $filesystem; + $this->icuVersion = $icuVersion; + } + + /** + * {@inheritdoc} + */ + public function getBinaryDir() + { + return $this->binaryDir; + } + + /** + * {@inheritdoc} + */ + public function getStubDir() + { + return $this->stubDir; + } + + /** + * {@inheritdoc} + */ + public function getFilesystem() + { + return $this->filesystem; + } + + /** + * {@inheritdoc} + */ + public function getIcuVersion() + { + return $this->icuVersion; + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContextInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContextInterface.php new file mode 100644 index 00000000..dc492556 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContextInterface.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Transformer; + +/** + * @author Bernhard Schussek + */ +interface StubbingContextInterface +{ + /** + * Returns the directory where the binary resource bundles are stored. + * + * @return string An absolute path to a directory. + */ + public function getBinaryDir(); + + /** + * Returns the directory where the stub resource bundles are stored. + * + * @return string An absolute path to a directory. + */ + public function getStubDir(); + + /** + * Returns a tool for manipulating the filesystem. + * + * @return \Symfony\Component\Filesystem\Filesystem The filesystem manipulator. + */ + public function getFilesystem(); + + /** + * Returns the ICU version of the bundles being converted. + * + * @return string The ICU version string. + */ + public function getIcuVersion(); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/ArrayAccessibleResourceBundle.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/ArrayAccessibleResourceBundle.php new file mode 100644 index 00000000..9a4cccb4 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/ArrayAccessibleResourceBundle.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Util; + +use Symfony\Component\Intl\Exception\BadMethodCallException; + +/** + * Work-around for a bug in PHP's \ResourceBundle implementation. + * + * More information can be found on https://bugs.php.net/bug.php?id=64356. + * This class can be removed once that bug is fixed. + * + * @author Bernhard Schussek + */ +class ArrayAccessibleResourceBundle implements \ArrayAccess, \IteratorAggregate, \Countable +{ + private $bundleImpl; + + public function __construct(\ResourceBundle $bundleImpl) + { + $this->bundleImpl = $bundleImpl; + } + + public function get($offset, $fallback = null) + { + $value = $this->bundleImpl->get($offset, $fallback); + + return $value instanceof \ResourceBundle ? new static($value) : $value; + } + + public function offsetExists($offset) + { + return null !== $this->bundleImpl[$offset]; + } + + public function offsetGet($offset) + { + return $this->get($offset); + } + + public function offsetSet($offset, $value) + { + throw new BadMethodCallException('Resource bundles cannot be modified.'); + } + + public function offsetUnset($offset) + { + throw new BadMethodCallException('Resource bundles cannot be modified.'); + } + + public function getIterator() + { + return $this->bundleImpl; + } + + public function count() + { + return $this->bundleImpl->count(); + } + + public function getErrorCode() + { + return $this->bundleImpl->getErrorCode(); + } + + public function getErrorMessage() + { + return $this->bundleImpl->getErrorMessage(); + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RecursiveArrayAccess.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RecursiveArrayAccess.php new file mode 100644 index 00000000..e1feaa2c --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RecursiveArrayAccess.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Util; + +/** + * @author Bernhard Schussek + */ +class RecursiveArrayAccess +{ + public static function get($array, array $indices) + { + foreach ($indices as $index) { + if (!$array instanceof \ArrayAccess && !is_array($array)) { + return null; + } + + $array = $array[$index]; + } + + return $array; + } + + private function __construct() {} +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RingBuffer.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RingBuffer.php new file mode 100644 index 00000000..7ccbd1e7 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Util/RingBuffer.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Util; + +use Symfony\Component\Intl\Exception\OutOfBoundsException; + +/** + * Implements a ring buffer. + * + * A ring buffer is an array-like structure with a fixed size. If the buffer + * is full, the next written element overwrites the first bucket in the buffer, + * then the second and so on. + * + * @author Bernhard Schussek + */ +class RingBuffer implements \ArrayAccess +{ + private $values = array(); + + private $indices = array(); + + private $cursor = 0; + + private $size; + + public function __construct($size) + { + $this->size = $size; + } + + /** + * {@inheritdoc} + */ + public function offsetExists($key) + { + return isset($this->indices[$key]); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($key) + { + if (!isset($this->indices[$key])) { + throw new OutOfBoundsException(sprintf( + 'The index "%s" does not exist.', + $key + )); + } + + return $this->values[$this->indices[$key]]; + } + + /** + * {@inheritdoc} + */ + public function offsetSet($key, $value) + { + if (false !== ($keyToRemove = array_search($this->cursor, $this->indices))) { + unset($this->indices[$keyToRemove]); + } + + $this->values[$this->cursor] = $value; + $this->indices[$key] = $this->cursor; + + $this->cursor = ($this->cursor + 1) % $this->size; + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($key) + { + if (isset($this->indices[$key])) { + $this->values[$this->indices[$key]] = null; + unset($this->indices[$key]); + } + } +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php new file mode 100644 index 00000000..cc3b9586 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Writer; + +/** + * Writes resource bundle files. + * + * @author Bernhard Schussek + */ +interface BundleWriterInterface +{ + /** + * Writes data to a resource bundle. + * + * @param string $path The path to the resource bundle. + * @param string $locale The locale to (over-)write. + * @param mixed $data The data to write. + */ + public function write($path, $locale, $data); +} diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php new file mode 100644 index 00000000..d2688b49 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\ResourceBundle\Writer; + +/** + * Writes .php resource bundles. + * + * @author Bernhard Schussek + */ +class PhpBundleWriter implements BundleWriterInterface +{ + /** + * {@inheritdoc} + */ + public function write($path, $locale, $data) + { + $template = <<