CurrencyBundle.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\ResourceBundle;
  11. use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
  12. use Symfony\Component\Intl\Data\Provider\CurrencyDataProvider;
  13. use Symfony\Component\Intl\Data\Provider\LocaleDataProvider;
  14. use Symfony\Component\Intl\Exception\MissingResourceException;
  15. /**
  16. * Default implementation of {@link CurrencyBundleInterface}.
  17. *
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. *
  20. * @internal
  21. */
  22. class CurrencyBundle extends CurrencyDataProvider implements CurrencyBundleInterface
  23. {
  24. /**
  25. * @var LocaleDataProvider
  26. */
  27. private $localeProvider;
  28. /**
  29. * Creates a new currency bundle.
  30. *
  31. * @param string $path
  32. * @param BundleEntryReaderInterface $reader
  33. * @param LocaleDataProvider $localeProvider
  34. */
  35. public function __construct($path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider)
  36. {
  37. parent::__construct($path, $reader);
  38. $this->localeProvider = $localeProvider;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getCurrencySymbol($currency, $displayLocale = null)
  44. {
  45. try {
  46. return $this->getSymbol($currency, $displayLocale);
  47. } catch (MissingResourceException $e) {
  48. return;
  49. }
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getCurrencyName($currency, $displayLocale = null)
  55. {
  56. try {
  57. return $this->getName($currency, $displayLocale);
  58. } catch (MissingResourceException $e) {
  59. return;
  60. }
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getCurrencyNames($displayLocale = null)
  66. {
  67. try {
  68. return $this->getNames($displayLocale);
  69. } catch (MissingResourceException $e) {
  70. return array();
  71. }
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function getFractionDigits($currency)
  77. {
  78. try {
  79. return parent::getFractionDigits($currency);
  80. } catch (MissingResourceException $e) {
  81. return;
  82. }
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function getRoundingIncrement($currency)
  88. {
  89. try {
  90. return parent::getRoundingIncrement($currency);
  91. } catch (MissingResourceException $e) {
  92. return;
  93. }
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function getLocales()
  99. {
  100. try {
  101. return $this->localeProvider->getLocales();
  102. } catch (MissingResourceException $e) {
  103. return array();
  104. }
  105. }
  106. }