RegionBundle.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\LocaleDataProvider;
  13. use Symfony\Component\Intl\Data\Provider\RegionDataProvider;
  14. use Symfony\Component\Intl\Exception\MissingResourceException;
  15. /**
  16. * Default implementation of {@link RegionBundleInterface}.
  17. *
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. *
  20. * @internal
  21. */
  22. class RegionBundle extends RegionDataProvider implements RegionBundleInterface
  23. {
  24. /**
  25. * @var LocaleDataProvider
  26. */
  27. private $localeProvider;
  28. /**
  29. * Creates a new region 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 getCountryName($country, $displayLocale = null)
  44. {
  45. try {
  46. return $this->getName($country, $displayLocale);
  47. } catch (MissingResourceException $e) {
  48. return;
  49. }
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getCountryNames($displayLocale = null)
  55. {
  56. try {
  57. return $this->getNames($displayLocale);
  58. } catch (MissingResourceException $e) {
  59. return array();
  60. }
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getLocales()
  66. {
  67. try {
  68. return $this->localeProvider->getLocales();
  69. } catch (MissingResourceException $e) {
  70. return array();
  71. }
  72. }
  73. }