| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Loader; |
| 13 |
|
| 14 |
use Symfony\Component\Config\Resource\FileResource; |
| 15 |
use Symfony\Component\Translation\Exception\InvalidResourceException; |
| 16 |
use Symfony\Component\Translation\Exception\NotFoundResourceException; |
| 17 |
use Symfony\Component\Translation\MessageCatalogue; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
abstract class FileLoader extends ArrayLoader |
| 23 |
{ |
| 24 |
public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue |
| 25 |
{ |
| 26 |
if (!stream_is_local($resource)) { |
| 27 |
throw new InvalidResourceException(\sprintf('This is not a local file "%s".', $resource)); |
| 28 |
} |
| 29 |
|
| 30 |
if (!file_exists($resource)) { |
| 31 |
throw new NotFoundResourceException(\sprintf('File "%s" not found.', $resource)); |
| 32 |
} |
| 33 |
|
| 34 |
$messages = $this->loadResource($resource); |
| 35 |
|
| 36 |
|
| 37 |
$messages ??= []; |
| 38 |
|
| 39 |
|
| 40 |
if (!\is_array($messages)) { |
| 41 |
throw new InvalidResourceException(\sprintf('Unable to load file "%s".', $resource)); |
| 42 |
} |
| 43 |
|
| 44 |
$catalogue = parent::load($messages, $locale, $domain); |
| 45 |
|
| 46 |
if (class_exists(FileResource::class)) { |
| 47 |
$catalogue->addResource(new FileResource($resource)); |
| 48 |
} |
| 49 |
|
| 50 |
return $catalogue; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
abstract protected function loadResource(string $resource): array; |
| 57 |
} |