1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\XML\XSDReader\Schema\Inheritance; |
3
|
|
|
|
4
|
|
|
use DOMElement; |
5
|
|
|
use GoetasWebservices\XML\XSDReader\Schema\Type\Type; |
6
|
|
|
use GoetasWebservices\XML\XSDReader\SchemaReader; |
7
|
|
|
|
8
|
|
|
class Restriction extends Base |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var mixed[][] |
12
|
|
|
*/ |
13
|
|
|
protected $checks = array(); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param string $type |
17
|
|
|
* @param mixed[] $value |
18
|
|
|
* |
19
|
|
|
* @return $this |
20
|
|
|
*/ |
21
|
135 |
|
public function addCheck($type, $value) |
22
|
|
|
{ |
23
|
135 |
|
$this->checks[$type][] = $value; |
24
|
135 |
|
return $this; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return mixed[][] |
29
|
|
|
*/ |
30
|
30 |
|
public function getChecks() |
31
|
|
|
{ |
32
|
30 |
|
return $this->checks; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $type |
37
|
|
|
* |
38
|
|
|
* @return mixed[] |
39
|
|
|
*/ |
40
|
|
|
public function getChecksByType($type) |
41
|
|
|
{ |
42
|
|
|
return isset($this->checks[$type])?$this->checks[$type]:array(); |
43
|
|
|
} |
44
|
|
|
|
45
|
135 |
|
public static function loadRestriction( |
46
|
|
|
SchemaReader $reader, |
47
|
|
|
Type $type, |
48
|
|
|
DOMElement $node |
49
|
|
|
) { |
50
|
135 |
|
$restriction = new Restriction(); |
51
|
135 |
|
$type->setRestriction($restriction); |
52
|
135 |
|
if ($node->hasAttribute("base")) { |
53
|
135 |
|
$reader->findAndSetSomeBase($type, $restriction, $node); |
54
|
45 |
|
} else { |
55
|
135 |
|
$addCallback = function (Type $restType) use ($restriction) { |
56
|
135 |
|
$restriction->setBase($restType); |
57
|
135 |
|
}; |
58
|
|
|
|
59
|
135 |
|
Type::loadTypeWithCallbackOnChildNodes( |
60
|
135 |
|
$reader, |
61
|
135 |
|
$type->getSchema(), |
62
|
135 |
|
$node, |
63
|
90 |
|
$addCallback |
64
|
45 |
|
); |
65
|
|
|
} |
66
|
135 |
|
foreach ($node->childNodes as $childNode) { |
67
|
135 |
|
if ($childNode instanceof DOMElement) { |
68
|
135 |
|
static::maybeLoadRestrictionOnChildNode( |
69
|
135 |
|
$restriction, |
70
|
90 |
|
$childNode |
71
|
45 |
|
); |
72
|
45 |
|
} |
73
|
45 |
|
} |
74
|
135 |
|
} |
75
|
|
|
|
76
|
135 |
|
protected static function maybeLoadRestrictionOnChildNode( |
77
|
|
|
Restriction $restriction, |
78
|
|
|
DOMElement $childNode |
79
|
|
|
) { |
80
|
|
|
if ( |
81
|
135 |
|
in_array( |
82
|
135 |
|
$childNode->localName, |
83
|
|
|
[ |
84
|
135 |
|
'enumeration', |
85
|
45 |
|
'pattern', |
86
|
45 |
|
'length', |
87
|
45 |
|
'minLength', |
88
|
45 |
|
'maxLength', |
89
|
45 |
|
'minInclusive', |
90
|
45 |
|
'maxInclusive', |
91
|
45 |
|
'minExclusive', |
92
|
45 |
|
'maxExclusive', |
93
|
45 |
|
'fractionDigits', |
94
|
45 |
|
'totalDigits', |
95
|
|
|
'whiteSpace' |
96
|
45 |
|
], |
97
|
90 |
|
true |
98
|
45 |
|
) |
99
|
45 |
|
) { |
100
|
135 |
|
static::definitelyLoadRestrictionOnChildNode( |
101
|
135 |
|
$restriction, |
102
|
90 |
|
$childNode |
103
|
45 |
|
); |
104
|
45 |
|
} |
105
|
135 |
|
} |
106
|
|
|
|
107
|
135 |
|
protected static function definitelyLoadRestrictionOnChildNode( |
108
|
|
|
Restriction $restriction, |
109
|
|
|
DOMElement $childNode |
110
|
|
|
) { |
111
|
135 |
|
$restriction->addCheck( |
112
|
135 |
|
$childNode->localName, |
113
|
|
|
[ |
114
|
135 |
|
'value' => $childNode->getAttribute("value"), |
115
|
135 |
|
'doc' => SchemaReader::getDocumentation($childNode) |
116
|
45 |
|
] |
117
|
45 |
|
); |
118
|
135 |
|
} |
119
|
|
|
} |
120
|
|
|
|