1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace TemplateNamespace\Entity\Embeddable\Objects\CatName; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
8
|
|
|
use TemplateNamespace\Entity\Embeddable\Interfaces\CatName\HasSkeletonEmbeddableInterface; |
9
|
|
|
use TemplateNamespace\Entity\Embeddable\Interfaces\Objects\CatName\SkeletonEmbeddableInterface; |
10
|
|
|
|
11
|
|
|
class SkeletonEmbeddable extends AbstractEmbeddableObject implements SkeletonEmbeddableInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $propertyOne; |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $propertyTwo; |
21
|
|
|
|
22
|
|
|
public function __construct(string $propertyOne, string $propertyTwo) |
23
|
|
|
{ |
24
|
|
|
$this->validate($propertyOne, $propertyTwo); |
25
|
|
|
$this->propertyOne = $propertyOne; |
26
|
|
|
$this->propertyTwo = $propertyTwo; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
private function validate(string $propertyOne, string $propertyTwo): void |
30
|
|
|
{ |
31
|
|
|
$errors = []; |
32
|
|
|
if ('' === $propertyOne) { |
33
|
|
|
$errors[] = 'property one is empty'; |
34
|
|
|
} |
35
|
|
|
if ('' === $propertyTwo) { |
36
|
|
|
$errors[] = 'property two is empty'; |
37
|
|
|
} |
38
|
|
|
if ([] === $errors) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
throw new \InvalidArgumentException('Invalid arguments: ' . print_r($errors, true)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ClassMetadata $metadata |
46
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
47
|
|
|
*/ |
48
|
|
|
public static function loadMetadata(ClassMetadata $metadata): void |
49
|
|
|
{ |
50
|
|
|
$builder = self::setEmbeddableAndGetBuilder($metadata); |
51
|
|
|
MappingHelper::setSimpleFields( |
52
|
|
|
[ |
53
|
|
|
SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE => MappingHelper::TYPE_STRING, |
54
|
|
|
SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_TWO => MappingHelper::TYPE_STRING, |
55
|
|
|
], |
56
|
|
|
$builder |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param array $properties |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public static function create(array $properties): SkeletonEmbeddableInterface |
66
|
|
|
{ |
67
|
|
|
if (array_key_exists(SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE, $properties)) { |
68
|
|
|
return new self( |
69
|
|
|
$properties[SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE], |
70
|
|
|
$properties[SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_TWO] |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return new self(...array_values($properties)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function __toString(): string |
78
|
|
|
{ |
79
|
|
|
return (string)print_r( |
80
|
|
|
[ |
81
|
|
|
'skeletonEmbeddable' => [ |
82
|
|
|
SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE => $this->getPropertyOne(), |
83
|
|
|
SkeletonEmbeddableInterface::EMBEDDED_PROP_PROPERTY_TWO => $this->getPropertyTwo(), |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
true |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getPropertyOne(): string |
94
|
|
|
{ |
95
|
|
|
return $this->propertyOne; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getPropertyTwo(): string |
102
|
|
|
{ |
103
|
|
|
return $this->propertyTwo; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
protected function getPrefix(): string |
107
|
|
|
{ |
108
|
|
|
return HasSkeletonEmbeddableInterface::PROP_SKELETON_EMBEDDABLE; |
109
|
|
|
} |
110
|
|
|
} |