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