1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\DataTransferObjects; |
6
|
|
|
|
7
|
|
|
// phpcs:disable |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\CodeHelper; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\AbstractCreator; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Process\ReplaceEntitiesSubNamespaceProcess; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Process\Src\Entity\DataTransferObjects\CreateDtoBodyProcess; |
12
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FileFactory; |
13
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FindReplaceFactory; |
14
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File; |
15
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
16
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\ReflectionHelper; |
17
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Config; |
18
|
|
|
|
19
|
|
|
// phpcs:enable |
20
|
|
|
class DtoCreator extends AbstractCreator |
21
|
|
|
{ |
22
|
|
|
public const FIND_NAME = 'TemplateEntityDto'; |
23
|
|
|
|
24
|
|
|
public const TEMPLATE_PATH = self::ROOT_TEMPLATE_PATH . |
25
|
|
|
'/src/Entity/DataTransferObjects/' . |
26
|
|
|
self::FIND_NAME . |
27
|
|
|
'.php'; |
28
|
|
|
/** |
29
|
|
|
* @var ReflectionHelper |
30
|
|
|
*/ |
31
|
|
|
private $reflectionHelper; |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $entityFqn; |
36
|
|
|
/** |
37
|
|
|
* @var CodeHelper |
38
|
|
|
*/ |
39
|
|
|
private $codeHelper; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
FileFactory $fileFactory, |
43
|
|
|
NamespaceHelper $namespaceHelper, |
44
|
|
|
File\Writer $fileWriter, |
45
|
|
|
Config $config, |
46
|
|
|
FindReplaceFactory $findReplaceFactory, |
47
|
|
|
ReflectionHelper $reflectionHelper, |
48
|
|
|
CodeHelper $codeHelper |
49
|
|
|
) { |
50
|
|
|
parent::__construct($fileFactory, $namespaceHelper, $fileWriter, $config, $findReplaceFactory); |
51
|
|
|
$this->reflectionHelper = $reflectionHelper; |
52
|
|
|
$this->codeHelper = $codeHelper; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function configurePipeline(): void |
56
|
|
|
{ |
57
|
|
|
parent::configurePipeline(); |
58
|
|
|
$this->registerReplaceEntitiesNamespaceProcess(); |
59
|
|
|
$this->registerDataTransferObjectProcess(); |
60
|
|
|
$this->registerEntityReplaceName($this->getEntityFqn()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function registerReplaceEntitiesNamespaceProcess(): void |
64
|
|
|
{ |
65
|
|
|
$process = new ReplaceEntitiesSubNamespaceProcess(); |
66
|
|
|
$process->setEntityFqn($this->getEntityFqn()); |
67
|
|
|
$process->setProjectRootNamespace($this->projectRootNamespace); |
|
|
|
|
68
|
|
|
$this->pipeline->register($process); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function getEntityFqn(): string |
72
|
|
|
{ |
73
|
|
|
return $this->entityFqn ?? $this->namespaceHelper->getEntityFqnFromEntityDtoFqn($this->newObjectFqn); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
private function registerDataTransferObjectProcess(): void |
77
|
|
|
{ |
78
|
|
|
$process = new CreateDtoBodyProcess($this->reflectionHelper, $this->codeHelper, $this->namespaceHelper); |
79
|
|
|
$process->setEntityFqn($this->getEntityFqn()); |
80
|
|
|
$this->pipeline->register($process); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setNewObjectFqnFromEntityFqn(string $entityFqn): self |
84
|
|
|
{ |
85
|
|
|
$this->entityFqn = $entityFqn; |
86
|
|
|
$this->newObjectFqn = $this->namespaceHelper->getEntityDtoFqnFromEntityFqn($entityFqn); |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|