1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Console; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\Domain\ConsoleException; |
8
|
|
|
use Gacela\Framework\AbstractConfig; |
9
|
|
|
use JsonException; |
10
|
|
|
|
11
|
|
|
final class ConsoleConfig extends AbstractConfig |
12
|
|
|
{ |
13
|
|
|
public function getFacadeMakerTemplate(): string |
14
|
|
|
{ |
15
|
|
|
return $this->getCommandTemplateContent('facade-maker.txt'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function getFactoryMakerTemplate(): string |
19
|
|
|
{ |
20
|
|
|
return $this->getCommandTemplateContent('factory-maker.txt'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getConfigMakerTemplate(): string |
24
|
|
|
{ |
25
|
|
|
return $this->getCommandTemplateContent('config-maker.txt'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getProviderMakerTemplate(): string |
29
|
|
|
{ |
30
|
|
|
return $this->getCommandTemplateContent('provider-maker.txt'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @psalm-suppress MixedReturnTypeCoercion |
35
|
|
|
* |
36
|
|
|
* @throws ConsoleException|JsonException |
37
|
|
|
* |
38
|
|
|
* @return array{autoload: array{"psr-4": array<string,string>}} |
39
|
|
|
*/ |
40
|
|
|
public function getComposerJsonContentAsArray(): array |
41
|
|
|
{ |
42
|
|
|
$filename = $this->getAppRootDir() . '/composer.json'; |
43
|
|
|
if (!file_exists($filename)) { |
44
|
|
|
throw ConsoleException::composerJsonNotFound(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @var string $content */ |
48
|
|
|
$content = file_get_contents($filename); |
49
|
|
|
|
50
|
|
|
/** @var array{autoload: array{"psr-4": array<string,string>}} $jsonDecode */ |
51
|
|
|
$jsonDecode = json_decode(json: $content, associative: true, flags: JSON_THROW_ON_ERROR); |
52
|
|
|
|
53
|
|
|
return $jsonDecode; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getCommandTemplateContent(string $filename): string |
57
|
|
|
{ |
58
|
|
|
/** @var string $content */ |
59
|
|
|
$content = file_get_contents(__DIR__ . '/Infrastructure/Template/Command/' . $filename); |
60
|
|
|
|
61
|
|
|
return $content; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|