1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Console; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\Domain\Cache\CacheClearer; |
8
|
|
|
use Gacela\Console\Domain\Cache\DirectoryIoInterface; |
9
|
|
|
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParser; |
10
|
|
|
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParserInterface; |
11
|
|
|
use Gacela\Console\Domain\FileContent\FileContentGenerator; |
12
|
|
|
use Gacela\Console\Domain\FileContent\FileContentGeneratorInterface; |
13
|
|
|
use Gacela\Console\Domain\FileContent\FileContentIoInterface; |
14
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer; |
15
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizerInterface; |
16
|
|
|
use Gacela\Console\Infrastructure\DirectoryIo; |
17
|
|
|
use Gacela\Console\Infrastructure\FileContentIo; |
18
|
|
|
use Gacela\Framework\AbstractFactory; |
19
|
|
|
use Symfony\Component\Console\Command\Command; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @method ConsoleConfig getConfig() |
23
|
|
|
*/ |
24
|
|
|
final class ConsoleFactory extends AbstractFactory |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @return list<Command> |
28
|
|
|
* |
29
|
|
|
* @psalm-suppress MixedReturnTypeCoercion |
30
|
|
|
*/ |
31
|
|
|
public function getConsoleCommands(): array |
32
|
|
|
{ |
33
|
|
|
return (array)$this->getProvidedDependency(ConsoleDependencyProvider::COMMANDS); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function createCommandArgumentsParser(): CommandArgumentsParserInterface |
37
|
|
|
{ |
38
|
|
|
return new CommandArgumentsParser( |
39
|
|
|
$this->getConfig()->getComposerJsonContentAsArray() |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function createFilenameSanitizer(): FilenameSanitizerInterface |
44
|
|
|
{ |
45
|
|
|
return new FilenameSanitizer(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function createFileContentGenerator(): FileContentGeneratorInterface |
49
|
|
|
{ |
50
|
|
|
return new FileContentGenerator( |
51
|
|
|
$this->createFileContentIo(), |
52
|
|
|
$this->getTemplateByFilenameMap() |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function createCacheClearer(): CacheClearer |
57
|
|
|
{ |
58
|
|
|
return new CacheClearer( |
59
|
|
|
$this->getConfig()->getCacheDir(), |
60
|
|
|
$this->createDirectoryIo() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function createFileContentIo(): FileContentIoInterface |
65
|
|
|
{ |
66
|
|
|
return new FileContentIo(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array<string,string> |
71
|
|
|
*/ |
72
|
|
|
private function getTemplateByFilenameMap(): array |
73
|
|
|
{ |
74
|
|
|
/** @var array<string,string> $map */ |
75
|
|
|
$map = $this->getProvidedDependency(ConsoleDependencyProvider::TEMPLATE_BY_FILENAME_MAP); |
76
|
|
|
|
77
|
|
|
return $map; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function createDirectoryIo(): DirectoryIoInterface |
81
|
|
|
{ |
82
|
|
|
return new DirectoryIo(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|