1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Inflector\Inflector; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Fields\Interfaces\FieldInterfaceCreator; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Fields\Traits\FieldTraitCreator; |
8
|
|
|
|
9
|
|
|
class CreateDbalFieldAndInterfaceAction implements ActionInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var FieldTraitCreator |
13
|
|
|
*/ |
14
|
|
|
private $fieldTraitCreator; |
15
|
|
|
/** |
16
|
|
|
* @var FieldInterfaceCreator |
17
|
|
|
*/ |
18
|
|
|
private $fieldInterfaceCreator; |
19
|
|
|
|
20
|
|
|
public function __construct(FieldTraitCreator $fieldTraitCreator, FieldInterfaceCreator $fieldInterfaceCreator) |
21
|
|
|
{ |
22
|
|
|
$this->fieldTraitCreator = $fieldTraitCreator; |
23
|
|
|
$this->fieldInterfaceCreator = $fieldInterfaceCreator; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This must be the method that actually performs the action |
28
|
|
|
* |
29
|
|
|
* All your requirements, configuration and dependencies must be called with individual setters |
30
|
|
|
*/ |
31
|
|
|
public function run(): void |
32
|
|
|
{ |
33
|
|
|
$this->fieldTraitCreator->createTargetFileObject()->write(); |
34
|
|
|
$this->fieldInterfaceCreator->createTargetFileObject()->write(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function setProjectRootNamespace(string $projectRootNamespace): self |
38
|
|
|
{ |
39
|
|
|
$this->fieldTraitCreator->setProjectRootNamespace($projectRootNamespace); |
40
|
|
|
$this->fieldInterfaceCreator->setProjectRootNamespace($projectRootNamespace); |
41
|
|
|
|
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function setProjectRootDirectory(string $projectRootDirectory): self |
46
|
|
|
{ |
47
|
|
|
$this->fieldTraitCreator->setProjectRootDirectory($projectRootDirectory); |
48
|
|
|
$this->fieldInterfaceCreator->setProjectRootDirectory($projectRootDirectory); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setIsUnique(bool $isUnique): self |
54
|
|
|
{ |
55
|
|
|
$this->fieldTraitCreator->setUnique($isUnique); |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function setDefaultValue($defaultValue): self |
61
|
|
|
{ |
62
|
|
|
$this->fieldInterfaceCreator->setDefaultValue($defaultValue); |
63
|
|
|
$this->fieldTraitCreator->setDefaultValue($defaultValue); |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setMappingHelperCommonType(string $mappingHelperCommonType): self |
69
|
|
|
{ |
70
|
|
|
$this->fieldTraitCreator->setMappingHelperCommonType($mappingHelperCommonType); |
71
|
|
|
$this->fieldInterfaceCreator->setMappingHelperCommonType($mappingHelperCommonType); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $fieldTraitFqn |
78
|
|
|
* |
79
|
|
|
* @return CreateDbalFieldAndInterfaceAction |
80
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
81
|
|
|
*/ |
82
|
|
|
public function setFieldTraitFqn(string $fieldTraitFqn): self |
83
|
|
|
{ |
84
|
|
|
$fieldTraitFqn = Inflector::classify($fieldTraitFqn); |
85
|
|
|
$this->fieldTraitCreator->setNewObjectFqn($fieldTraitFqn); |
86
|
|
|
$interfaceFqn = str_replace( |
87
|
|
|
[ |
88
|
|
|
'\\Traits\\', |
89
|
|
|
FieldTraitCreator::SUFFIX, |
90
|
|
|
], |
91
|
|
|
[ |
92
|
|
|
'\\Interfaces\\', |
93
|
|
|
FieldTraitCreator::INTERFACE_SUFFIX, |
94
|
|
|
], |
95
|
|
|
$fieldTraitFqn |
96
|
|
|
); |
97
|
|
|
$this->fieldInterfaceCreator->setNewObjectFqn($interfaceFqn); |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|