ArrayLoader.php
1 month ago
CsvFileLoader.php
1 month ago
FileLoader.php
1 month ago
IcuDatFileLoader.php
1 month ago
IcuResFileLoader.php
1 month ago
IniFileLoader.php
1 month ago
JsonFileLoader.php
1 month ago
LoaderInterface.php
1 month ago
MoFileLoader.php
1 month ago
PhpFileLoader.php
1 month ago
PoFileLoader.php
1 month ago
QtFileLoader.php
1 month ago
XliffFileLoader.php
1 month ago
YamlFileLoader.php
1 month ago
YamlFileLoader.php
49 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation\Loader; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\Exception\InvalidResourceException; |
| 14 | use IAWPSCOPED\Symfony\Component\Translation\Exception\LogicException; |
| 15 | use IAWPSCOPED\Symfony\Component\Yaml\Exception\ParseException; |
| 16 | use IAWPSCOPED\Symfony\Component\Yaml\Parser as YamlParser; |
| 17 | use IAWPSCOPED\Symfony\Component\Yaml\Yaml; |
| 18 | /** |
| 19 | * YamlFileLoader loads translations from Yaml files. |
| 20 | * |
| 21 | * @author Fabien Potencier <fabien@symfony.com> |
| 22 | * @internal |
| 23 | */ |
| 24 | class YamlFileLoader extends FileLoader |
| 25 | { |
| 26 | private $yamlParser; |
| 27 | /** |
| 28 | * {@inheritdoc} |
| 29 | */ |
| 30 | protected function loadResource(string $resource) : array |
| 31 | { |
| 32 | if (null === $this->yamlParser) { |
| 33 | if (!\class_exists(\IAWPSCOPED\Symfony\Component\Yaml\Parser::class)) { |
| 34 | throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.'); |
| 35 | } |
| 36 | $this->yamlParser = new YamlParser(); |
| 37 | } |
| 38 | try { |
| 39 | $messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT); |
| 40 | } catch (ParseException $e) { |
| 41 | throw new InvalidResourceException(\sprintf('The file "%s" does not contain valid YAML: ', $resource) . $e->getMessage(), 0, $e); |
| 42 | } |
| 43 | if (null !== $messages && !\is_array($messages)) { |
| 44 | throw new InvalidResourceException(\sprintf('Unable to load file "%s".', $resource)); |
| 45 | } |
| 46 | return $messages ?: []; |
| 47 | } |
| 48 | } |
| 49 |