1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\ElementParser\Properties; |
4
|
|
|
|
5
|
|
|
use UCD\Unicode\Character\Properties\General; |
6
|
|
|
use UCD\Unicode\Character\Properties\General\Block; |
7
|
|
|
use UCD\Unicode\Character\Properties\General\GeneralCategory; |
8
|
|
|
use UCD\Unicode\Character\Properties\General\Name\Assigned; |
9
|
|
|
use UCD\Unicode\Character\Properties\General\Name\Unassigned; |
10
|
|
|
use UCD\Unicode\Character\Properties\General\Names; |
11
|
|
|
use UCD\Unicode\Character\Properties\General\Name; |
12
|
|
|
use UCD\Unicode\Character\Properties\General\Script; |
13
|
|
|
use UCD\Unicode\Character\Properties\General\Version; |
14
|
|
|
|
15
|
|
|
class GeneralParser extends BaseParser |
16
|
|
|
{ |
17
|
|
|
const ATTR_AGE = 'age'; |
18
|
|
|
const ATTR_NAME = 'na'; |
19
|
|
|
const ATTR_NAME_VERSION_1 = 'na1'; |
20
|
|
|
const ATTR_BLOCK = 'blk'; |
21
|
|
|
const ATTR_GENERAL_CATEGORY = 'gc'; |
22
|
|
|
const ATTR_SCRIPT = 'sc'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return General |
26
|
|
|
*/ |
27
|
|
|
protected function parse() |
28
|
|
|
{ |
29
|
|
|
$names = $this->parseNames(); |
30
|
|
|
$block = $this->parseBlock(); |
31
|
|
|
$age = $this->parseAge(); |
32
|
|
|
$generalCategory = $this->parseGeneralCategory(); |
33
|
|
|
$script = $this->parseScript(); |
34
|
|
|
|
35
|
|
|
return new General($names, $block, $age, $generalCategory, $script); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return Names |
40
|
|
|
*/ |
41
|
|
|
private function parseNames() |
42
|
|
|
{ |
43
|
|
|
$primaryName = $this->parsePrimaryName(); |
44
|
|
|
$version1Name = $this->parseVersion1Name(); |
45
|
|
|
|
46
|
|
|
return new Names($primaryName, [], $version1Name); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return Name |
51
|
|
|
*/ |
52
|
|
|
private function parsePrimaryName() |
53
|
|
|
{ |
54
|
|
|
return $this->parseNameWithValue( |
55
|
|
|
$this->getOptionalAttribute(self::ATTR_NAME) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return Name |
61
|
|
|
*/ |
62
|
|
|
private function parseVersion1Name() |
63
|
|
|
{ |
64
|
|
|
return $this->parseNameWithValue( |
65
|
|
|
$this->getOptionalAttribute(self::ATTR_NAME_VERSION_1) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $value |
71
|
|
|
* @return Assigned|Unassigned |
72
|
|
|
*/ |
73
|
|
|
private function parseNameWithValue($value) |
74
|
|
|
{ |
75
|
|
|
$version1NameValue = $this->parsePlaceholders($value, $this->codepoint); |
76
|
|
|
|
77
|
|
|
if ($version1NameValue === null) { |
78
|
|
|
return new Unassigned(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return new Assigned($version1NameValue); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return Block |
86
|
|
|
*/ |
87
|
|
|
private function parseBlock() |
88
|
|
|
{ |
89
|
|
|
return new Block($this->getAttribute(self::ATTR_BLOCK)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Version |
94
|
|
|
*/ |
95
|
|
|
private function parseAge() |
96
|
|
|
{ |
97
|
|
|
return new Version($this->getAttribute(self::ATTR_AGE)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return GeneralCategory |
102
|
|
|
*/ |
103
|
|
|
private function parseGeneralCategory() |
104
|
|
|
{ |
105
|
|
|
return new GeneralCategory($this->getAttribute(self::ATTR_GENERAL_CATEGORY)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return Script |
110
|
|
|
*/ |
111
|
|
|
private function parseScript() |
112
|
|
|
{ |
113
|
|
|
return new Script($this->getAttribute(self::ATTR_SCRIPT)); |
114
|
|
|
} |
115
|
|
|
} |