1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\AbstractCreator; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Process\ReplaceNameProcess; |
7
|
|
|
|
8
|
|
|
abstract class AbstractEmbeddableCreator extends AbstractCreator |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string|null |
12
|
|
|
*/ |
13
|
|
|
protected $catName; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string|null |
17
|
|
|
*/ |
18
|
|
|
protected $name; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
public function createTargetFileObject(string $newObjectFqn = null): AbstractCreator |
22
|
|
|
{ |
23
|
|
|
if (null !== $newObjectFqn) { |
24
|
|
|
throw new \InvalidArgumentException('You do not pass a new object FQN into this creator'); |
25
|
|
|
} |
26
|
|
|
if ('' === (string)$this->catName) { |
27
|
|
|
throw new \RuntimeException('You must call setCatName before running this creator'); |
28
|
|
|
} |
29
|
|
|
if ('' === (string)$this->name) { |
30
|
|
|
throw new \RuntimeException('You must call setName before running this creator'); |
31
|
|
|
} |
32
|
|
|
if ('' === (string)$this->projectRootNamespace) { |
33
|
|
|
throw new \RuntimeException('You must call setProjectRootNamespace before running this creator'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return parent::createTargetFileObject($this->getNewObjectFqn()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
abstract protected function getNewObjectFqn(): string; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $catName |
43
|
|
|
* |
44
|
|
|
* @return AbstractEmbeddableCreator |
45
|
|
|
*/ |
46
|
|
|
public function setCatName(string $catName): AbstractEmbeddableCreator |
47
|
|
|
{ |
48
|
|
|
$this->catName = $catName; |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $name |
55
|
|
|
* |
56
|
|
|
* @return AbstractEmbeddableCreator |
57
|
|
|
*/ |
58
|
|
|
public function setName(string $name): AbstractEmbeddableCreator |
59
|
|
|
{ |
60
|
|
|
$this->name = $name; |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function configurePipeline(): void |
66
|
|
|
{ |
67
|
|
|
parent::configurePipeline(); |
68
|
|
|
$this->registerReplaceSkeletonEmbeddable(); |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function registerReplaceSkeletonEmbeddable(): void |
73
|
|
|
{ |
74
|
|
|
$replaceName = new ReplaceNameProcess(); |
75
|
|
|
$replaceName->setArgs( |
76
|
|
|
'CatName', |
77
|
|
|
$this->catName |
|
|
|
|
78
|
|
|
); |
79
|
|
|
$this->pipeline->register($replaceName); |
80
|
|
|
$replaceName = new ReplaceNameProcess(); |
81
|
|
|
$replaceName->setArgs( |
82
|
|
|
'Skeleton', |
83
|
|
|
$this->name |
84
|
|
|
); |
85
|
|
|
$this->pipeline->register($replaceName); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
} |