maestriam /
samurai
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Maestriam\Samurai\Foundation; |
||
| 4 | |||
| 5 | use Illuminate\Support\Facades\Config; |
||
| 6 | |||
| 7 | class DirectoryStructure |
||
| 8 | { |
||
| 9 | private ConfigKeeper $configInstance; |
||
| 10 | |||
| 11 | public function __construct() |
||
| 12 | { |
||
| 13 | $this->setConfig(); |
||
| 14 | } |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Retorna o nome do diretório do |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function vendor() : string |
||
| 22 | { |
||
| 23 | return base_path('vendor'); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Retorna o caminho do tema dentro do diretório-base |
||
| 28 | * de temas ou dentro do diretório do composer |
||
| 29 | * |
||
| 30 | * @param string $name |
||
| 31 | * @return string |
||
| 32 | */ |
||
| 33 | public function theme(string $vendor, string $name) : ?string |
||
| 34 | { |
||
| 35 | $base = $this->config()->base(); |
||
| 36 | |||
| 37 | // $finded = $this->findVendor($vendor, $name); |
||
| 38 | |||
| 39 | // if ($finded) return $finded; |
||
| 40 | |||
| 41 | return $this->findTheme($base, $vendor, $name); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Retorna o caminho relativo de um tema/diretiva |
||
| 46 | * dentro do projeto |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | public function indicative(string $path) : string |
||
| 51 | { |
||
| 52 | $base = base_path() . DS; |
||
| 53 | |||
| 54 | return str_replace($base, '', $path); |
||
|
0 ignored issues
–
show
|
|||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Undocumented function |
||
| 59 | * |
||
| 60 | * @param string $name |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | public function assets(string $vendor, string $name) : string |
||
| 64 | { |
||
| 65 | $assets = config('samurai.themes.assets'); |
||
| 66 | |||
| 67 | return $this->theme($vendor, $name) . DS . $assets; |
||
|
0 ignored issues
–
show
|
|||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Retorna o caminho público onde os assets |
||
| 72 | * do tema são armazenados |
||
| 73 | * |
||
| 74 | * @param string $name |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | public function public(string $vendor, string $name) : string |
||
| 78 | { |
||
| 79 | return public_path('themes'. DS . $vendor . DS . $name); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Retorna o nome do diretório do projeto |
||
| 84 | * Para receber o caminho completo, basta passar true em $path |
||
| 85 | * |
||
| 86 | * @param boolean $path |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function project(bool $path = false) : string |
||
| 90 | { |
||
| 91 | $dir = base_path(); |
||
| 92 | |||
| 93 | $pieces = explode(DS, $dir); |
||
| 94 | |||
| 95 | return ($path == true ) ? $dir : end($pieces); |
||
|
0 ignored issues
–
show
|
|||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Undocumented function |
||
| 100 | * |
||
| 101 | * @param string $name |
||
| 102 | * @return void |
||
| 103 | */ |
||
| 104 | public function files(string $vendor, string $name) : string |
||
| 105 | { |
||
| 106 | $files = config('samurai.themes.files'); |
||
| 107 | |||
| 108 | return $this->theme($vendor, $name) . DS . $files . DS; |
||
|
0 ignored issues
–
show
|
|||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Undocumented function |
||
| 113 | * |
||
| 114 | * @param string $vendor |
||
| 115 | * @param string $name |
||
| 116 | * @return string|null |
||
| 117 | */ |
||
| 118 | private function findVendor(string $vendor, string $name) : ?string |
||
|
0 ignored issues
–
show
|
|||
| 119 | { |
||
| 120 | $base = $this->vendor(); |
||
| 121 | |||
| 122 | $path = $this->findTheme($base, $vendor, $name); |
||
| 123 | |||
| 124 | return (is_dir($path)) ? $path : null; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Retorna o caminho do diretório de um tema dado o nome |
||
| 129 | * |
||
| 130 | * @param string $base |
||
| 131 | * @param string $name |
||
| 132 | * @return string|null |
||
| 133 | */ |
||
| 134 | private function findTheme(string $base, string $vendor, string $name) : string |
||
| 135 | { |
||
| 136 | $name = strtolower($name); |
||
| 137 | |||
| 138 | $path = $base . $vendor . DS . $name; |
||
| 139 | |||
| 140 | return $path; |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Retorna a instância de configurações do arquivo. |
||
| 145 | * |
||
| 146 | * @return ConfigKeeper |
||
| 147 | */ |
||
| 148 | private function config() : ConfigKeeper |
||
| 149 | { |
||
| 150 | return $this->configInstance; |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Define a instância de configurações do arquivo. |
||
| 155 | * |
||
| 156 | * @return DirectoryStructure |
||
| 157 | */ |
||
| 158 | private function setConfig() : DirectoryStructure |
||
| 159 | { |
||
| 160 | $this->configInstance = new ConfigKeeper(); |
||
| 161 | |||
| 162 | return $this; |
||
| 163 | } |
||
| 164 | } |
||
| 165 |