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