2010-09-27 08:45:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-09-27 08:45:29 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-09-27 08:45:29 +01: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-09-27 08:45:29 +01: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;
|
|
|
|
use Symfony\Component\Translation\Exception\NotFoundResourceException;
|
2011-02-10 15:15:51 +00:00
|
|
|
use Symfony\Component\Config\Resource\FileResource;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
2010-09-27 08:45:29 +01:00
|
|
|
/**
|
|
|
|
* PhpFileLoader loads translations from PHP files returning an array of translations.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-03-24 08:07:52 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-09-27 08:45:29 +01:00
|
|
|
*/
|
2015-03-20 16:17:32 +00:00
|
|
|
class PhpFileLoader extends ArrayLoader
|
2010-09-27 08:45:29 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
2011-03-24 08:07:52 +00:00
|
|
|
*
|
|
|
|
* @api
|
2010-09-27 08:45:29 +01:00
|
|
|
*/
|
2010-11-14 19:24:29 +00:00
|
|
|
public function load($resource, $locale, $domain = 'messages')
|
2010-09-27 08:45:29 +01:00
|
|
|
{
|
2012-12-12 19:43:13 +00:00
|
|
|
if (!stream_is_local($resource)) {
|
|
|
|
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
2012-12-12 16:29:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 19:43:13 +00:00
|
|
|
if (!file_exists($resource)) {
|
|
|
|
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
2011-10-07 17:30:56 +01:00
|
|
|
}
|
|
|
|
|
2014-07-27 09:25:12 +01:00
|
|
|
$messages = require $resource;
|
2010-11-14 19:31:11 +00:00
|
|
|
|
|
|
|
$catalogue = parent::load($messages, $locale, $domain);
|
2010-09-27 08:45:29 +01:00
|
|
|
$catalogue->addResource(new FileResource($resource));
|
|
|
|
|
|
|
|
return $catalogue;
|
|
|
|
}
|
|
|
|
}
|