PhpBundleReader.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Reader;
  11. use Symfony\Component\Intl\Exception\InvalidArgumentException;
  12. use Symfony\Component\Intl\Exception\RuntimeException;
  13. /**
  14. * Reads .php resource bundles.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. */
  18. class PhpBundleReader extends AbstractBundleReader implements BundleReaderInterface
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function read($path, $locale)
  24. {
  25. if ('en' !== $locale) {
  26. throw new InvalidArgumentException('Only the locale "en" is supported.');
  27. }
  28. $fileName = $path . '/' . $locale . '.php';
  29. if (!file_exists($fileName)) {
  30. throw new RuntimeException(sprintf(
  31. 'The resource bundle "%s/%s.php" does not exist.',
  32. $path,
  33. $locale
  34. ));
  35. }
  36. if (!is_file($fileName)) {
  37. throw new RuntimeException(sprintf(
  38. 'The resource bundle "%s/%s.php" is not a file.',
  39. $path,
  40. $locale
  41. ));
  42. }
  43. return include $fileName;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. protected function getFileExtension()
  49. {
  50. return 'php';
  51. }
  52. }