Projekt

Obecné

Profil

Stáhnout (2.89 KB) Statistiky
| Větev: | Revize:
1 cb15593b Cajova-Houba
<?php
2
3
namespace Illuminate\Translation;
4
5
use Illuminate\Filesystem\Filesystem;
6
7
class FileLoader implements LoaderInterface
8
{
9
    /**
10
     * The filesystem instance.
11
     *
12
     * @var \Illuminate\Filesystem\Filesystem
13
     */
14
    protected $files;
15
16
    /**
17
     * The default path for the loader.
18
     *
19
     * @var string
20
     */
21
    protected $path;
22
23
    /**
24
     * All of the namespace hints.
25
     *
26
     * @var array
27
     */
28
    protected $hints = [];
29
30
    /**
31
     * Create a new file loader instance.
32
     *
33
     * @param  \Illuminate\Filesystem\Filesystem  $files
34
     * @param  string  $path
35
     * @return void
36
     */
37
    public function __construct(Filesystem $files, $path)
38
    {
39
        $this->path = $path;
40
        $this->files = $files;
41
    }
42
43
    /**
44
     * Load the messages for the given locale.
45
     *
46
     * @param  string  $locale
47
     * @param  string  $group
48
     * @param  string  $namespace
49
     * @return array
50
     */
51
    public function load($locale, $group, $namespace = null)
52
    {
53
        if (is_null($namespace) || $namespace == '*') {
54
            return $this->loadPath($this->path, $locale, $group);
55
        }
56
57
        return $this->loadNamespaced($locale, $group, $namespace);
58
    }
59
60
    /**
61
     * Load a namespaced translation group.
62
     *
63
     * @param  string  $locale
64
     * @param  string  $group
65
     * @param  string  $namespace
66
     * @return array
67
     */
68
    protected function loadNamespaced($locale, $group, $namespace)
69
    {
70
        if (isset($this->hints[$namespace])) {
71
            $lines = $this->loadPath($this->hints[$namespace], $locale, $group);
72
73
            return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace);
74
        }
75
76
        return [];
77
    }
78
79
    /**
80
     * Load a local namespaced translation group for overrides.
81
     *
82
     * @param  array  $lines
83
     * @param  string  $locale
84
     * @param  string  $group
85
     * @param  string  $namespace
86
     * @return array
87
     */
88
    protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)
89
    {
90
        $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php";
91
92
        if ($this->files->exists($file)) {
93
            return array_replace_recursive($lines, $this->files->getRequire($file));
94
        }
95
96
        return $lines;
97
    }
98
99
    /**
100
     * Load a locale from a given path.
101
     *
102
     * @param  string  $path
103
     * @param  string  $locale
104
     * @param  string  $group
105
     * @return array
106
     */
107
    protected function loadPath($path, $locale, $group)
108
    {
109
        if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) {
110
            return $this->files->getRequire($full);
111
        }
112
113
        return [];
114
    }
115
116
    /**
117
     * Add a new namespace to the loader.
118
     *
119
     * @param  string  $namespace
120
     * @param  string  $hint
121
     * @return void
122
     */
123
    public function addNamespace($namespace, $hint)
124
    {
125
        $this->hints[$namespace] = $hint;
126
    }
127
}