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