1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Console; |
6
|
|
|
|
7
|
|
|
use FilesystemIterator; |
8
|
|
|
use Gacela\Console\Domain\AllAppModules\AllAppModulesFinder; |
9
|
|
|
use Gacela\Console\Domain\AllAppModules\AppModuleCreator; |
10
|
|
|
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParser; |
11
|
|
|
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParserInterface; |
12
|
|
|
use Gacela\Console\Domain\FileContent\FileContentGenerator; |
13
|
|
|
use Gacela\Console\Domain\FileContent\FileContentGeneratorInterface; |
14
|
|
|
use Gacela\Console\Domain\FileContent\FileContentIoInterface; |
15
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer; |
16
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizerInterface; |
17
|
|
|
use Gacela\Console\Infrastructure\FileContentIo; |
18
|
|
|
use Gacela\Framework\AbstractFactory; |
19
|
|
|
use Gacela\Framework\ClassResolver\Config\ConfigResolver; |
20
|
|
|
use Gacela\Framework\ClassResolver\Factory\FactoryResolver; |
21
|
|
|
use Gacela\Framework\ClassResolver\Provider\ProviderResolver; |
22
|
|
|
use Gacela\Framework\Gacela; |
23
|
|
|
use RecursiveDirectoryIterator; |
24
|
|
|
use RecursiveIteratorIterator; |
25
|
|
|
use Symfony\Component\Console\Command\Command; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @method ConsoleConfig getConfig() |
29
|
|
|
*/ |
30
|
|
|
final class ConsoleFactory extends AbstractFactory |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @return list<Command> |
34
|
|
|
* |
35
|
|
|
* @psalm-suppress MixedReturnTypeCoercion |
36
|
10 |
|
*/ |
37
|
|
|
public function getConsoleCommands(): array |
38
|
10 |
|
{ |
39
|
|
|
return (array)$this->getProvidedDependency(ConsoleProvider::COMMANDS); |
40
|
|
|
} |
41
|
12 |
|
|
42
|
|
|
public function createCommandArgumentsParser(): CommandArgumentsParserInterface |
43
|
12 |
|
{ |
44
|
12 |
|
return new CommandArgumentsParser( |
45
|
12 |
|
$this->getConfig()->getComposerJsonContentAsArray(), |
46
|
|
|
); |
47
|
|
|
} |
48
|
9 |
|
|
49
|
|
|
public function createFilenameSanitizer(): FilenameSanitizerInterface |
50
|
9 |
|
{ |
51
|
|
|
return new FilenameSanitizer(); |
52
|
|
|
} |
53
|
10 |
|
|
54
|
|
|
public function createFileContentGenerator(): FileContentGeneratorInterface |
55
|
10 |
|
{ |
56
|
10 |
|
return new FileContentGenerator( |
57
|
10 |
|
$this->createFileContentIo(), |
58
|
10 |
|
$this->getTemplateByFilenameMap(), |
59
|
|
|
); |
60
|
|
|
} |
61
|
6 |
|
|
62
|
|
|
public function createAllAppModulesFinder(): AllAppModulesFinder |
63
|
6 |
|
{ |
64
|
6 |
|
return new AllAppModulesFinder( |
65
|
6 |
|
$this->createRecursiveIterator(), |
66
|
6 |
|
$this->createAppModuleCreator(), |
67
|
|
|
); |
68
|
|
|
} |
69
|
8 |
|
|
70
|
|
|
public function createAppModuleCreator(): AppModuleCreator |
71
|
8 |
|
{ |
72
|
8 |
|
return new AppModuleCreator( |
73
|
8 |
|
new FactoryResolver(), |
74
|
8 |
|
new ConfigResolver(), |
75
|
8 |
|
new ProviderResolver(), |
76
|
|
|
); |
77
|
|
|
} |
78
|
6 |
|
|
79
|
|
|
/** |
80
|
6 |
|
* @return RecursiveIteratorIterator<RecursiveDirectoryIterator> |
81
|
6 |
|
*/ |
82
|
6 |
|
private function createRecursiveIterator(): RecursiveIteratorIterator |
83
|
6 |
|
{ |
84
|
|
|
return new RecursiveIteratorIterator( |
85
|
|
|
new RecursiveDirectoryIterator(Gacela::rootDir(), FilesystemIterator::SKIP_DOTS), |
86
|
10 |
|
RecursiveIteratorIterator::LEAVES_ONLY, |
87
|
|
|
); |
88
|
10 |
|
} |
89
|
|
|
|
90
|
|
|
private function createFileContentIo(): FileContentIoInterface |
91
|
|
|
{ |
92
|
|
|
return new FileContentIo(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
10 |
|
* @psalm-suppress MixedReturnTypeCoercion |
97
|
|
|
* |
98
|
10 |
|
* @return array<string,string> |
99
|
|
|
*/ |
100
|
|
|
private function getTemplateByFilenameMap(): array |
101
|
|
|
{ |
102
|
|
|
return (array)$this->getProvidedDependency(ConsoleProvider::TEMPLATE_BY_FILENAME_MAP); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|