2010-11-14 19:27:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-11-14 19:27:35 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-11-14 19:27:35 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +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
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Translation\Loader;
|
|
|
|
|
2012-12-12 19:43:13 +00:00
|
|
|
use Symfony\Component\Translation\Exception\InvalidResourceException;
|
2013-05-05 10:27:54 +01:00
|
|
|
use Symfony\Component\Yaml\Parser as YamlParser;
|
2012-12-12 19:43:13 +00:00
|
|
|
use Symfony\Component\Yaml\Exception\ParseException;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
2010-11-14 19:27:35 +00:00
|
|
|
/**
|
|
|
|
* YamlFileLoader loads translations from Yaml files.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-03-24 08:07:52 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
{
|
2013-05-05 10:27:54 +01: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
|
|
|
{
|
2013-05-05 10:27:54 +01:00
|
|
|
if (null === $this->yamlParser) {
|
|
|
|
$this->yamlParser = new YamlParser();
|
|
|
|
}
|
|
|
|
|
2012-12-12 19:43:13 +00:00
|
|
|
try {
|
2013-05-05 10:27:54 +01:00
|
|
|
$messages = $this->yamlParser->parse(file_get_contents($resource));
|
2012-12-12 19:43:13 +00:00
|
|
|
} catch (ParseException $e) {
|
2014-05-20 09:28:23 +01:00
|
|
|
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
|
2012-12-12 19:43:13 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|