BinaryBundleReader.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\RuntimeException;
  12. use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle;
  13. /**
  14. * Reads binary .res resource bundles.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. */
  18. class BinaryBundleReader extends AbstractBundleReader implements BundleReaderInterface
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function read($path, $locale)
  24. {
  25. // Point for future extension: Modify this class so that it works also
  26. // if the \ResourceBundle class is not available.
  27. $bundle = new \ResourceBundle($locale, $path);
  28. if (null === $bundle) {
  29. throw new RuntimeException(sprintf(
  30. 'Could not load the resource bundle "%s/%s.res".',
  31. $path,
  32. $locale
  33. ));
  34. }
  35. return new ArrayAccessibleResourceBundle($bundle);
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. protected function getFileExtension()
  41. {
  42. return 'res';
  43. }
  44. }