]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / ResourceBundle / CurrencyBundle.php
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
12 namespace Symfony\Component\Intl\ResourceBundle;
13
14 /**
15 * Default implementation of {@link CurrencyBundleInterface}.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19 class CurrencyBundle extends AbstractBundle implements CurrencyBundleInterface
20 {
21 const INDEX_NAME = 0;
22
23 const INDEX_SYMBOL = 1;
24
25 const INDEX_FRACTION_DIGITS = 2;
26
27 const INDEX_ROUNDING_INCREMENT = 3;
28
29 /**
30 * {@inheritdoc}
31 */
32 public function getCurrencySymbol($currency, $locale = null)
33 {
34 if (null === $locale) {
35 $locale = \Locale::getDefault();
36 }
37
38 return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_SYMBOL));
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function getCurrencyName($currency, $locale = null)
45 {
46 if (null === $locale) {
47 $locale = \Locale::getDefault();
48 }
49
50 return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_NAME));
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function getCurrencyNames($locale = null)
57 {
58 if (null === $locale) {
59 $locale = \Locale::getDefault();
60 }
61
62 if (null === ($currencies = $this->readEntry($locale, array('Currencies')))) {
63 return array();
64 }
65
66 if ($currencies instanceof \Traversable) {
67 $currencies = iterator_to_array($currencies);
68 }
69
70 $index = static::INDEX_NAME;
71
72 array_walk($currencies, function (&$value) use ($index) {
73 $value = $value[$index];
74 });
75
76 return $currencies;
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function getFractionDigits($currency)
83 {
84 return $this->readEntry('en', array('Currencies', $currency, static::INDEX_FRACTION_DIGITS));
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function getRoundingIncrement($currency)
91 {
92 return $this->readEntry('en', array('Currencies', $currency, static::INDEX_ROUNDING_INCREMENT));
93 }
94 }