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