composer package updates
[openemr.git] / vendor / symfony / translation / Loader / YamlFileLoader.php
blob41e390d0e967d92d9f63c9d996d3d1dc9c02c7a2
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Loader;
14 use Symfony\Component\Translation\Exception\InvalidResourceException;
15 use Symfony\Component\Translation\Exception\LogicException;
16 use Symfony\Component\Yaml\Parser as YamlParser;
17 use Symfony\Component\Yaml\Exception\ParseException;
19 /**
20 * YamlFileLoader loads translations from Yaml files.
22 * @author Fabien Potencier <fabien@symfony.com>
24 class YamlFileLoader extends FileLoader
26 private $yamlParser;
28 /**
29 * {@inheritdoc}
31 protected function loadResource($resource)
33 if (null === $this->yamlParser) {
34 if (!class_exists('Symfony\Component\Yaml\Parser')) {
35 throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
38 $this->yamlParser = new YamlParser();
41 try {
42 $messages = $this->yamlParser->parse(file_get_contents($resource));
43 } catch (ParseException $e) {
44 throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
47 return $messages;