Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Translation] added FileLoader.
- Loading branch information
Showing
8 changed files
with
83 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Loader; | ||
|
||
use Symfony\Component\Translation\Exception\InvalidResourceException; | ||
use Symfony\Component\Translation\Exception\NotFoundResourceException; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
|
||
/** | ||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com> | ||
*/ | ||
abstract class FileLoader extends ArrayLoader | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load($resource, $locale, $domain = 'messages') | ||
{ | ||
if (!stream_is_local($resource)) { | ||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); | ||
} | ||
|
||
if (!file_exists($resource)) { | ||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); | ||
} | ||
|
||
$messages = $this->loadResource($resource); | ||
|
||
// empty resource | ||
if (null === $messages) { | ||
$messages = array(); | ||
} | ||
|
||
// not an array | ||
if (!is_array($messages)) { | ||
throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource)); | ||
} | ||
|
||
$catalogue = parent::load($messages, $locale, $domain); | ||
$catalogue->addResource(new FileResource($resource)); | ||
|
||
return $catalogue; | ||
} | ||
|
||
/* | ||
* @param string $resource | ||
* | ||
* @return array | ||
* | ||
* @throws InvalidResourceException If stream content has an invalid format. | ||
*/ | ||
abstract protected function loadResource($resource); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.