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/PhpFileLoader.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2010-09-27 08:45:29 +01:00
<?php
/*
* This file is part of the Symfony package.
2010-09-27 08:45:29 +01:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-09-27 08:45:29 +01:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-09-27 08:45:29 +01:00
*/
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Config\Resource\FileResource;
2010-09-27 08:45:29 +01:00
/**
* PhpFileLoader loads translations from PHP files returning an array of translations.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
2010-09-27 08:45:29 +01:00
*/
class PhpFileLoader extends ArrayLoader implements LoaderInterface
2010-09-27 08:45:29 +01:00
{
/**
* {@inheritdoc}
*
* @api
2010-09-27 08:45:29 +01:00
*/
public function load($resource, $locale, $domain = 'messages')
2010-09-27 08:45:29 +01:00
{
if (!file_exists($resource)) {
throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource));
}
if (!stream_is_local($resource)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
}
$messages = require($resource);
$catalogue = parent::load($messages, $locale, $domain);
2010-09-27 08:45:29 +01:00
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
}