1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\xsdTypes\Facets\LengthTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* type xsd:QName represents an XML namespace-qualified name. A xsd:QName value consists |
9
|
|
|
* of a prefix and a local part, separated by a colon, both of which are NCName values. The prefix and colon are |
10
|
|
|
* optional, but if they are not present, it is assumed that either the name is namespace-qualified by other means |
11
|
|
|
* (e.g., by a default namespace declaration), or the name is not in a namespace. |
12
|
|
|
* @package AlgoWeb\xsdTypesThe |
13
|
|
|
*/ |
14
|
|
|
class xsQName extends xsAnySimpleType |
15
|
|
|
{ |
16
|
|
|
use LengthTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Construct. |
20
|
|
|
* |
21
|
|
|
* @param string $value |
22
|
|
|
*/ |
23
|
|
|
public function __construct($value) |
24
|
|
|
{ |
25
|
|
|
parent::__construct($value); |
26
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function isOK() |
30
|
|
|
{ |
31
|
|
|
$this->checkLength($this->value); |
32
|
|
|
if (':' == $this->value[0]) { |
33
|
|
|
throw new \InvalidArgumentException('QName cannot start with colon'); |
34
|
|
|
} |
35
|
|
|
$this->checkColen(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private function checkColen() |
39
|
|
|
{ |
40
|
|
|
$bitz = explode(':', $this->value); |
41
|
|
|
if (2 < count($bitz)) { |
42
|
|
|
throw new \InvalidArgumentException('QName cannot contain two or more colons'); |
43
|
|
|
} |
44
|
|
|
$this->checkParts($bitz); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function checkParts($bitz) |
48
|
|
|
{ |
49
|
|
|
foreach ($bitz as $bit) { |
50
|
|
|
$ncName = new xsNCName($bit); |
51
|
|
|
$ncNameStr = $ncName->__toString(); |
52
|
|
|
if ($bit != $ncNameStr) { |
53
|
|
|
throw new \InvalidArgumentException($bit . ' is not a valid NCName so can not be part ofa QName'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|