IniFileLoader.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\Translation\Loader;
  11. use Symfony\Component\Translation\Exception\InvalidResourceException;
  12. use Symfony\Component\Translation\Exception\NotFoundResourceException;
  13. use Symfony\Component\Config\Resource\FileResource;
  14. /**
  15. * IniFileLoader loads translations from an ini file.
  16. *
  17. * @author stealth35
  18. */
  19. class IniFileLoader extends ArrayLoader implements LoaderInterface
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function load($resource, $locale, $domain = 'messages')
  25. {
  26. if (!stream_is_local($resource)) {
  27. throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
  28. }
  29. if (!file_exists($resource)) {
  30. throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
  31. }
  32. $messages = parse_ini_file($resource, true);
  33. $catalogue = parent::load($messages, $locale, $domain);
  34. $catalogue->addResource(new FileResource($resource));
  35. return $catalogue;
  36. }
  37. }