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