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

47 lines
1.1 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>
*
* @api
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) {
$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
}
}