1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the "andrey-helldar/laravel-lang-publisher" project. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @author Andrey Helldar <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @copyright 2021 Andrey Helldar |
12
|
|
|
* |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @see https://github.com/andrey-helldar/laravel-lang-publisher |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Helldar\LaravelLangPublisher\Helpers; |
21
|
|
|
|
22
|
|
|
use function config; |
|
|
|
|
23
|
|
|
use Helldar\Contracts\LangPublisher\Provider; |
24
|
|
|
use Helldar\LaravelLangPublisher\Constants\Config as ConfigConst; |
25
|
|
|
use Helldar\Support\Facades\Helpers\Ables\Arrayable; |
26
|
|
|
|
27
|
|
|
use Helldar\Support\Facades\Helpers\Instance; |
28
|
|
|
|
29
|
|
|
class Config |
30
|
|
|
{ |
31
|
|
|
public function vendor(): string |
32
|
|
|
{ |
33
|
|
|
return $this->getPrivate('path.base'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function resources(): string |
37
|
|
|
{ |
38
|
|
|
return $this->getPrivate('path.resources'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function plugins(): array |
42
|
|
|
{ |
43
|
|
|
$private = $this->getPrivate('plugins'); |
44
|
|
|
$public = $this->getPublic('plugins'); |
45
|
|
|
|
46
|
|
|
return Arrayable::of($public) |
47
|
|
|
->merge($private) |
48
|
|
|
->unique() |
49
|
|
|
->filter(static function (string $plugin) { |
50
|
|
|
return Instance::exists($plugin) |
51
|
|
|
&& Instance::of($plugin, Provider::class); |
52
|
|
|
}) |
53
|
|
|
->sort() |
54
|
|
|
->get(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function hasInline(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->getPublic('inline'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function hasAlignment(): bool |
63
|
|
|
{ |
64
|
|
|
return $this->getPublic('alignment'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function excludes(): array |
68
|
|
|
{ |
69
|
|
|
return $this->getPublic('excludes'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function case(): int |
73
|
|
|
{ |
74
|
|
|
return $this->getPublic('case'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function getPrivate(string $key) |
78
|
|
|
{ |
79
|
|
|
$key = $this->privateKey($key); |
80
|
|
|
|
81
|
|
|
return config($key); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function getPublic(string $key) |
85
|
|
|
{ |
86
|
|
|
$key = $this->publicKey($key); |
87
|
|
|
|
88
|
|
|
return config($key); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function privateKey(string $suffix): string |
92
|
|
|
{ |
93
|
|
|
return ConfigConst::PRIVATE_KEY . '.' . $suffix; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
protected function publicKey(string $suffix): string |
97
|
|
|
{ |
98
|
|
|
return ConfigConst::PUBLIC_KEY . '.' . $suffix; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: