|
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
|
|
|
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
|
|
|
parent::__construct($fileFactory, $namespaceHelper, $fileWriter, $config, $findReplaceFactory); |
|
49
|
|
|
$this->reflectionHelper = $reflectionHelper; |
|
50
|
|
|
$this->codeHelper = $codeHelper; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function configurePipeline(): void |
|
54
|
|
|
{ |
|
55
|
|
|
parent::configurePipeline(); |
|
56
|
|
|
$this->registerReplaceEntitiesNamespaceProcess(); |
|
57
|
|
|
$this->registerDataTransferObjectProcess(); |
|
58
|
|
|
$this->registerEntityReplaceName($this->getEntityFqn()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function registerReplaceEntitiesNamespaceProcess(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$process = new ReplaceEntitiesSubNamespaceProcess(); |
|
64
|
|
|
$process->setEntityFqn($this->getEntityFqn()); |
|
65
|
|
|
$process->setProjectRootNamespace($this->projectRootNamespace); |
|
66
|
|
|
$this->pipeline->register($process); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
private function getEntityFqn(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->entityFqn ?? $this->namespaceHelper->getEntityFqnFromEntityDtoFqn($this->newObjectFqn); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function registerDataTransferObjectProcess(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$process = new CreateDtoBodyProcess($this->reflectionHelper, $this->codeHelper, $this->namespaceHelper); |
|
77
|
|
|
$process->setEntityFqn($this->getEntityFqn()); |
|
78
|
|
|
$this->pipeline->register($process); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function setNewObjectFqnFromEntityFqn(string $entityFqn): self |
|
82
|
|
|
{ |
|
83
|
|
|
$this->entityFqn = $entityFqn; |
|
84
|
|
|
$this->newObjectFqn = $this->namespaceHelper->getEntityDtoFqnFromEntityFqn($entityFqn); |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.