1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maestriam\Samurai\Foundation; |
4
|
|
|
|
5
|
|
|
use Maestriam\FileSystem\Support\FileSystem; |
|
|
|
|
6
|
|
|
|
7
|
|
|
class ConfigKeeper |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Retorna o nome da chave que será aplicada no arquivo .env. |
11
|
|
|
* Se não conseguir encontrar a chave no arquivo de configuração |
12
|
|
|
* do pacote, retorne CURRENT_THEME. |
13
|
|
|
* |
14
|
|
|
* @return string |
15
|
|
|
*/ |
16
|
|
|
public function env() : string |
17
|
|
|
{ |
18
|
|
|
return config('samurai.env_key') ?? 'CURRENT_THEME'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Retorna o caminho-base dos temas dentro do projeto |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function base() : string |
27
|
|
|
{ |
28
|
|
|
$default = base_path('themes'); |
29
|
|
|
|
30
|
|
|
$base = config('samurai.themes.folder') ?? $default; |
31
|
|
|
$base .= DS; |
32
|
|
|
|
33
|
|
|
return FileSystem::folder($base)->sanitize(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Retorna as configurações do autor para criação de um tema |
38
|
|
|
* |
39
|
|
|
* @return object |
40
|
|
|
*/ |
41
|
|
|
public function author() : object |
42
|
|
|
{ |
43
|
|
|
$author = config('samurai.author'); |
44
|
|
|
|
45
|
|
|
return (object) $author; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Retorna o nome do distribuidor padrão do tema |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function dist() : string |
54
|
|
|
{ |
55
|
|
|
return config('samurai.author.dist') ?? 'maestriam'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Retorna o texto da descrição para a criação de um novo tema |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function description() : string |
64
|
|
|
{ |
65
|
|
|
$default = 'A new awsome theme is comming!'; |
66
|
|
|
|
67
|
|
|
return config('samurai.description') ?? $default; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Retorna o caminho do diretório onde está armazenado os |
72
|
|
|
* arquivos de template |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function template() : string |
77
|
|
|
{ |
78
|
|
|
return config('samurai.template_path'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Retorna a relação de tipos de templates com o caminho |
83
|
|
|
* onde ele deve ser inserido no diretório |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function structure() : array |
88
|
|
|
{ |
89
|
|
|
return config('samurai.structure'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Retorna o diretório que deverá |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function publishable() : string |
98
|
|
|
{ |
99
|
|
|
return config('samurai.publishable'); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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: