1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace As3\Modlr\Metadata; |
4
|
|
|
|
5
|
|
|
use As3\Modlr\Exception\MetadataException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Defines the metadata for an embed. |
9
|
|
|
* Should be loaded using the MetadataFactory, not instantiated directly. |
10
|
|
|
* |
11
|
|
|
* @author Jacob Bare <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class EmbedMetadata implements Interfaces\AttributeInterface, Interfaces\EmbedInterface, Interfaces\MixinInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Uses attributes. |
17
|
|
|
*/ |
18
|
|
|
use Traits\AttributesTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Uses embeds. |
22
|
|
|
*/ |
23
|
|
|
use Traits\EmbedsTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Uses mixins. |
27
|
|
|
*/ |
28
|
|
|
use Traits\MixinsTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Uses merged properties. |
32
|
|
|
*/ |
33
|
|
|
use Traits\PropertiesTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The embed name/key. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
public $name; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor. |
44
|
|
|
* |
45
|
|
|
* @param string $name The embed name. |
46
|
|
|
*/ |
47
|
|
|
public function __construct($name) |
48
|
|
|
{ |
49
|
|
|
$this->name = $name; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getProperties() |
56
|
|
|
{ |
57
|
|
|
return array_merge($this->getAttributes(), $this->getEmbeds()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
protected function applyMixinProperties(MixinMetadata $mixin) |
64
|
|
|
{ |
65
|
|
|
foreach ($mixin->getAttributes() as $attribute) { |
66
|
|
|
if (true === $this->hasAttribute($attribute->key)) { |
67
|
|
|
throw MetadataException::mixinPropertyExists($this->name, $mixin->name, 'attribute', $attribute->key); |
68
|
|
|
} |
69
|
|
|
$this->addAttribute($attribute); |
70
|
|
|
} |
71
|
|
|
foreach ($mixin->getEmbeds() as $embed) { |
72
|
|
|
if (true === $this->hasEmbed($embed->key)) { |
73
|
|
|
throw MetadataException::mixinPropertyExists($this->name, $mixin->name, 'embed', $embed->key); |
74
|
|
|
} |
75
|
|
|
$this->addEmbed($embed); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
protected function validateAttribute(AttributeMetadata $attribute) |
83
|
|
|
{ |
84
|
|
|
if (true === $this->hasEmbed($attribute->getKey())) { |
85
|
|
|
throw MetadataException::fieldKeyInUse('attribute', 'embed', $attribute->getKey(), $this->name); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
protected function validateEmbed(EmbeddedPropMetadata $embed) |
93
|
|
|
{ |
94
|
|
|
if (true === $this->hasAttribute($embed->getKey())) { |
95
|
|
|
throw MetadataException::fieldKeyInUse('embed', 'attribute', $embed->getKey(), $this->name); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|