1 | <?php declare(strict_types=1); |
||
15 | abstract class RuleAbstract |
||
16 | { |
||
17 | const NODE_NAME = 'node'; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $nodeName; |
||
23 | |||
24 | /** |
||
25 | * @param string $nodeName |
||
26 | */ |
||
27 | 98 | public function __construct(string $nodeName = null) |
|
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | 59 | public function getNodeName() : string |
|
39 | |||
40 | /** |
||
41 | * @param \DOMElement $element |
||
42 | * @param string $name |
||
43 | * @return string|null |
||
44 | */ |
||
45 | 12 | public function getAttributeValue(\DOMElement $element, $name) : ? string |
|
53 | |||
54 | /** |
||
55 | * @param \DOMElement $element |
||
56 | * @param string $name |
||
57 | * @return string|null |
||
58 | */ |
||
59 | 4 | public function getChildValue(\DOMElement $element, string $name) : ? string |
|
68 | |||
69 | /** |
||
70 | * adds the accurate DomElement content according to the node's property |
||
71 | * |
||
72 | * @param \DomDocument $document |
||
73 | * @param \DOMElement $rootElement |
||
74 | * @param NodeInterface $node |
||
75 | */ |
||
76 | 25 | public function apply(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
82 | |||
83 | /** |
||
84 | * Sets the attribute only if the value is not empty |
||
85 | * @param DomElement $element |
||
86 | * @param string $name |
||
87 | * @param string $value |
||
88 | */ |
||
89 | 3 | protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void |
|
95 | |||
96 | /** |
||
97 | * Appends a child node only if the value is not null |
||
98 | * @param DomDocument $document |
||
99 | * @param DOMElement $element |
||
100 | * @param string $name |
||
101 | * @param string $value |
||
102 | */ |
||
103 | 1 | protected function appendNonEmptyChild(\DomDocument $document, \DOMElement $element, string $name, string $value = null) : void |
|
109 | |||
110 | /** |
||
111 | * Sets the accurate $item property according to the DomElement content |
||
112 | * |
||
113 | * @param NodeInterface $node |
||
114 | * @param \DOMElement $element |
||
115 | */ |
||
116 | abstract public function setProperty(NodeInterface $node, \DOMElement $element) : void; |
||
117 | |||
118 | /** |
||
119 | * Tells if the node contains the expected value |
||
120 | * |
||
121 | * @param NodeInterface $node |
||
122 | * @return bool |
||
123 | */ |
||
124 | abstract protected function hasValue(NodeInterface $node) : bool; |
||
125 | |||
126 | /** |
||
127 | * Creates and adds the element(s) to the document's rootElement |
||
128 | * |
||
129 | * @param \DomDocument $document |
||
130 | * @param \DOMElement $rootElement |
||
131 | * @param NodeInterface $node |
||
132 | */ |
||
133 | abstract protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void; |
||
134 | } |
||
135 |