@@ -479,6 +479,9 @@ |
||
479 | 479 | return $set; |
480 | 480 | } |
481 | 481 | |
482 | + /** |
|
483 | + * @param callable $fn |
|
484 | + */ |
|
482 | 485 | protected function callfn($fn, $args) |
483 | 486 | { |
484 | 487 | if ($fn instanceof \Closure) { |
@@ -8,9 +8,9 @@ |
||
8 | 8 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
9 | 9 | { |
10 | 10 | use NewableTrait, |
11 | - FluidSaveTrait, |
|
12 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
11 | + FluidSaveTrait, |
|
12 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | 14 | |
15 | 15 | private $document; |
16 | 16 | private $handler; |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | { |
10 | 10 | use NewableTrait, |
11 | 11 | FluidSaveTrait, |
12 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
12 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | 14 | |
15 | 15 | private $document; |
16 | 16 | private $handler; |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | $this->document = $document; |
23 | 23 | $this->handler = $handler; |
24 | 24 | |
25 | - if (! \is_array($context) && ! $context instanceof \Traversable) { |
|
25 | + if (!\is_array($context) && !$context instanceof \Traversable) { |
|
26 | 26 | // DOMDocument, DOMElement and DOMNode are not iterable. |
27 | 27 | // DOMNodeList and FluidContext are iterable. |
28 | - $context = [ $context ]; |
|
28 | + $context = [$context]; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | foreach ($context as $n) { |
32 | - if (! $n instanceof \DOMNode) { |
|
32 | + if (!$n instanceof \DOMNode) { |
|
33 | 33 | throw new \Exception('Node type not recognized.'); |
34 | 34 | } |
35 | 35 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | // addChild($child, $value?, $attributes? = [], $switchContext? = false) |
205 | 205 | public function addChild($child, ...$optionals) |
206 | 206 | { |
207 | - return $this->handler->insertElement($this->nodes, $child, $optionals, function ($parent, $element) { |
|
207 | + return $this->handler->insertElement($this->nodes, $child, $optionals, function($parent, $element) { |
|
208 | 208 | return $parent->appendChild($element); |
209 | 209 | }, $this); |
210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | public function prependSibling($sibling, ...$optionals) |
219 | 219 | { |
220 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
220 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
221 | 221 | return $sibling->parentNode->insertBefore($element, $sibling); |
222 | 222 | }, $this); |
223 | 223 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | public function appendSibling($sibling, ...$optionals) |
238 | 238 | { |
239 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
239 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
240 | 240 | // If ->nextSibling is null, $element is simply appended as last sibling. |
241 | 241 | return $sibling->parentNode->insertBefore($element, $sibling->nextSibling); |
242 | 242 | }, $this); |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | // the user has passed two arguments: |
262 | 262 | // 1. is the attribute name |
263 | 263 | // 2. is the attribute value |
264 | - if (! \is_array($arguments[0])) { |
|
265 | - $val = isset($arguments[1]) ? $arguments[1]: ''; |
|
264 | + if (!\is_array($arguments[0])) { |
|
265 | + $val = isset($arguments[1]) ? $arguments[1] : ''; |
|
266 | 266 | $attrs = [$arguments[0] => $val]; |
267 | 267 | } |
268 | 268 | |
@@ -444,13 +444,13 @@ discard block |
||
444 | 444 | $is_dot = $query === '.'; |
445 | 445 | $matched = $matched || $is_dot; |
446 | 446 | |
447 | - $slash = ! $matched && $query[0] === '/'; |
|
447 | + $slash = !$matched && $query[0] === '/'; |
|
448 | 448 | $matched = $matched || $slash; |
449 | 449 | |
450 | - $dotslash = ! $matched && $query[0] === '.' && $query[1] === '/'; |
|
450 | + $dotslash = !$matched && $query[0] === '.' && $query[1] === '/'; |
|
451 | 451 | $matched = $matched || $dotslash; |
452 | 452 | |
453 | - $dotdot = ! $matched && $query[0] === '.' && $query[1] === '.'; |
|
453 | + $dotdot = !$matched && $query[0] === '.' && $query[1] === '.'; |
|
454 | 454 | $matched = $matched || $dotdot; |
455 | 455 | |
456 | 456 | if ($is_dot || $slash || $dotslash || $dotdot) { |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $found = ($r === $u) || $found; |
472 | 472 | } |
473 | 473 | |
474 | - if (! $found) { |
|
474 | + if (!$found) { |
|
475 | 475 | $set[] = $r; |
476 | 476 | } |
477 | 477 | } |
@@ -4,6 +4,9 @@ discard block |
||
4 | 4 | |
5 | 5 | class FluidHelper |
6 | 6 | { |
7 | + /** |
|
8 | + * @param string $string |
|
9 | + */ |
|
7 | 10 | public static function isAnXmlString($string) |
8 | 11 | { |
9 | 12 | // Removes any empty new line at the beginning, |
@@ -69,6 +72,9 @@ discard block |
||
69 | 72 | return static::exportNode($dom->ownerDocument, $dom, $html); |
70 | 73 | } |
71 | 74 | |
75 | + /** |
|
76 | + * @param \DOMDocument $dom |
|
77 | + */ |
|
72 | 78 | public static function domdocumentToHtml($dom, $clone = true) |
73 | 79 | { |
74 | 80 | if ($clone) { |
@@ -76,22 +76,22 @@ |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | $voids = ['area', |
79 | - 'base', |
|
80 | - 'br', |
|
81 | - 'col', |
|
82 | - 'colgroup', |
|
83 | - 'command', |
|
84 | - 'embed', |
|
85 | - 'hr', |
|
86 | - 'img', |
|
87 | - 'input', |
|
88 | - 'keygen', |
|
89 | - 'link', |
|
90 | - 'meta', |
|
91 | - 'param', |
|
92 | - 'source', |
|
93 | - 'track', |
|
94 | - 'wbr']; |
|
79 | + 'base', |
|
80 | + 'br', |
|
81 | + 'col', |
|
82 | + 'colgroup', |
|
83 | + 'command', |
|
84 | + 'embed', |
|
85 | + 'hr', |
|
86 | + 'img', |
|
87 | + 'input', |
|
88 | + 'keygen', |
|
89 | + 'link', |
|
90 | + 'meta', |
|
91 | + 'param', |
|
92 | + 'source', |
|
93 | + 'track', |
|
94 | + 'wbr']; |
|
95 | 95 | |
96 | 96 | // Every empty node. There is no reason to match nodes with content inside. |
97 | 97 | $query = '//*[not(node())]'; |
@@ -98,7 +98,7 @@ |
||
98 | 98 | $nodes = (new \DOMXPath($dom))->query($query); |
99 | 99 | |
100 | 100 | foreach ($nodes as $n) { |
101 | - if (! \in_array($n->nodeName, $voids)) { |
|
101 | + if (!\in_array($n->nodeName, $voids)) { |
|
102 | 102 | // If it is not a void/empty tag, |
103 | 103 | // we need to leave the tag open. |
104 | 104 | $n->appendChild(new \DOMProcessingInstruction('X-NOT-VOID')); |
@@ -8,6 +8,9 @@ |
||
8 | 8 | private $dom; |
9 | 9 | private $namespaces; |
10 | 10 | |
11 | + /** |
|
12 | + * @param FluidDocument $document |
|
13 | + */ |
|
11 | 14 | public function __construct($document) |
12 | 15 | { |
13 | 16 | $this->document = $document; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | { |
13 | 13 | $this->document = $document; |
14 | 14 | $this->dom = $document->dom; |
15 | - $this->namespaces =& $document->namespaces; |
|
15 | + $this->namespaces = & $document->namespaces; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function insertElement(&$nodes, $element, &$optionals, $fn, $orig_context) |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | // offers to the user and is the same of: |
35 | 35 | // 1. appending a child switching the context |
36 | 36 | // 2. setting the attributes over the new context. |
37 | - if (! empty($attributes)) { |
|
37 | + if (!empty($attributes)) { |
|
38 | 38 | $new_context->setAttribute($attributes); |
39 | 39 | } |
40 | 40 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | protected function handleOptionals($element, &$optionals) |
50 | 50 | { |
51 | - if (! \is_array($element)) { |
|
52 | - $element = [ $element ]; |
|
51 | + if (!\is_array($element)) { |
|
52 | + $element = [$element]; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | $switch_context = false; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - return [ $element, $attributes, $switch_context ]; |
|
75 | + return [$element, $attributes, $switch_context]; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | |
@@ -85,34 +85,34 @@ discard block |
||
85 | 85 | // is prefered to collapse many identical checks to one. |
86 | 86 | |
87 | 87 | $k_is_string = \is_string($k); |
88 | - $k_is_integer = ! $k_is_string && \is_integer($k); |
|
88 | + $k_is_integer = !$k_is_string && \is_integer($k); |
|
89 | 89 | $k_is_special = $k_is_string && $k[0] === '@'; |
90 | 90 | $k_is_special_cont = $k_is_special && $k === '@'; |
91 | - $k_is_special_attr = $k_is_special && ! $k_is_special_cont; |
|
91 | + $k_is_special_attr = $k_is_special && !$k_is_special_cont; |
|
92 | 92 | |
93 | 93 | $v_is_string = \is_string($v); |
94 | 94 | $v_is_xml = $v_is_string && FluidHelper::isAnXmlString($v); |
95 | 95 | $v_is_simple = $v_is_string || \is_numeric($v); |
96 | - $v_is_array = ! $v_is_simple && \is_array($v); |
|
96 | + $v_is_array = !$v_is_simple && \is_array($v); |
|
97 | 97 | $v_matches = $v_is_string || $v_is_xml || $v_is_simple || $v_is_array; |
98 | - $v_is_domdoc = ! $v_matches && $v instanceof \DOMDocument; |
|
98 | + $v_is_domdoc = !$v_matches && $v instanceof \DOMDocument; |
|
99 | 99 | $v_matches = $v_matches || $v_is_domdoc; |
100 | - $v_is_domnodelist = ! $v_matches && $v instanceof \DOMNodeList; |
|
100 | + $v_is_domnodelist = !$v_matches && $v instanceof \DOMNodeList; |
|
101 | 101 | $v_matches = $v_matches || $v_is_domnodelist; |
102 | - $v_is_domnode = ! $v_matches && $v instanceof \DOMNode; |
|
102 | + $v_is_domnode = !$v_matches && $v instanceof \DOMNode; |
|
103 | 103 | $v_matches = $v_matches || $v_is_domnode; |
104 | - $v_is_simplexml = ! $v_matches && $v instanceof \SimpleXMLElement; |
|
104 | + $v_is_simplexml = !$v_matches && $v instanceof \SimpleXMLElement; |
|
105 | 105 | $v_matches = $v_matches || $v_is_simplexml; |
106 | - $v_is_fluidxml = ! $v_matches && $v instanceof FluidXml; |
|
106 | + $v_is_fluidxml = !$v_matches && $v instanceof FluidXml; |
|
107 | 107 | $v_matches = $v_matches || $v_is_fluidxml; |
108 | - $v_is_fluidcx = ! $v_matches && $v instanceof FluidContext; |
|
108 | + $v_is_fluidcx = !$v_matches && $v instanceof FluidContext; |
|
109 | 109 | $v_matches = $v_matches || $v_is_fluidcx; |
110 | 110 | |
111 | - $map = ['insertStringSimple' => $k_is_string && ! $k_is_special && $v_is_simple && ! $v_is_xml, |
|
111 | + $map = ['insertStringSimple' => $k_is_string && !$k_is_special && $v_is_simple && !$v_is_xml, |
|
112 | 112 | 'insertSpecialContent' => $k_is_special_cont && $v_is_simple, |
113 | 113 | 'insertSpecialAttribute' => $k_is_special_attr && $v_is_simple, |
114 | - 'insertStringMixed' => $k_is_string && ! $v_is_string, |
|
115 | - 'insertIntegerString' => $k_is_integer && $v_is_string && ! $v_is_xml, |
|
114 | + 'insertStringMixed' => $k_is_string && !$v_is_string, |
|
115 | + 'insertIntegerString' => $k_is_integer && $v_is_string && !$v_is_xml, |
|
116 | 116 | 'insertIntegerXml' => $k_is_integer && $v_is_string && $v_is_xml, |
117 | 117 | 'insertIntegerArray' => $k_is_integer && $v_is_array, |
118 | 118 | 'insertIntegerDomdocument' => $v_is_domdoc, |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | |
171 | 171 | protected function attachNodes($parent, $nodes, $fn) |
172 | 172 | { |
173 | - if (! \is_array($nodes) && ! $nodes instanceof \Traversable) { |
|
174 | - $nodes = [ $nodes ]; |
|
173 | + if (!\is_array($nodes) && !$nodes instanceof \Traversable) { |
|
174 | + $nodes = [$nodes]; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | $context = []; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $el = $this->createElement($k, $v); |
221 | 221 | $el = $fn($parent, $el); |
222 | 222 | |
223 | - return [ $el ]; |
|
223 | + return [$el]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | protected function insertStringMixed($parent, $k, $v, $fn, &$optionals) |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | // they are supplied, so 'addChild' is the perfect operation. |
237 | 237 | $this->newContext($el)->addChild($v, ...$optionals); |
238 | 238 | |
239 | - return [ $el ]; |
|
239 | + return [$el]; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals) |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $el = $this->createElement($v); |
264 | 264 | $el = $fn($parent, $el); |
265 | 265 | |
266 | - return [ $el ]; |
|
266 | + return [$el]; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | protected function insertIntegerXml($parent, $k, $v, $fn) |
@@ -59,10 +59,10 @@ |
||
59 | 59 | if (\is_array($opt)) { |
60 | 60 | $attributes = $opt; |
61 | 61 | |
62 | - } elseif (\is_bool($opt)) { |
|
62 | + } elseif (\is_bool($opt)) { |
|
63 | 63 | $switch_context = $opt; |
64 | 64 | |
65 | - } elseif (\is_string($opt)) { |
|
65 | + } elseif (\is_string($opt)) { |
|
66 | 66 | $e = \array_pop($element); |
67 | 67 | |
68 | 68 | $element[$e] = $opt; |
@@ -38,21 +38,21 @@ |
||
38 | 38 | $ds = \DIRECTORY_SEPARATOR; |
39 | 39 | |
40 | 40 | // First of all. |
41 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidInterface.php"; |
|
42 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidSaveTrait.php"; |
|
43 | -require_once __DIR__ . "{$ds}FluidXml{$ds}NewableTrait.php"; |
|
44 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallStaticTrait.php"; |
|
45 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallTrait.php"; |
|
41 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidInterface.php"; |
|
42 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidSaveTrait.php"; |
|
43 | +require_once __DIR__ . "{$ds}fluidxml{$ds}NewableTrait.php"; |
|
44 | +require_once __DIR__ . "{$ds}fluidxml{$ds}ReservedCallStaticTrait.php"; |
|
45 | +require_once __DIR__ . "{$ds}fluidxml{$ds}ReservedCallTrait.php"; |
|
46 | 46 | |
47 | 47 | // All. |
48 | -require_once __DIR__ . "{$ds}FluidXml{$ds}CssTranslator.php"; |
|
49 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidContext.php"; |
|
50 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidDocument.php"; |
|
51 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidHelper.php"; |
|
52 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidInsertionHandler.php"; |
|
53 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidNamespace.php"; |
|
54 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidRepeater.php"; |
|
55 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidXml.php"; |
|
48 | +require_once __DIR__ . "{$ds}fluidxml{$ds}CssTranslator.php"; |
|
49 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidContext.php"; |
|
50 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidDocument.php"; |
|
51 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidHelper.php"; |
|
52 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidInsertionHandler.php"; |
|
53 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidNamespace.php"; |
|
54 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidRepeater.php"; |
|
55 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidXml.php"; |
|
56 | 56 | |
57 | 57 | // After of all. |
58 | -require_once __DIR__ . "{$ds}FluidXml{$ds}fluid.php"; |
|
58 | +require_once __DIR__ . "{$ds}fluidxml{$ds}fluid.php"; |
@@ -9,28 +9,28 @@ discard block |
||
9 | 9 | // Empty part of #id and .class |
10 | 10 | [ '(?<=^|\s) # The begining or an empty space. |
11 | 11 | (?=[.#\[]) # . | # | [', |
12 | - '*', |
|
13 | - 'TAG', |
|
14 | - false ], |
|
12 | + '*', |
|
13 | + 'TAG', |
|
14 | + false ], |
|
15 | 15 | // #id |
16 | 16 | [ '\# |
17 | 17 | ([\w\-]+)', |
18 | - '[@id="\1"]', |
|
19 | - 'ID', |
|
20 | - false ], |
|
18 | + '[@id="\1"]', |
|
19 | + 'ID', |
|
20 | + false ], |
|
21 | 21 | // .class |
22 | 22 | [ '\. |
23 | 23 | ([\w\-]+)', |
24 | - '[ contains( concat(" ", normalize-space(@class), " "), concat(" ", "\1", " ") ) ]', |
|
25 | - 'CLASS', |
|
26 | - false ], |
|
24 | + '[ contains( concat(" ", normalize-space(@class), " "), concat(" ", "\1", " ") ) ]', |
|
25 | + 'CLASS', |
|
26 | + false ], |
|
27 | 27 | // [attr] |
28 | 28 | [ '\[ |
29 | 29 | ([\w\-]+) |
30 | 30 | \]', |
31 | - '[@\1]', |
|
32 | - 'ATTR', |
|
33 | - false ], |
|
31 | + '[@\1]', |
|
32 | + 'ATTR', |
|
33 | + false ], |
|
34 | 34 | // [attr="val"] |
35 | 35 | [ '\[ |
36 | 36 | ([\w\-]+) |
@@ -38,76 +38,76 @@ discard block |
||
38 | 38 | (.*) |
39 | 39 | ["\'] |
40 | 40 | \]', |
41 | - '[@\1="\2"]', |
|
42 | - 'ATTR', |
|
43 | - false ], |
|
41 | + '[@\1="\2"]', |
|
42 | + 'ATTR', |
|
43 | + false ], |
|
44 | 44 | // ns|A |
45 | 45 | [ '([\w\-]+) |
46 | 46 | \| |
47 | 47 | (?=\w) # A namespace must be followed at least by a character.', |
48 | - '\1:', |
|
49 | - 'NS', |
|
50 | - false ], |
|
48 | + '\1:', |
|
49 | + 'NS', |
|
50 | + false ], |
|
51 | 51 | // :root |
52 | 52 | [ ':root\b', |
53 | - '/*', |
|
54 | - 'TAG', |
|
55 | - false ], |
|
53 | + '/*', |
|
54 | + 'TAG', |
|
55 | + false ], |
|
56 | 56 | // A |
57 | 57 | [ '(?<=^|\s|\}) |
58 | 58 | ( [\w\-]+ | \* )', |
59 | - '\1', |
|
60 | - 'TAG', |
|
61 | - false ], |
|
59 | + '\1', |
|
60 | + 'TAG', |
|
61 | + false ], |
|
62 | 62 | // Aggregates the components of a tag in an expression. |
63 | 63 | [ '({NS\d+})? |
64 | 64 | ({TAG\d+}) |
65 | 65 | ((?:{ATTR\d+})*|) |
66 | 66 | ((?:{ID\d+})*|) |
67 | 67 | ((?:{CLASS\d+})*|)', |
68 | - '\1\2\3\4\5', |
|
69 | - 'EXP', |
|
70 | - false ], |
|
68 | + '\1\2\3\4\5', |
|
69 | + 'EXP', |
|
70 | + false ], |
|
71 | 71 | [ '({EXP\d+}) |
72 | 72 | :first-child', |
73 | - '*[1]/self::\1', |
|
74 | - 'EXP', |
|
75 | - false ], |
|
73 | + '*[1]/self::\1', |
|
74 | + 'EXP', |
|
75 | + false ], |
|
76 | 76 | // {} + {} |
77 | 77 | [ '({EXP\d+}) |
78 | 78 | \s* \+ \s* |
79 | 79 | ({EXP\d+})', |
80 | - '\1/following-sibling::*[1]/self::\2', |
|
81 | - 'EXP', |
|
82 | - true ], |
|
80 | + '\1/following-sibling::*[1]/self::\2', |
|
81 | + 'EXP', |
|
82 | + true ], |
|
83 | 83 | // {} ~ {} |
84 | 84 | [ '({EXP\d+}) |
85 | 85 | \s* \~ \s* |
86 | 86 | ({EXP\d+})', |
87 | - '\1/following-sibling::*/self::\2', |
|
88 | - 'EXP', |
|
89 | - true ], |
|
87 | + '\1/following-sibling::*/self::\2', |
|
88 | + 'EXP', |
|
89 | + true ], |
|
90 | 90 | // {} > {} |
91 | 91 | [ '({EXP\d+}) |
92 | 92 | \s* > \s* |
93 | 93 | ({EXP\d+})', |
94 | - '\1/\2', |
|
95 | - 'EXP', |
|
96 | - true ], |
|
94 | + '\1/\2', |
|
95 | + 'EXP', |
|
96 | + true ], |
|
97 | 97 | // {} {} |
98 | 98 | [ '({EXP\d+}) |
99 | 99 | \s+ |
100 | 100 | ({EXP\d+})', |
101 | - '\1//\2', |
|
102 | - 'EXP', |
|
103 | - true ], |
|
101 | + '\1//\2', |
|
102 | + 'EXP', |
|
103 | + true ], |
|
104 | 104 | // {}, {} |
105 | 105 | [ '({EXP\d+}) |
106 | 106 | \s* , \s* |
107 | 107 | ({EXP\d+})', |
108 | - '\1|\2', |
|
109 | - 'EXP', |
|
110 | - true ] |
|
108 | + '\1|\2', |
|
109 | + 'EXP', |
|
110 | + true ] |
|
111 | 111 | ]; |
112 | 112 | |
113 | 113 | public static function xpath($css) |
@@ -7,32 +7,32 @@ discard block |
||
7 | 7 | const TOKEN = '/{([[:alpha:]]+)(\d+)}/i'; |
8 | 8 | const MAP = [ |
9 | 9 | // Empty part of #id and .class |
10 | - [ '(?<=^|\s) # The begining or an empty space. |
|
10 | + ['(?<=^|\s) # The begining or an empty space. |
|
11 | 11 | (?=[.#\[]) # . | # | [', |
12 | 12 | '*', |
13 | 13 | 'TAG', |
14 | - false ], |
|
14 | + false], |
|
15 | 15 | // #id |
16 | - [ '\# |
|
16 | + ['\# |
|
17 | 17 | ([\w\-]+)', |
18 | 18 | '[@id="\1"]', |
19 | 19 | 'ID', |
20 | - false ], |
|
20 | + false], |
|
21 | 21 | // .class |
22 | - [ '\. |
|
22 | + ['\. |
|
23 | 23 | ([\w\-]+)', |
24 | 24 | '[ contains( concat(" ", normalize-space(@class), " "), concat(" ", "\1", " ") ) ]', |
25 | 25 | 'CLASS', |
26 | - false ], |
|
26 | + false], |
|
27 | 27 | // [attr] |
28 | - [ '\[ |
|
28 | + ['\[ |
|
29 | 29 | ([\w\-]+) |
30 | 30 | \]', |
31 | 31 | '[@\1]', |
32 | 32 | 'ATTR', |
33 | - false ], |
|
33 | + false], |
|
34 | 34 | // [attr="val"] |
35 | - [ '\[ |
|
35 | + ['\[ |
|
36 | 36 | ([\w\-]+) |
37 | 37 | =["\'] |
38 | 38 | (.*) |
@@ -40,74 +40,74 @@ discard block |
||
40 | 40 | \]', |
41 | 41 | '[@\1="\2"]', |
42 | 42 | 'ATTR', |
43 | - false ], |
|
43 | + false], |
|
44 | 44 | // ns|A |
45 | - [ '([\w\-]+) |
|
45 | + ['([\w\-]+) |
|
46 | 46 | \| |
47 | 47 | (?=\w) # A namespace must be followed at least by a character.', |
48 | 48 | '\1:', |
49 | 49 | 'NS', |
50 | - false ], |
|
50 | + false], |
|
51 | 51 | // :root |
52 | - [ ':root\b', |
|
52 | + [':root\b', |
|
53 | 53 | '/*', |
54 | 54 | 'TAG', |
55 | - false ], |
|
55 | + false], |
|
56 | 56 | // A |
57 | - [ '(?<=^|\s|\}) |
|
57 | + ['(?<=^|\s|\}) |
|
58 | 58 | ( [\w\-]+ | \* )', |
59 | 59 | '\1', |
60 | 60 | 'TAG', |
61 | - false ], |
|
61 | + false], |
|
62 | 62 | // Aggregates the components of a tag in an expression. |
63 | - [ '({NS\d+})? |
|
63 | + ['({NS\d+})? |
|
64 | 64 | ({TAG\d+}) |
65 | 65 | ((?:{ATTR\d+})*|) |
66 | 66 | ((?:{ID\d+})*|) |
67 | 67 | ((?:{CLASS\d+})*|)', |
68 | 68 | '\1\2\3\4\5', |
69 | 69 | 'EXP', |
70 | - false ], |
|
71 | - [ '({EXP\d+}) |
|
70 | + false], |
|
71 | + ['({EXP\d+}) |
|
72 | 72 | :first-child', |
73 | 73 | '*[1]/self::\1', |
74 | 74 | 'EXP', |
75 | - false ], |
|
75 | + false], |
|
76 | 76 | // {} + {} |
77 | - [ '({EXP\d+}) |
|
77 | + ['({EXP\d+}) |
|
78 | 78 | \s* \+ \s* |
79 | 79 | ({EXP\d+})', |
80 | 80 | '\1/following-sibling::*[1]/self::\2', |
81 | 81 | 'EXP', |
82 | - true ], |
|
82 | + true], |
|
83 | 83 | // {} ~ {} |
84 | - [ '({EXP\d+}) |
|
84 | + ['({EXP\d+}) |
|
85 | 85 | \s* \~ \s* |
86 | 86 | ({EXP\d+})', |
87 | 87 | '\1/following-sibling::*/self::\2', |
88 | 88 | 'EXP', |
89 | - true ], |
|
89 | + true], |
|
90 | 90 | // {} > {} |
91 | - [ '({EXP\d+}) |
|
91 | + ['({EXP\d+}) |
|
92 | 92 | \s* > \s* |
93 | 93 | ({EXP\d+})', |
94 | 94 | '\1/\2', |
95 | 95 | 'EXP', |
96 | - true ], |
|
96 | + true], |
|
97 | 97 | // {} {} |
98 | - [ '({EXP\d+}) |
|
98 | + ['({EXP\d+}) |
|
99 | 99 | \s+ |
100 | 100 | ({EXP\d+})', |
101 | 101 | '\1//\2', |
102 | 102 | 'EXP', |
103 | - true ], |
|
103 | + true], |
|
104 | 104 | // {}, {} |
105 | - [ '({EXP\d+}) |
|
105 | + ['({EXP\d+}) |
|
106 | 106 | \s* , \s* |
107 | 107 | ({EXP\d+})', |
108 | 108 | '\1|\2', |
109 | 109 | 'EXP', |
110 | - true ] |
|
110 | + true] |
|
111 | 111 | ]; |
112 | 112 | |
113 | 113 | public static function xpath($css) |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $xpath = \trim($xpath); |
134 | 134 | $xpath = ".//$xpath"; |
135 | - $xpath = \str_replace('|', '|.//', $xpath); |
|
135 | + $xpath = \str_replace('|', '|.//', $xpath); |
|
136 | 136 | $xpath = \str_replace('.///', '/', $xpath); |
137 | 137 | |
138 | 138 | return $xpath; |
@@ -12,8 +12,8 @@ |
||
12 | 12 | const MODE_EXPLICIT = 1; |
13 | 13 | |
14 | 14 | private $config = [ self::ID => '', |
15 | - self::URI => '', |
|
16 | - self::MODE => self::MODE_EXPLICIT ]; |
|
15 | + self::URI => '', |
|
16 | + self::MODE => self::MODE_EXPLICIT ]; |
|
17 | 17 | |
18 | 18 | public function __construct($id, $uri, $mode = 1) |
19 | 19 | { |
@@ -4,16 +4,16 @@ discard block |
||
4 | 4 | |
5 | 5 | class FluidNamespace |
6 | 6 | { |
7 | - const ID = 'id' ; |
|
8 | - const URI = 'uri' ; |
|
7 | + const ID = 'id'; |
|
8 | + const URI = 'uri'; |
|
9 | 9 | const MODE = 'mode'; |
10 | 10 | |
11 | 11 | const MODE_IMPLICIT = 0; |
12 | 12 | const MODE_EXPLICIT = 1; |
13 | 13 | |
14 | - private $config = [ self::ID => '', |
|
14 | + private $config = [self::ID => '', |
|
15 | 15 | self::URI => '', |
16 | - self::MODE => self::MODE_EXPLICIT ]; |
|
16 | + self::MODE => self::MODE_EXPLICIT]; |
|
17 | 17 | |
18 | 18 | public function __construct($id, $uri, $mode = 1) |
19 | 19 | { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $id = $this->id(); |
53 | 53 | |
54 | - if (! empty($id)) { |
|
54 | + if (!empty($id)) { |
|
55 | 55 | $id .= ':'; |
56 | 56 | } |
57 | 57 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $nodes = \explode('/', $xpath); |
63 | 63 | |
64 | 64 | foreach ($nodes as $node) { |
65 | - if (! empty($node)) { |
|
65 | + if (!empty($node)) { |
|
66 | 66 | // An XPath query can have multiple slashes. |
67 | 67 | // Example: //target |
68 | 68 | $new_xpath .= "{$id}{$node}"; |
@@ -8,7 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | $status = \file_put_contents($file, $this->xml($strip)); |
10 | 10 | |
11 | - if (! $status) { |
|
11 | + if (!$status) { |
|
12 | 12 | throw new \Exception("The file '$file' is not writable."); |
13 | 13 | } |
14 | 14 |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | class FluidXml implements FluidInterface |
9 | 9 | { |
10 | 10 | use NewableTrait, |
11 | - FluidSaveTrait, |
|
12 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
11 | + FluidSaveTrait, |
|
12 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | 14 | |
15 | 15 | const ROOT_NODE = 'doc'; |
16 | 16 | |
17 | 17 | private $defaults = [ 'root' => self::ROOT_NODE, |
18 | - 'version' => '1.0', |
|
19 | - 'encoding' => 'UTF-8', |
|
20 | - 'stylesheet' => null ]; |
|
18 | + 'version' => '1.0', |
|
19 | + 'encoding' => 'UTF-8', |
|
20 | + 'stylesheet' => null ]; |
|
21 | 21 | |
22 | 22 | private $document; |
23 | 23 | private $handler; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | // Now, we can further populate the DOM with any stylesheet or child. |
64 | 64 | $this->initStylesheet($options) |
65 | - ->initRoot($options); |
|
65 | + ->initRoot($options); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | protected function buildOptions(&$arguments) |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | { |
98 | 98 | if (! empty($options['stylesheet'])) { |
99 | 99 | $attrs = 'type="text/xsl" ' |
100 | - . "encoding=\"{$options['encoding']}\" " |
|
101 | - . 'indent="yes" ' |
|
102 | - . "href=\"{$options['stylesheet']}\""; |
|
100 | + . "encoding=\"{$options['encoding']}\" " |
|
101 | + . 'indent="yes" ' |
|
102 | + . "href=\"{$options['stylesheet']}\""; |
|
103 | 103 | |
104 | 104 | $stylesheet = new \DOMProcessingInstruction('xml-stylesheet', $attrs); |
105 | 105 |
@@ -9,15 +9,15 @@ discard block |
||
9 | 9 | { |
10 | 10 | use NewableTrait, |
11 | 11 | FluidSaveTrait, |
12 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
12 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
13 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | 14 | |
15 | 15 | const ROOT_NODE = 'doc'; |
16 | 16 | |
17 | - private $defaults = [ 'root' => self::ROOT_NODE, |
|
17 | + private $defaults = ['root' => self::ROOT_NODE, |
|
18 | 18 | 'version' => '1.0', |
19 | 19 | 'encoding' => 'UTF-8', |
20 | - 'stylesheet' => null ]; |
|
20 | + 'stylesheet' => null]; |
|
21 | 21 | |
22 | 22 | private $document; |
23 | 23 | private $handler; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $document = \file_get_contents($file); |
32 | 32 | |
33 | 33 | // file_get_contents() returns false in case of error. |
34 | - if (! $document) { |
|
34 | + if (!$document) { |
|
35 | 35 | throw new \Exception("File '$file' not accessible."); |
36 | 36 | } |
37 | 37 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | private function initStylesheet(&$options) |
97 | 97 | { |
98 | - if (! empty($options['stylesheet'])) { |
|
98 | + if (!empty($options['stylesheet'])) { |
|
99 | 99 | $attrs = 'type="text/xsl" ' |
100 | 100 | . "encoding=\"{$options['encoding']}\" " |
101 | 101 | . 'indent="yes" ' |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | private function initRoot(&$options) |
117 | 117 | { |
118 | - if (! empty($options['root'])) { |
|
118 | + if (!empty($options['root'])) { |
|
119 | 119 | $this->appendSibling($options['root']); |
120 | 120 | } |
121 | 121 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | // it is shadowed by the __call() method. |
144 | 144 | public function array_() |
145 | 145 | { |
146 | - return [ $this->document->dom ]; |
|
146 | + return [$this->document->dom]; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | public function __toString() |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $namespaces = []; |
187 | 187 | |
188 | 188 | if (\is_string($arguments[0])) { |
189 | - $args = [ $arguments[0], $arguments[1] ]; |
|
189 | + $args = [$arguments[0], $arguments[1]]; |
|
190 | 190 | |
191 | 191 | if (isset($arguments[2])) { |
192 | 192 | $args[] = $arguments[2]; |
@@ -193,7 +193,7 @@ |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | $namespaces[] = new FluidNamespace(...$args); |
196 | - } elseif (\is_array($arguments[0])) { |
|
196 | + } elseif (\is_array($arguments[0])) { |
|
197 | 197 | $namespaces = $arguments[0]; |
198 | 198 | } else { |
199 | 199 | $namespaces = $arguments; |