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