4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule
;
14 use Symfony\Component\Intl\Intl
;
15 use Symfony\Component\Intl\ResourceBundle\CurrencyBundle
;
16 use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface
;
17 use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface
;
18 use Symfony\Component\Intl\Util\IcuVersion
;
21 * The rule for compiling the currency bundle.
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class CurrencyBundleTransformationRule
implements TransformationRuleInterface
30 public function getBundleName()
38 public function beforeCompile(CompilationContextInterface
$context)
40 // The currency data is contained in the locales and misc bundles
42 if (IcuVersion
::compare($context->getIcuVersion(), '4.2', '<=', 1)) {
44 $context->getSourceDir() . '/misc/supplementalData.txt',
45 $context->getSourceDir() . '/locales'
49 return $context->getSourceDir() . '/curr';
55 public function afterCompile(CompilationContextInterface
$context)
57 // \ResourceBundle does not like locale names with uppercase chars, so rename
59 // See: http://bugs.php.net/bug.php?id=54025
60 $fileName = $context->getBinaryDir() . '/curr/supplementalData.res';
61 $fileNameLower = $context->getBinaryDir() . '/curr/supplementaldata.res';
63 $context->getFilesystem()->rename($fileName, $fileNameLower);
69 public function beforeCreateStub(StubbingContextInterface
$context)
71 $currencies = array();
72 $currencyBundle = Intl
::getCurrencyBundle();
74 foreach ($currencyBundle->getCurrencyNames('en') as $code => $name) {
75 $currencies[$code] = array(
76 CurrencyBundle
::INDEX_NAME
=> $name,
77 CurrencyBundle
::INDEX_SYMBOL
=> $currencyBundle->getCurrencySymbol($code, 'en'),
78 CurrencyBundle
::INDEX_FRACTION_DIGITS
=> $currencyBundle->getFractionDigits($code),
79 CurrencyBundle
::INDEX_ROUNDING_INCREMENT
=> $currencyBundle->getRoundingIncrement($code),
84 'Currencies' => $currencies,
91 public function afterCreateStub(StubbingContextInterface
$context)