1
|
|
|
<?php namespace Anomaly\Streams\Platform\Lang; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Application\Application; |
4
|
|
|
use Illuminate\Filesystem\Filesystem; |
5
|
|
|
use Illuminate\Translation\FileLoader; |
6
|
|
|
|
7
|
|
|
class Loader extends FileLoader |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The application instance. |
12
|
|
|
* |
13
|
|
|
* @var Application |
14
|
|
|
*/ |
15
|
|
|
protected $application; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Create a new Loader instance. |
19
|
|
|
* |
20
|
|
|
* @param Filesystem $files |
21
|
|
|
* @param string $path |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Filesystem $files, $path) |
24
|
|
|
{ |
25
|
|
|
$this->application = app(Application::class); |
26
|
|
|
|
27
|
|
|
parent::__construct($files, $path); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Load namespaced overrides from |
32
|
|
|
* system AND application paths. |
33
|
|
|
* |
34
|
|
|
* @param array $lines |
35
|
|
|
* @param string $locale |
36
|
|
|
* @param string $group |
37
|
|
|
* @param string $namespace |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) |
41
|
|
|
{ |
42
|
|
|
$lines = $this->loadSystemOverrides($lines, $locale, $group, $namespace); |
43
|
|
|
$lines = $this->loadApplicationOverrides($lines, $locale, $group, $namespace); |
44
|
|
|
|
45
|
|
|
return parent::loadNamespaceOverrides($lines, $locale, $group, $namespace); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Load system overrides. |
50
|
|
|
* |
51
|
|
|
* @param array $lines |
52
|
|
|
* @param $locale |
53
|
|
|
* @param $group |
54
|
|
|
* @param $namespace |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function loadSystemOverrides(array $lines, $locale, $group, $namespace) |
58
|
|
|
{ |
59
|
|
View Code Duplication |
if ($namespace == 'streams') { |
|
|
|
|
60
|
|
|
$file = base_path("resources/streams/lang/{$locale}/{$group}.php"); |
61
|
|
|
|
62
|
|
|
if ($this->files->exists($file)) { |
63
|
|
|
$lines = array_replace_recursive($lines, $this->files->getRequire($file)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
if (str_is('*.*.*', $namespace)) { |
|
|
|
|
68
|
|
|
list($vendor, $type, $slug) = explode('.', $namespace); |
69
|
|
|
|
70
|
|
|
$file = base_path("resources/addons/{$vendor}/{$slug}-{$type}/lang/{$locale}/{$group}.php"); |
71
|
|
|
|
72
|
|
|
if ($this->files->exists($file)) { |
73
|
|
|
$lines = array_replace_recursive($lines, $this->files->getRequire($file)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $lines; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Load system overrides. |
82
|
|
|
* |
83
|
|
|
* @param array $lines |
84
|
|
|
* @param $locale |
85
|
|
|
* @param $group |
86
|
|
|
* @param $namespace |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
protected function loadApplicationOverrides(array $lines, $locale, $group, $namespace) |
90
|
|
|
{ |
91
|
|
View Code Duplication |
if ($namespace == 'streams') { |
|
|
|
|
92
|
|
|
$file = $this->application->getResourcesPath("streams/lang/{$locale}/{$group}.php"); |
93
|
|
|
|
94
|
|
|
if ($this->files->exists($file)) { |
95
|
|
|
$lines = array_replace_recursive($lines, $this->files->getRequire($file)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
if (str_is('*.*.*', $namespace)) { |
|
|
|
|
100
|
|
|
list($vendor, $type, $slug) = explode('.', $namespace); |
101
|
|
|
|
102
|
|
|
$file = $this->application->getResourcesPath( |
103
|
|
|
"addons/{$vendor}/{$slug}-{$type}/lang/{$locale}/{$group}.php" |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
if ($this->files->exists($file)) { |
107
|
|
|
$lines = array_replace_recursive($lines, $this->files->getRequire($file)); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $lines; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.