|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace As3\Modlr\Metadata; |
|
4
|
|
|
|
|
5
|
|
|
use As3\Modlr\Exception\MetadataException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Defines metadata for an embedded field. |
|
9
|
|
|
* Should be loaded using the MetadataFactory, not instantiated directly. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Jacob Bare <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class EmbeddedPropMetadata extends FieldMetadata |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The embedded metadata for this embedded property. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
public $embedMeta; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The embed type: one or many |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
public $embedType; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $key |
|
33
|
|
|
* @param string $embedType |
|
34
|
|
|
* @param EmbedMetadata $embedMeta |
|
35
|
|
|
* @param bool $mixin |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($key, $embedType, EmbedMetadata $embedMeta, $mixin = false) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->embedMeta = $embedMeta; |
|
|
|
|
|
|
40
|
|
|
$this->setEmbedType($embedType); |
|
41
|
|
|
parent::__construct($key, $mixin); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Determines if this is a one (single) embed. |
|
46
|
|
|
* |
|
47
|
|
|
* @return bool |
|
48
|
|
|
*/ |
|
49
|
|
|
public function isOne() |
|
50
|
|
|
{ |
|
51
|
|
|
return 'one' === $this->embedType; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Determines if this is a many embed. |
|
56
|
|
|
* |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function isMany() |
|
60
|
|
|
{ |
|
61
|
|
|
return 'many' === $this->embedType; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets the embed type: one or many. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $relType |
|
|
|
|
|
|
68
|
|
|
* @return self |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setEmbedType($embedType) |
|
71
|
|
|
{ |
|
72
|
|
|
$embedType = strtolower($embedType); |
|
73
|
|
|
$this->validateType($embedType); |
|
74
|
|
|
$this->embedType = $embedType; |
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Validates the embed type. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $type |
|
|
|
|
|
|
82
|
|
|
* @return bool |
|
83
|
|
|
* @throws MetadataException |
|
84
|
|
|
*/ |
|
85
|
|
View Code Duplication |
protected function validateType($embedType) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
$valid = ['one', 'many']; |
|
88
|
|
|
if (!in_array($embedType, $valid)) { |
|
89
|
|
|
throw MetadataException::invalidRelType($embedType, $valid); |
|
90
|
|
|
} |
|
91
|
|
|
return true; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..