1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace dlindberg\BlobChunk\Manager; |
6
|
|
|
|
7
|
|
|
final class Manager extends NodeCheck implements CheckNode |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var RowCol |
11
|
|
|
*/ |
12
|
|
|
private $rowCol; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Pairs |
16
|
|
|
*/ |
17
|
|
|
private $pairs; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Pairs|null |
21
|
|
|
*/ |
22
|
|
|
private $currentPair; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var RowCol|null |
26
|
|
|
*/ |
27
|
|
|
private $currentRowCol; |
28
|
|
|
|
29
|
|
|
public function __construct(Config $config) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($config); |
32
|
|
|
$this->rowCol = new RowCol($config); |
33
|
|
|
$this->pairs = new Pairs($config); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getType(\DOMNode $input): string |
37
|
|
|
{ |
38
|
|
|
return $this->nameNodeType($input); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function isParentNode(\DOMNode $input): bool |
42
|
|
|
{ |
43
|
|
|
return $this->test($input, 'parent'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function isSpecialNode(\DOMNode $input): bool |
47
|
|
|
{ |
48
|
|
|
return $this->test($input, 'special'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function isSplitNode(\DOMNode $input): bool |
52
|
|
|
{ |
53
|
|
|
return $this->test($input, 'splitWhat'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getSplitNodeDelimiters(bool $trim = false): array |
57
|
|
|
{ |
58
|
|
|
return $trim ? $this->trimmedDelimiters() : $this->config->splitOn; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function isRecursiveParentNode(\DOMNode $input): bool |
62
|
|
|
{ |
63
|
|
|
return $this->test($input, 'recursionParent'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function isRecursiveChildNode(\DOMNode $input): bool |
67
|
|
|
{ |
68
|
|
|
return $this->test($input, 'recursionChildren'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function isPairParentNode(\DOMNode $input): bool |
72
|
|
|
{ |
73
|
|
|
return $this->test($input, 'pairParents'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setPairParentNode(\DOMNode $input): ?CheckNode |
77
|
|
|
{ |
78
|
|
|
$this->currentPair = $this->isPairParentNode($input) ? $this->pairs->getSet($input) : null; |
79
|
|
|
|
80
|
|
|
return $this->currentPair ? $this : null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function clearPairParentNode(): void |
84
|
|
|
{ |
85
|
|
|
$this->currentPair = null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function isPairSideANode(\DOMNode $input): bool |
89
|
|
|
{ |
90
|
|
|
return $this->currentPair ? $this->testFlat($input, $this->currentPair->sideA) : false; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function isPairSideBNode(\DOMNode $input): bool |
94
|
|
|
{ |
95
|
|
|
return $this->currentPair ? $this->testFlat($input, $this->currentPair->sideB) : false; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function isRowColParentNode(\DOMNode $input): bool |
99
|
|
|
{ |
100
|
|
|
return $this->test($input, 'rowColParent'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function setRowColParentNode(\DOMNode $input): ?CheckNode |
104
|
|
|
{ |
105
|
|
|
$this->currentRowCol = $this->isRowColParentNode($input) ? $this->rowCol->getSet($input) : null; |
106
|
|
|
|
107
|
|
|
return $this->currentRowCol ? $this : null; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function clearRowColParentNode(): void |
111
|
|
|
{ |
112
|
|
|
$this->currentRowCol = null; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function rowColHasHeaders(): bool |
116
|
|
|
{ |
117
|
|
|
return $this->currentRowCol && |
118
|
|
|
\array_key_exists('value', $this->currentRowCol->colDefs) && |
119
|
|
|
\array_key_exists('value', $this->currentRowCol->rowsGroup); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function isRowColHeaderSectionNode(\DOMNode $input): bool |
123
|
|
|
{ |
124
|
|
|
return $this->currentRowCol ? $this->testFlat($input, $this->currentRowCol->colDefs) : false; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function isRowColRowGroupNode(\DOMNode $input): bool |
128
|
|
|
{ |
129
|
|
|
return $this->currentRowCol ? $this->testFlat($input, $this->currentRowCol->rowsGroup) : false; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function isRowColRowNode(\DOMNode $input): bool |
133
|
|
|
{ |
134
|
|
|
return $this->currentRowCol ? $this->testFlat($input, $this->currentRowCol->row) : false; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|