This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Translation/Loader/YamlFileLoader.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2010-11-14 19:27:35 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-11-14 19:27:35 +00:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-11-14 19:27:35 +00:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-11-14 19:27:35 +00:00
*/
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Yaml\Parser as YamlParser;
use Symfony\Component\Yaml\Exception\ParseException;
2010-11-14 19:27:35 +00:00
/**
* YamlFileLoader loads translations from Yaml files.
*
* @author Fabien Potencier <fabien@symfony.com>
2010-11-14 19:27:35 +00:00
*/
2015-04-15 01:53:15 +01:00
class YamlFileLoader extends FileLoader
2010-11-14 19:27:35 +00:00
{
private $yamlParser;
2010-11-14 19:27:35 +00:00
/**
* {@inheritdoc}
*/
2015-04-15 01:53:15 +01:00
protected function loadResource($resource)
2010-11-14 19:27:35 +00:00
{
if (null === $this->yamlParser) {
Merge branch '2.7' into 2.8 * 2.7: (70 commits) [travis] Use container-based infrastructure [HttpKernel] use ConfigCache::getPath() method when it exists [PropertyAccess] Fix setting public property on a class having a magic getter [Routing] Display file which contain deprecated option ContainerInterface: unused exception dropped bumped Symfony version to 2.6.8 updated VERSION for 2.6.7 updated CHANGELOG for 2.6.7 bumped Symfony version to 2.3.29 updated VERSION for 2.3.28 update CONTRIBUTORS for 2.3.28 updated CHANGELOG for 2.3.28 [Debug] Fixed ClassNotFoundFatalErrorHandlerTest [SecurityBundle] use access decision constants in config [SecurityBundle] use session auth constants in config PhpDoc fix in AbstractRememberMeServices [Filesystem] Simplified an if statement [SecurityBundle] Use Enum Nodes Instead Of Scalar [Debug 2.3] Fix test for PHP7 [HttpKernel] Check if "symfony/proxy-manager-bridge" package is installed ... Conflicts: src/Symfony/Bundle/DebugBundle/composer.json src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Component/Form/README.md src/Symfony/Component/Intl/README.md src/Symfony/Component/Security/README.md src/Symfony/Component/Translation/Loader/CsvFileLoader.php src/Symfony/Component/Translation/Loader/IniFileLoader.php src/Symfony/Component/Translation/Loader/MoFileLoader.php src/Symfony/Component/Translation/Loader/PhpFileLoader.php src/Symfony/Component/Translation/Loader/PoFileLoader.php src/Symfony/Component/Translation/Loader/YamlFileLoader.php src/Symfony/Component/Translation/README.md src/Symfony/Component/Translation/Translator.php src/Symfony/Component/Validator/README.md
2015-05-12 16:16:46 +01:00
if (!class_exists('Symfony\Component\Yaml\Parser')) {
throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
}
$this->yamlParser = new YamlParser();
}
try {
$messages = $this->yamlParser->parse(file_get_contents($resource));
} catch (ParseException $e) {
2014-05-20 09:28:23 +01:00
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
}
2010-11-14 19:27:35 +00:00
2015-04-15 01:53:15 +01:00
return $messages;
2010-11-14 19:27:35 +00:00
}
}