@@ -33,45 +33,45 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Evaluate and return the result of a given XPath expression using this element as context node |
|
| 37 | - * |
|
| 38 | - * @param string $expr XPath expression |
|
| 39 | - * @return mixed |
|
| 40 | - */ |
|
| 36 | + * Evaluate and return the result of a given XPath expression using this element as context node |
|
| 37 | + * |
|
| 38 | + * @param string $expr XPath expression |
|
| 39 | + * @return mixed |
|
| 40 | + */ |
|
| 41 | 41 | public function evaluate(string $expr) |
| 42 | 42 | { |
| 43 | 43 | return $this->ownerDocument->evaluate($expr, $this); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * Evaluate and return the first element of a given XPath query using this element as context node |
|
| 48 | - * |
|
| 49 | - * @param string $expr XPath expression |
|
| 50 | - * @return DOMNode|null |
|
| 51 | - */ |
|
| 47 | + * Evaluate and return the first element of a given XPath query using this element as context node |
|
| 48 | + * |
|
| 49 | + * @param string $expr XPath expression |
|
| 50 | + * @return DOMNode|null |
|
| 51 | + */ |
|
| 52 | 52 | public function firstOf(string $expr): ?DOMNode |
| 53 | 53 | { |
| 54 | 54 | return $this->ownerDocument->firstOf($expr, $this); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Evaluate and return the result of a given XPath query using this element as context node |
|
| 59 | - * |
|
| 60 | - * @param string $expr XPath expression |
|
| 61 | - * @return DOMNodeList |
|
| 62 | - */ |
|
| 58 | + * Evaluate and return the result of a given XPath query using this element as context node |
|
| 59 | + * |
|
| 60 | + * @param string $expr XPath expression |
|
| 61 | + * @return DOMNodeList |
|
| 62 | + */ |
|
| 63 | 63 | public function query(string $expr): DOMNodeList |
| 64 | 64 | { |
| 65 | 65 | return $this->ownerDocument->query($expr, $this); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | - * Insert given element relative to this element's position |
|
| 70 | - * |
|
| 71 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 72 | - * @param self $element |
|
| 73 | - * @return self |
|
| 74 | - */ |
|
| 69 | + * Insert given element relative to this element's position |
|
| 70 | + * |
|
| 71 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 72 | + * @param self $element |
|
| 73 | + * @return self |
|
| 74 | + */ |
|
| 75 | 75 | public function insertAdjacentElement(string $where, self $element): self |
| 76 | 76 | { |
| 77 | 77 | $this->insertAdjacentNode($where, $element); |
@@ -80,24 +80,24 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * Insert given text relative to this element's position |
|
| 84 | - * |
|
| 85 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 86 | - * @param string $text |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 83 | + * Insert given text relative to this element's position |
|
| 84 | + * |
|
| 85 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 86 | + * @param string $text |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | 89 | public function insertAdjacentText(string $where, string $text): void |
| 90 | 90 | { |
| 91 | 91 | $this->insertAdjacentXML($where, htmlspecialchars($text, ENT_XML1)); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * Insert given XML relative to this element's position |
|
| 96 | - * |
|
| 97 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 98 | - * @param string $xml |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 95 | + * Insert given XML relative to this element's position |
|
| 96 | + * |
|
| 97 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 98 | + * @param string $xml |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | 101 | public function insertAdjacentXML(string $where, string $xml): void |
| 102 | 102 | { |
| 103 | 103 | $fragment = $this->ownerDocument->createDocumentFragment(); |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | - * Remove this element from the document |
|
| 111 | - * |
|
| 112 | - * @return self This element |
|
| 113 | - */ |
|
| 110 | + * Remove this element from the document |
|
| 111 | + * |
|
| 112 | + * @return self This element |
|
| 113 | + */ |
|
| 114 | 114 | public function remove(): self |
| 115 | 115 | { |
| 116 | 116 | return $this->parentNode->removeChild($this); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * Replace this element with given element |
|
| 121 | - * |
|
| 122 | - * @param self $element Replacement element |
|
| 123 | - * @return self This element |
|
| 124 | - */ |
|
| 120 | + * Replace this element with given element |
|
| 121 | + * |
|
| 122 | + * @param self $element Replacement element |
|
| 123 | + * @return self This element |
|
| 124 | + */ |
|
| 125 | 125 | public function replace(self $element): self |
| 126 | 126 | { |
| 127 | 127 | return $this->parentNode->replaceChild($element, $this); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Add namespace declarations that may be missing in given XML |
|
| 132 | - * |
|
| 133 | - * @param string $xml Original XML |
|
| 134 | - * @return string Modified XML |
|
| 135 | - */ |
|
| 131 | + * Add namespace declarations that may be missing in given XML |
|
| 132 | + * |
|
| 133 | + * @param string $xml Original XML |
|
| 134 | + * @return string Modified XML |
|
| 135 | + */ |
|
| 136 | 136 | protected function addMissingNamespaceDeclarations(string $xml): string |
| 137 | 137 | { |
| 138 | 138 | preg_match_all('(xmlns:\\K[-\\w]++(?==))', $xml, $m); |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | - * Insert given node relative to this element's position |
|
| 165 | - * |
|
| 166 | - * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 167 | - * @param DOMNode $node |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 164 | + * Insert given node relative to this element's position |
|
| 165 | + * |
|
| 166 | + * @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' |
|
| 167 | + * @param DOMNode $node |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | 170 | protected function insertAdjacentNode(string $where, DOMNode $node): void |
| 171 | 171 | { |
| 172 | 172 | if ($where === 'beforebegin') |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | class Document extends DOMDocument |
| 16 | 16 | { |
| 17 | 17 | /** |
| 18 | - * @link https://www.php.net/manual/domdocument.construct.php |
|
| 19 | - * |
|
| 20 | - * @param string $version Version number of the document |
|
| 21 | - * @param string $encoding Encoding of the document |
|
| 22 | - */ |
|
| 18 | + * @link https://www.php.net/manual/domdocument.construct.php |
|
| 19 | + * |
|
| 20 | + * @param string $version Version number of the document |
|
| 21 | + * @param string $encoding Encoding of the document |
|
| 22 | + */ |
|
| 23 | 23 | public function __construct(string $version = '1.0', string $encoding = 'utf-8') |
| 24 | 24 | { |
| 25 | 25 | parent::__construct($version, $encoding); |
@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Create and return an xsl:apply-templates element |
|
| 32 | - * |
|
| 33 | - * @param string $select XPath expression for the "select" attribute |
|
| 34 | - * @return Element |
|
| 35 | - */ |
|
| 31 | + * Create and return an xsl:apply-templates element |
|
| 32 | + * |
|
| 33 | + * @param string $select XPath expression for the "select" attribute |
|
| 34 | + * @return Element |
|
| 35 | + */ |
|
| 36 | 36 | public function createXslApplyTemplates(string $select = null): Element |
| 37 | 37 | { |
| 38 | 38 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:apply-templates'); |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Create and return an xsl:attribute element |
|
| 49 | - * |
|
| 50 | - * @param string $name Attribute's name |
|
| 51 | - * @param string $namespace Attribute's namespace URI |
|
| 52 | - * @return Element |
|
| 53 | - */ |
|
| 48 | + * Create and return an xsl:attribute element |
|
| 49 | + * |
|
| 50 | + * @param string $name Attribute's name |
|
| 51 | + * @param string $namespace Attribute's namespace URI |
|
| 52 | + * @return Element |
|
| 53 | + */ |
|
| 54 | 54 | public function createXslAttribute(string $name, string $namespace = null): Element |
| 55 | 55 | { |
| 56 | 56 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:attribute'); |
@@ -64,32 +64,32 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * Create and return an xsl:choose element |
|
| 68 | - * |
|
| 69 | - * @return Element |
|
| 70 | - */ |
|
| 67 | + * Create and return an xsl:choose element |
|
| 68 | + * |
|
| 69 | + * @return Element |
|
| 70 | + */ |
|
| 71 | 71 | public function createXslChoose(): Element |
| 72 | 72 | { |
| 73 | 73 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:choose'); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Create and return an xsl:comment element |
|
| 78 | - * |
|
| 79 | - * @param string $text Text content for the comment |
|
| 80 | - * @return Element |
|
| 81 | - */ |
|
| 77 | + * Create and return an xsl:comment element |
|
| 78 | + * |
|
| 79 | + * @param string $text Text content for the comment |
|
| 80 | + * @return Element |
|
| 81 | + */ |
|
| 82 | 82 | public function createXslComment(string $text = ''): Element |
| 83 | 83 | { |
| 84 | 84 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:comment', htmlspecialchars($text, ENT_XML1)); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Create and return an xsl:copy-of element |
|
| 89 | - * |
|
| 90 | - * @param string $select XPath expression for the "select" attribute |
|
| 91 | - * @return Element |
|
| 92 | - */ |
|
| 88 | + * Create and return an xsl:copy-of element |
|
| 89 | + * |
|
| 90 | + * @param string $select XPath expression for the "select" attribute |
|
| 91 | + * @return Element |
|
| 92 | + */ |
|
| 93 | 93 | public function createXslCopyOf(string $select): Element |
| 94 | 94 | { |
| 95 | 95 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:copy-of'); |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | - * Create and return an xsl:if element |
|
| 103 | - * |
|
| 104 | - * @param string $test XPath expression for the "test" attribute |
|
| 105 | - * @return Element |
|
| 106 | - */ |
|
| 102 | + * Create and return an xsl:if element |
|
| 103 | + * |
|
| 104 | + * @param string $test XPath expression for the "test" attribute |
|
| 105 | + * @return Element |
|
| 106 | + */ |
|
| 107 | 107 | public function createXslIf(string $test): Element |
| 108 | 108 | { |
| 109 | 109 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:if'); |
@@ -113,32 +113,32 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Create and return an xsl:otherwise element |
|
| 117 | - * |
|
| 118 | - * @return Element |
|
| 119 | - */ |
|
| 116 | + * Create and return an xsl:otherwise element |
|
| 117 | + * |
|
| 118 | + * @return Element |
|
| 119 | + */ |
|
| 120 | 120 | public function createXslOtherwise(): Element |
| 121 | 121 | { |
| 122 | 122 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:otherwise'); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | - * Create and return an xsl:text element |
|
| 127 | - * |
|
| 128 | - * @param string $text Text content for the element |
|
| 129 | - * @return Element |
|
| 130 | - */ |
|
| 126 | + * Create and return an xsl:text element |
|
| 127 | + * |
|
| 128 | + * @param string $text Text content for the element |
|
| 129 | + * @return Element |
|
| 130 | + */ |
|
| 131 | 131 | public function createXslText(string $text = ''): Element |
| 132 | 132 | { |
| 133 | 133 | return $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:text', htmlspecialchars($text, ENT_XML1)); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Create and return an xsl:value-of element |
|
| 138 | - * |
|
| 139 | - * @param string $select XPath expression for the "select" attribute |
|
| 140 | - * @return Element |
|
| 141 | - */ |
|
| 137 | + * Create and return an xsl:value-of element |
|
| 138 | + * |
|
| 139 | + * @param string $select XPath expression for the "select" attribute |
|
| 140 | + * @return Element |
|
| 141 | + */ |
|
| 142 | 142 | public function createXslValueOf(string $select): Element |
| 143 | 143 | { |
| 144 | 144 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:value-of'); |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | - * Create and return an xsl:variable element |
|
| 152 | - * |
|
| 153 | - * @param string $name Name of the variable |
|
| 154 | - * @param string $select XPath expression |
|
| 155 | - * @return Element |
|
| 156 | - */ |
|
| 151 | + * Create and return an xsl:variable element |
|
| 152 | + * |
|
| 153 | + * @param string $name Name of the variable |
|
| 154 | + * @param string $select XPath expression |
|
| 155 | + * @return Element |
|
| 156 | + */ |
|
| 157 | 157 | public function createXslVariable(string $name, string $select = null): Element |
| 158 | 158 | { |
| 159 | 159 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:variable'); |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * Create and return an xsl:when element |
|
| 171 | - * |
|
| 172 | - * @param string $test XPath expression for the "test" attribute |
|
| 173 | - * @return Element |
|
| 174 | - */ |
|
| 170 | + * Create and return an xsl:when element |
|
| 171 | + * |
|
| 172 | + * @param string $test XPath expression for the "test" attribute |
|
| 173 | + * @return Element |
|
| 174 | + */ |
|
| 175 | 175 | public function createXslWhen(string $test): Element |
| 176 | 176 | { |
| 177 | 177 | $element = $this->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:when'); |
@@ -181,39 +181,39 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | - * Evaluate and return the result of a given XPath expression |
|
| 185 | - * |
|
| 186 | - * @param string $expr XPath expression |
|
| 187 | - * @param DOMNode $node Context node |
|
| 188 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 189 | - * @return mixed |
|
| 190 | - */ |
|
| 184 | + * Evaluate and return the result of a given XPath expression |
|
| 185 | + * |
|
| 186 | + * @param string $expr XPath expression |
|
| 187 | + * @param DOMNode $node Context node |
|
| 188 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 189 | + * @return mixed |
|
| 190 | + */ |
|
| 191 | 191 | public function evaluate(string $expr, DOMNode $node = null, bool $registerNodeNS = true) |
| 192 | 192 | { |
| 193 | 193 | return call_user_func_array([$this->xpath(), 'evaluate'], func_get_args()); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | - * Evaluate and return the first element of a given XPath query |
|
| 198 | - * |
|
| 199 | - * @param string $expr XPath expression |
|
| 200 | - * @param DOMNode $node Context node |
|
| 201 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 202 | - * @return DOMNode|null |
|
| 203 | - */ |
|
| 197 | + * Evaluate and return the first element of a given XPath query |
|
| 198 | + * |
|
| 199 | + * @param string $expr XPath expression |
|
| 200 | + * @param DOMNode $node Context node |
|
| 201 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 202 | + * @return DOMNode|null |
|
| 203 | + */ |
|
| 204 | 204 | public function firstOf(string $expr, DOMNode $node = null, bool $registerNodeNS = true): ?DOMNode |
| 205 | 205 | { |
| 206 | 206 | return call_user_func_array([$this, 'query'], func_get_args())->item(0); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | - * Evaluate and return the result of a given XPath query |
|
| 211 | - * |
|
| 212 | - * @param string $expr XPath expression |
|
| 213 | - * @param DOMNode $node Context node |
|
| 214 | - * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 215 | - * @return DOMNodeList |
|
| 216 | - */ |
|
| 210 | + * Evaluate and return the result of a given XPath query |
|
| 211 | + * |
|
| 212 | + * @param string $expr XPath expression |
|
| 213 | + * @param DOMNode $node Context node |
|
| 214 | + * @param bool $registerNodeNS Whether to register the node's namespace |
|
| 215 | + * @return DOMNodeList |
|
| 216 | + */ |
|
| 217 | 217 | public function query(string $expr, DOMNode $node = null, bool $registerNodeNS = true): DOMNodeList |
| 218 | 218 | { |
| 219 | 219 | return call_user_func_array([$this->xpath(), 'query'], func_get_args()); |