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.2 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.potencier@symfony-project.com>
*
* 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\Resource\FileResource;
use Symfony\Component\Yaml\Yaml;
2010-11-14 19:27:35 +00:00
/**
* YamlFileLoader loads translations from Yaml files.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class YamlFileLoader extends ArrayLoader implements LoaderInterface
2010-11-14 19:27:35 +00:00
{
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = Yaml::load($resource);
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
2010-11-14 19:27:35 +00:00
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
}