1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action; |
4
|
|
|
// phpcs:disable |
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\FakerData\EmbeddableFakerDataCreator; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\Interfaces\HasEmbeddableInterfaceCreator; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\Interfaces\Objects\EmbeddableInterfaceCreator; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\Objects\EmbeddableCreator; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\Traits\HasEmbeddableTraitCreator; |
10
|
|
|
// phpcs:enable |
11
|
|
|
class CreateEmbeddableAction implements ActionInterface |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var EmbeddableFakerDataCreator |
16
|
|
|
*/ |
17
|
|
|
private $fakerDataCreator; |
18
|
|
|
/** |
19
|
|
|
* @var EmbeddableInterfaceCreator |
20
|
|
|
*/ |
21
|
|
|
private $interfaceCreator; |
22
|
|
|
/** |
23
|
|
|
* @var HasEmbeddableInterfaceCreator |
24
|
|
|
*/ |
25
|
|
|
private $hasInterfaceCreator; |
26
|
|
|
/** |
27
|
|
|
* @var EmbeddableCreator |
28
|
|
|
*/ |
29
|
|
|
private $embeddableCreator; |
30
|
|
|
/** |
31
|
|
|
* @var HasEmbeddableTraitCreator |
32
|
|
|
*/ |
33
|
|
|
private $hasCreator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
*/ |
38
|
|
|
private $catName; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
*/ |
43
|
|
|
private $name; |
44
|
|
|
|
45
|
|
|
public function __construct( |
46
|
|
|
EmbeddableFakerDataCreator $fakerDataCreator, |
47
|
|
|
EmbeddableInterfaceCreator $interfaceCreator, |
48
|
|
|
HasEmbeddableInterfaceCreator $hasInterfaceCreator, |
49
|
|
|
EmbeddableCreator $embeddableCreator, |
50
|
|
|
HasEmbeddableTraitCreator $hasCreator |
51
|
|
|
) { |
52
|
|
|
$this->fakerDataCreator = $fakerDataCreator; |
53
|
|
|
$this->interfaceCreator = $interfaceCreator; |
54
|
|
|
$this->hasInterfaceCreator = $hasInterfaceCreator; |
55
|
|
|
$this->embeddableCreator = $embeddableCreator; |
56
|
|
|
$this->hasCreator = $hasCreator; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* This must be the method that actually performs the action |
62
|
|
|
* |
63
|
|
|
* All your requirements, configuration and dependencies must be called with individual setters |
64
|
|
|
*/ |
65
|
|
|
public function run(): void |
66
|
|
|
{ |
67
|
|
|
if ('' === (string)$this->catName) { |
68
|
|
|
throw new \RuntimeException('You must call setCatName before running this action'); |
69
|
|
|
} |
70
|
|
|
if ('' === (string)$this->name) { |
71
|
|
|
throw new \RuntimeException('You must call setName before running this action'); |
72
|
|
|
} |
73
|
|
|
$this->fakerDataCreator->setCatName($this->catName)->setName($this->name)->createTargetFileObject()->write(); |
|
|
|
|
74
|
|
|
$this->interfaceCreator->setCatName($this->catName)->setName($this->name)->createTargetFileObject()->write(); |
75
|
|
|
$this->hasInterfaceCreator->setCatName($this->catName)->setName($this->name)->createTargetFileObject()->write(); |
76
|
|
|
$this->embeddableCreator->setCatName($this->catName)->setName($this->name)->createTargetFileObject()->write(); |
77
|
|
|
$this->hasCreator->setCatName($this->catName)->setName($this->name)->createTargetFileObject()->write(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setProjectRootNamespace(string $projectRootNamespace) |
81
|
|
|
{ |
82
|
|
|
$this->fakerDataCreator->setProjectRootNamespace($projectRootNamespace); |
83
|
|
|
$this->interfaceCreator->setProjectRootNamespace($projectRootNamespace); |
84
|
|
|
$this->hasInterfaceCreator->setProjectRootNamespace($projectRootNamespace); |
85
|
|
|
$this->embeddableCreator->setProjectRootNamespace($projectRootNamespace); |
86
|
|
|
$this->hasCreator->setProjectRootNamespace($projectRootNamespace); |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setProjectRootDirectory(string $projectRootDirectory) |
92
|
|
|
{ |
93
|
|
|
$this->fakerDataCreator->setProjectRootDirectory($projectRootDirectory); |
94
|
|
|
$this->interfaceCreator->setProjectRootDirectory($projectRootDirectory); |
95
|
|
|
$this->hasInterfaceCreator->setProjectRootDirectory($projectRootDirectory); |
96
|
|
|
$this->embeddableCreator->setProjectRootDirectory($projectRootDirectory); |
97
|
|
|
$this->hasCreator->setProjectRootDirectory($projectRootDirectory); |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $catName |
104
|
|
|
* |
105
|
|
|
* @return CreateEmbeddableAction |
106
|
|
|
*/ |
107
|
|
|
public function setCatName(string $catName): CreateEmbeddableAction |
108
|
|
|
{ |
109
|
|
|
$this->catName = $catName; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $name |
116
|
|
|
* |
117
|
|
|
* @return CreateEmbeddableAction |
118
|
|
|
*/ |
119
|
|
|
public function setName(string $name): CreateEmbeddableAction |
120
|
|
|
{ |
121
|
|
|
$this->name = $name; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|