Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
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
 * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
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
        // empty resource
37
        $messages ??= [];
38
 
39
        // not an array
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
     * @throws InvalidResourceException if stream content has an invalid format
55
     */
56
    abstract protected function loadResource(string $resource): array;
57
}