aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php')
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php94
1 files changed, 94 insertions, 0 deletions
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 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule;
13
14use Symfony\Component\Intl\Intl;
15use Symfony\Component\Intl\ResourceBundle\CurrencyBundle;
16use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContextInterface;
17use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContextInterface;
18use Symfony\Component\Intl\Util\IcuVersion;
19
20/**
21 * The rule for compiling the currency bundle.
22 *
23 * @author Bernhard Schussek <bschussek@gmail.com>
24 */
25class CurrencyBundleTransformationRule implements TransformationRuleInterface
26{
27 /**
28 * {@inheritdoc}
29 */
30 public function getBundleName()
31 {
32 return 'curr';
33 }
34
35 /**
36 * {@inheritdoc}
37 */
38 public function beforeCompile(CompilationContextInterface $context)
39 {
40 // The currency data is contained in the locales and misc bundles
41 // in ICU <= 4.2
42 if (IcuVersion::compare($context->getIcuVersion(), '4.2', '<=', 1)) {
43 return array(
44 $context->getSourceDir() . '/misc/supplementalData.txt',
45 $context->getSourceDir() . '/locales'
46 );
47 }
48
49 return $context->getSourceDir() . '/curr';
50 }
51
52 /**
53 * {@inheritdoc}
54 */
55 public function afterCompile(CompilationContextInterface $context)
56 {
57 // \ResourceBundle does not like locale names with uppercase chars, so rename
58 // the resource file
59 // See: http://bugs.php.net/bug.php?id=54025
60 $fileName = $context->getBinaryDir() . '/curr/supplementalData.res';
61 $fileNameLower = $context->getBinaryDir() . '/curr/supplementaldata.res';
62
63 $context->getFilesystem()->rename($fileName, $fileNameLower);
64 }
65
66 /**
67 * {@inheritdoc}
68 */
69 public function beforeCreateStub(StubbingContextInterface $context)
70 {
71 $currencies = array();
72 $currencyBundle = Intl::getCurrencyBundle();
73
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),
80 );
81 }
82
83 return array(
84 'Currencies' => $currencies,
85 );
86 }
87
88 /**
89 * {@inheritdoc}
90 */
91 public function afterCreateStub(StubbingContextInterface $context)
92 {
93 }
94}