@@ -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; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - return [ $element, $attributes, $switch_context ]; |
|
74 | + return [$element, $attributes, $switch_context]; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | protected function recognizeStringMixed($k, $v) |
100 | 100 | { |
101 | - if (! \is_string($k)) { |
|
101 | + if (!\is_string($k)) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | if (\is_string($v) || $v === null) { |
113 | - if (! FluidHelper::isAnXmlString($v)) { |
|
113 | + if (!FluidHelper::isAnXmlString($v)) { |
|
114 | 114 | return 'insertStringSimple'; |
115 | 115 | } |
116 | 116 | } else { |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | |
210 | 210 | protected function attachNodes($parent, $nodes, $fn) |
211 | 211 | { |
212 | - if (! \is_array($nodes) && ! $nodes instanceof \Traversable) { |
|
213 | - $nodes = [ $nodes ]; |
|
212 | + if (!\is_array($nodes) && !$nodes instanceof \Traversable) { |
|
213 | + $nodes = [$nodes]; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | $context = []; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $el = $this->createElement($k, $v); |
260 | 260 | $el = $fn($parent, $el); |
261 | 261 | |
262 | - return [ $el ]; |
|
262 | + return [$el]; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | protected function insertStringMixed($parent, $k, $v, $fn, &$optionals) |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | // they are supplied, so 'addChild' is the perfect operation. |
277 | 277 | $this->newContext($el)->addChild($v, ...$optionals); |
278 | 278 | |
279 | - return [ $el ]; |
|
279 | + return [$el]; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals) |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $el = $this->createElement($v); |
304 | 304 | $el = $fn($parent, $el); |
305 | 305 | |
306 | - return [ $el ]; |
|
306 | + return [$el]; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | protected function insertIntegerXml($parent, $k, $v, $fn) |
@@ -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())]'; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $xml = ''; |
54 | 54 | |
55 | 55 | foreach ($nodes as $n) { |
56 | - $xml .= static::exportNode($dom, $n, $html) . PHP_EOL; |
|
56 | + $xml .= static::exportNode($dom, $n, $html).PHP_EOL; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | return \rtrim($xml); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $nodes = (new \DOMXPath($dom))->query($query); |
96 | 96 | |
97 | 97 | foreach ($nodes as $n) { |
98 | - if (! \in_array($n->nodeName, $voids)) { |
|
98 | + if (!\in_array($n->nodeName, $voids)) { |
|
99 | 99 | // If it is not a void/empty tag, |
100 | 100 | // we need to leave the tag open. |
101 | 101 | $n->appendChild(new \DOMProcessingInstruction('X-NOT-VOID')); |
@@ -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 |
@@ -38,22 +38,22 @@ |
||
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}FluidAliasesTrait.php"; |
|
43 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidSaveTrait.php"; |
|
44 | -require_once __DIR__ . "{$ds}FluidXml{$ds}NewableTrait.php"; |
|
45 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallStaticTrait.php"; |
|
46 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallTrait.php"; |
|
41 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidInterface.php"; |
|
42 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidAliasesTrait.php"; |
|
43 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidSaveTrait.php"; |
|
44 | +require_once __DIR__ . "{$ds}fluidxml{$ds}NewableTrait.php"; |
|
45 | +require_once __DIR__ . "{$ds}fluidxml{$ds}ReservedCallStaticTrait.php"; |
|
46 | +require_once __DIR__ . "{$ds}fluidxml{$ds}ReservedCallTrait.php"; |
|
47 | 47 | |
48 | 48 | // All. |
49 | -require_once __DIR__ . "{$ds}FluidXml{$ds}CssTranslator.php"; |
|
50 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidContext.php"; |
|
51 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidDocument.php"; |
|
52 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidHelper.php"; |
|
53 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidInsertionHandler.php"; |
|
54 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidNamespace.php"; |
|
55 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidRepeater.php"; |
|
56 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidXml.php"; |
|
49 | +require_once __DIR__ . "{$ds}fluidxml{$ds}CssTranslator.php"; |
|
50 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidContext.php"; |
|
51 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidDocument.php"; |
|
52 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidHelper.php"; |
|
53 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidInsertionHandler.php"; |
|
54 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidNamespace.php"; |
|
55 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidRepeater.php"; |
|
56 | +require_once __DIR__ . "{$ds}fluidxml{$ds}FluidXml.php"; |
|
57 | 57 | |
58 | 58 | // After of all. |
59 | -require_once __DIR__ . "{$ds}FluidXml{$ds}fluid.php"; |
|
59 | +require_once __DIR__ . "{$ds}fluidxml{$ds}fluid.php"; |
@@ -38,22 +38,22 @@ |
||
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}FluidAliasesTrait.php"; |
|
43 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidSaveTrait.php"; |
|
44 | -require_once __DIR__ . "{$ds}FluidXml{$ds}NewableTrait.php"; |
|
45 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallStaticTrait.php"; |
|
46 | -require_once __DIR__ . "{$ds}FluidXml{$ds}ReservedCallTrait.php"; |
|
41 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidInterface.php"; |
|
42 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidAliasesTrait.php"; |
|
43 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidSaveTrait.php"; |
|
44 | +require_once __DIR__."{$ds}FluidXml{$ds}NewableTrait.php"; |
|
45 | +require_once __DIR__."{$ds}FluidXml{$ds}ReservedCallStaticTrait.php"; |
|
46 | +require_once __DIR__."{$ds}FluidXml{$ds}ReservedCallTrait.php"; |
|
47 | 47 | |
48 | 48 | // All. |
49 | -require_once __DIR__ . "{$ds}FluidXml{$ds}CssTranslator.php"; |
|
50 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidContext.php"; |
|
51 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidDocument.php"; |
|
52 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidHelper.php"; |
|
53 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidInsertionHandler.php"; |
|
54 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidNamespace.php"; |
|
55 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidRepeater.php"; |
|
56 | -require_once __DIR__ . "{$ds}FluidXml{$ds}FluidXml.php"; |
|
49 | +require_once __DIR__."{$ds}FluidXml{$ds}CssTranslator.php"; |
|
50 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidContext.php"; |
|
51 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidDocument.php"; |
|
52 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidHelper.php"; |
|
53 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidInsertionHandler.php"; |
|
54 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidNamespace.php"; |
|
55 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidRepeater.php"; |
|
56 | +require_once __DIR__."{$ds}FluidXml{$ds}FluidXml.php"; |
|
57 | 57 | |
58 | 58 | // After of all. |
59 | -require_once __DIR__ . "{$ds}FluidXml{$ds}fluid.php"; |
|
59 | +require_once __DIR__."{$ds}FluidXml{$ds}fluid.php"; |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | trait FluidAliasesTrait |
6 | 6 | { |
7 | - public function size() { return $this->length(); } |
|
8 | - public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | - public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
7 | + public function size() { return $this->length(); } |
|
8 | + public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | + public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
10 | 10 | public function prepend($sibling, ...$optionals) { return $this->prependSibling($sibling, ...$optionals); } |
11 | - public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | - public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | - public function text($text) { return $this->setText($text); } |
|
14 | - public function cdata($text) { return $this->setCdata($text); } |
|
15 | - public function comment($text) { return $this->setComment($text); } |
|
11 | + public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | + public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | + public function text($text) { return $this->setText($text); } |
|
14 | + public function cdata($text) { return $this->setCdata($text); } |
|
15 | + public function comment($text) { return $this->setComment($text); } |
|
16 | 16 | abstract public function length(); |
17 | 17 | abstract public function query(...$query); |
18 | 18 | abstract public function addChild($child, ...$optionals); |
@@ -4,15 +4,33 @@ |
||
4 | 4 | |
5 | 5 | trait FluidAliasesTrait |
6 | 6 | { |
7 | - public function size() { return $this->length(); } |
|
8 | - public function __invoke(...$query) { return $this->query(...$query); } |
|
9 | - public function add($child, ...$optionals) { return $this->addChild($child, ...$optionals); } |
|
10 | - public function prepend($sibling, ...$optionals) { return $this->prependSibling($sibling, ...$optionals); } |
|
11 | - public function append($sibling, ...$optionals) { return $this->appendSibling($sibling, ...$optionals); } |
|
12 | - public function attr($name, $value = null) { return $this->setAttribute($name, $value); } |
|
13 | - public function text($text) { return $this->setText($text); } |
|
14 | - public function cdata($text) { return $this->setCdata($text); } |
|
15 | - public function comment($text) { return $this->setComment($text); } |
|
7 | + public function size() |
|
8 | + { |
|
9 | +return $this->length(); } |
|
10 | + public function __invoke(...$query) |
|
11 | + { |
|
12 | +return $this->query(...$query); } |
|
13 | + public function add($child, ...$optionals) |
|
14 | + { |
|
15 | +return $this->addChild($child, ...$optionals); } |
|
16 | + public function prepend($sibling, ...$optionals) |
|
17 | + { |
|
18 | +return $this->prependSibling($sibling, ...$optionals); } |
|
19 | + public function append($sibling, ...$optionals) |
|
20 | + { |
|
21 | +return $this->appendSibling($sibling, ...$optionals); } |
|
22 | + public function attr($name, $value = null) |
|
23 | + { |
|
24 | +return $this->setAttribute($name, $value); } |
|
25 | + public function text($text) |
|
26 | + { |
|
27 | +return $this->setText($text); } |
|
28 | + public function cdata($text) |
|
29 | + { |
|
30 | +return $this->setCdata($text); } |
|
31 | + public function comment($text) |
|
32 | + { |
|
33 | +return $this->setComment($text); } |
|
16 | 34 | abstract public function length(); |
17 | 35 | abstract public function query(...$query); |
18 | 36 | abstract public function addChild($child, ...$optionals); |
@@ -8,10 +8,10 @@ |
||
8 | 8 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
9 | 9 | { |
10 | 10 | use FluidAliasesTrait, |
11 | - FluidSaveTrait, |
|
12 | - NewableTrait, |
|
13 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
11 | + FluidSaveTrait, |
|
12 | + NewableTrait, |
|
13 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
15 | 15 | |
16 | 16 | private $document; |
17 | 17 | private $handler; |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use FluidAliasesTrait, |
11 | 11 | FluidSaveTrait, |
12 | 12 | NewableTrait, |
13 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
13 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
15 | 15 | |
16 | 16 | private $document; |
17 | 17 | private $handler; |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | $this->document = $document; |
24 | 24 | $this->handler = $handler; |
25 | 25 | |
26 | - if (! \is_array($context) && ! $context instanceof \Traversable) { |
|
26 | + if (!\is_array($context) && !$context instanceof \Traversable) { |
|
27 | 27 | // DOMDocument, DOMElement and DOMNode are not iterable. |
28 | 28 | // DOMNodeList and FluidContext are iterable. |
29 | - $context = [ $context ]; |
|
29 | + $context = [$context]; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | foreach ($context as $n) { |
33 | - if (! $n instanceof \DOMNode) { |
|
33 | + if (!$n instanceof \DOMNode) { |
|
34 | 34 | throw new \Exception('Node type not recognized.'); |
35 | 35 | } |
36 | 36 | |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | // addChild($child, $value?, $attributes? = [], $switchContext? = false) |
200 | 200 | public function addChild($child, ...$optionals) |
201 | 201 | { |
202 | - return $this->handler->insertElement($this->nodes, $child, $optionals, function ($parent, $element) { |
|
202 | + return $this->handler->insertElement($this->nodes, $child, $optionals, function($parent, $element) { |
|
203 | 203 | return $parent->appendChild($element); |
204 | 204 | }, $this); |
205 | 205 | } |
206 | 206 | |
207 | 207 | public function prependSibling($sibling, ...$optionals) |
208 | 208 | { |
209 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
209 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
210 | 210 | if ($sibling->parentNode === null) { |
211 | 211 | // If the node doesn't have at least one parent node, |
212 | 212 | // the sibling creation fails. In this case we replace |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | public function appendSibling($sibling, ...$optionals) |
223 | 223 | { |
224 | - return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) { |
|
224 | + return $this->handler->insertElement($this->nodes, $sibling, $optionals, function($sibling, $element) { |
|
225 | 225 | if ($sibling->parentNode === null) { |
226 | 226 | // If the node doesn't have at least one parent node, |
227 | 227 | // the sibling creation fails. In this case we replace |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | if (\is_array($name)) { |
243 | 243 | $attrs = $name; |
244 | 244 | } else { |
245 | - $attrs = [ $name => $value ]; |
|
245 | + $attrs = [$name => $value]; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | foreach ($this->nodes as $n) { |
@@ -394,10 +394,10 @@ discard block |
||
394 | 394 | |
395 | 395 | protected function resolveQuery($query) |
396 | 396 | { |
397 | - if ( $query === '.' |
|
397 | + if ($query === '.' |
|
398 | 398 | || $query[0] === '/' |
399 | - || ( $query[0] === '.' && $query[1] === '/' ) |
|
400 | - || ( $query[0] === '.' && $query[1] === '.' ) ) { |
|
399 | + || ($query[0] === '.' && $query[1] === '/') |
|
400 | + || ($query[0] === '.' && $query[1] === '.')) { |
|
401 | 401 | return $query; |
402 | 402 | } |
403 | 403 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | $found = ($r === $u) || $found; |
416 | 416 | } |
417 | 417 | |
418 | - if (! $found) { |
|
418 | + if (!$found) { |
|
419 | 419 | $set[] = $r; |
420 | 420 | } |
421 | 421 | } |
@@ -8,17 +8,17 @@ discard block |
||
8 | 8 | class FluidXml implements FluidInterface |
9 | 9 | { |
10 | 10 | use FluidAliasesTrait, |
11 | - FluidSaveTrait, |
|
12 | - NewableTrait, |
|
13 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
11 | + FluidSaveTrait, |
|
12 | + NewableTrait, |
|
13 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
14 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
15 | 15 | |
16 | 16 | const ROOT_NODE = 'doc'; |
17 | 17 | |
18 | 18 | private $defaults = [ 'root' => self::ROOT_NODE, |
19 | - 'version' => '1.0', |
|
20 | - 'encoding' => 'UTF-8', |
|
21 | - 'stylesheet' => null ]; |
|
19 | + 'version' => '1.0', |
|
20 | + 'encoding' => 'UTF-8', |
|
21 | + 'stylesheet' => null ]; |
|
22 | 22 | |
23 | 23 | private $document; |
24 | 24 | 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 mergeOptions(&$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 |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | use FluidAliasesTrait, |
12 | 12 | FluidSaveTrait, |
13 | 13 | NewableTrait, |
14 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
15 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
14 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
15 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
16 | 16 | |
17 | 17 | const ROOT_NODE = 'doc'; |
18 | 18 | |
19 | - private $defaults = [ 'root' => self::ROOT_NODE, |
|
19 | + private $defaults = ['root' => self::ROOT_NODE, |
|
20 | 20 | 'version' => '1.0', |
21 | 21 | 'encoding' => 'UTF-8', |
22 | - 'stylesheet' => null ]; |
|
22 | + 'stylesheet' => null]; |
|
23 | 23 | |
24 | 24 | private $document; |
25 | 25 | private $handler; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $document = \file_get_contents($file); |
33 | 33 | |
34 | 34 | // file_get_contents() returns false in case of error. |
35 | - if (! $document) { |
|
35 | + if (!$document) { |
|
36 | 36 | throw new \Exception("File '$file' not accessible."); |
37 | 37 | } |
38 | 38 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | private function initStylesheet(&$options) |
98 | 98 | { |
99 | - if (! empty($options['stylesheet'])) { |
|
99 | + if (!empty($options['stylesheet'])) { |
|
100 | 100 | $attrs = 'type="text/xsl" ' |
101 | 101 | . "encoding=\"{$options['encoding']}\" " |
102 | 102 | . 'indent="yes" ' |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | private function initRoot(&$options) |
118 | 118 | { |
119 | - if (! empty($options['root'])) { |
|
119 | + if (!empty($options['root'])) { |
|
120 | 120 | $this->appendSibling($options['root']); |
121 | 121 | } |
122 | 122 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $el = $this->document->dom; |
145 | 145 | } |
146 | 146 | |
147 | - return [ $el ]; |
|
147 | + return [$el]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | public function __toString() |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $namespaces = []; |
188 | 188 | |
189 | 189 | if (\is_string($arguments[0])) { |
190 | - $args = [ $arguments[0], $arguments[1] ]; |
|
190 | + $args = [$arguments[0], $arguments[1]]; |
|
191 | 191 | |
192 | 192 | if (isset($arguments[2])) { |
193 | 193 | $args[] = $arguments[2]; |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | return $this; |
207 | 207 | } |
208 | 208 | |
209 | - public function query(...$query) { return $this->context()->query(...$query); } |
|
209 | + public function query(...$query) { return $this->context()->query(...$query); } |
|
210 | 210 | public function times($times, callable $fn = null) { return $this->context()->times($times, $fn); } |
211 | - public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | - public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | - public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
211 | + public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | + public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | + public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
214 | 214 | public function setAttribute($name, $value = null) { $this->context()->setAttribute($name, $value); return $this; } |
215 | - public function setText($text) { $this->context()->setText($text); return $this; } |
|
216 | - public function addText($text) { $this->context()->addText($text); return $this; } |
|
217 | - public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
218 | - public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
219 | - public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
220 | - public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
221 | - public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
215 | + public function setText($text) { $this->context()->setText($text); return $this; } |
|
216 | + public function addText($text) { $this->context()->addText($text); return $this; } |
|
217 | + public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
218 | + public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
219 | + public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
220 | + public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
221 | + public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
222 | 222 | |
223 | 223 | public function addChild($child, ...$optionals) |
224 | 224 | { |
@@ -206,19 +206,45 @@ |
||
206 | 206 | return $this; |
207 | 207 | } |
208 | 208 | |
209 | - public function query(...$query) { return $this->context()->query(...$query); } |
|
210 | - public function times($times, callable $fn = null) { return $this->context()->times($times, $fn); } |
|
211 | - public function each(callable $fn) { return $this->context()->each($fn); } |
|
212 | - public function map(callable $fn) { return $this->context()->map($fn); } |
|
213 | - public function filter(callable $fn) { return $this->context()->filter($fn); } |
|
214 | - public function setAttribute($name, $value = null) { $this->context()->setAttribute($name, $value); return $this; } |
|
215 | - public function setText($text) { $this->context()->setText($text); return $this; } |
|
216 | - public function addText($text) { $this->context()->addText($text); return $this; } |
|
217 | - public function setCdata($text) { $this->context()->setCdata($text); return $this; } |
|
218 | - public function addCdata($text) { $this->context()->addCdata($text); return $this; } |
|
219 | - public function setComment($text) { $this->context()->setComment($text); return $this; } |
|
220 | - public function addComment($text) { $this->context()->addComment($text); return $this; } |
|
221 | - public function remove(...$query) { $this->context()->remove(...$query); return $this; } |
|
209 | + public function query(...$query) |
|
210 | + { |
|
211 | +return $this->context()->query(...$query); } |
|
212 | + public function times($times, callable $fn = null) |
|
213 | + { |
|
214 | +return $this->context()->times($times, $fn); } |
|
215 | + public function each(callable $fn) |
|
216 | + { |
|
217 | +return $this->context()->each($fn); } |
|
218 | + public function map(callable $fn) |
|
219 | + { |
|
220 | +return $this->context()->map($fn); } |
|
221 | + public function filter(callable $fn) |
|
222 | + { |
|
223 | +return $this->context()->filter($fn); } |
|
224 | + public function setAttribute($name, $value = null) |
|
225 | + { |
|
226 | +$this->context()->setAttribute($name, $value); return $this; } |
|
227 | + public function setText($text) |
|
228 | + { |
|
229 | +$this->context()->setText($text); return $this; } |
|
230 | + public function addText($text) |
|
231 | + { |
|
232 | +$this->context()->addText($text); return $this; } |
|
233 | + public function setCdata($text) |
|
234 | + { |
|
235 | +$this->context()->setCdata($text); return $this; } |
|
236 | + public function addCdata($text) |
|
237 | + { |
|
238 | +$this->context()->addCdata($text); return $this; } |
|
239 | + public function setComment($text) |
|
240 | + { |
|
241 | +$this->context()->setComment($text); return $this; } |
|
242 | + public function addComment($text) |
|
243 | + { |
|
244 | +$this->context()->addComment($text); return $this; } |
|
245 | + public function remove(...$query) |
|
246 | + { |
|
247 | +$this->context()->remove(...$query); return $this; } |
|
222 | 248 | |
223 | 249 | public function addChild($child, ...$optionals) |
224 | 250 | { |
@@ -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,83 +38,83 @@ 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 | // *|A |
52 | 52 | [ '\* # Namespace wildcard |
53 | 53 | \| |
54 | 54 | (\w+)', |
55 | - '*[local-name() = \'\1\']', |
|
56 | - 'NS', |
|
57 | - false ], |
|
55 | + '*[local-name() = \'\1\']', |
|
56 | + 'NS', |
|
57 | + false ], |
|
58 | 58 | // :root |
59 | 59 | [ ':root\b', |
60 | - '/*', |
|
61 | - 'TAG', |
|
62 | - false ], |
|
60 | + '/*', |
|
61 | + 'TAG', |
|
62 | + false ], |
|
63 | 63 | // A |
64 | 64 | [ '(?<=^|\s|\}) |
65 | 65 | ( [\w\-]+ | \* )', |
66 | - '\1', |
|
67 | - 'TAG', |
|
68 | - false ], |
|
66 | + '\1', |
|
67 | + 'TAG', |
|
68 | + false ], |
|
69 | 69 | // Aggregates the components of a tag in an expression. |
70 | 70 | [ '({NS\d+})? |
71 | 71 | ({TAG\d+}) |
72 | 72 | ((?:{ATTR\d+})*|) |
73 | 73 | ((?:{ID\d+})*|) |
74 | 74 | ((?:{CLASS\d+})*|)', |
75 | - '\1\2\3\4\5', |
|
76 | - 'EXP', |
|
77 | - false ], |
|
75 | + '\1\2\3\4\5', |
|
76 | + 'EXP', |
|
77 | + false ], |
|
78 | 78 | [ '({EXP\d+}) |
79 | 79 | :first-child', |
80 | - '*[1]/self::\1', |
|
81 | - 'EXP', |
|
82 | - false ], |
|
80 | + '*[1]/self::\1', |
|
81 | + 'EXP', |
|
82 | + false ], |
|
83 | 83 | // {} + {} |
84 | 84 | [ '({EXP\d+}) |
85 | 85 | \s* \+ \s* |
86 | 86 | ({EXP\d+})', |
87 | - '\1/following-sibling::*[1]/self::\2', |
|
88 | - 'EXP', |
|
89 | - true ], |
|
87 | + '\1/following-sibling::*[1]/self::\2', |
|
88 | + 'EXP', |
|
89 | + true ], |
|
90 | 90 | // {} ~ {} |
91 | 91 | [ '({EXP\d+}) |
92 | 92 | \s* \~ \s* |
93 | 93 | ({EXP\d+})', |
94 | - '\1/following-sibling::*/self::\2', |
|
95 | - 'EXP', |
|
96 | - true ], |
|
94 | + '\1/following-sibling::*/self::\2', |
|
95 | + 'EXP', |
|
96 | + true ], |
|
97 | 97 | // {} > {} |
98 | 98 | [ '({EXP\d+}) |
99 | 99 | \s* > \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+ |
107 | 107 | ({EXP\d+})', |
108 | - '\1//\2', |
|
109 | - 'EXP', |
|
110 | - true ], |
|
108 | + '\1//\2', |
|
109 | + 'EXP', |
|
110 | + true ], |
|
111 | 111 | // {}, {} |
112 | 112 | [ '({EXP\d+}) |
113 | 113 | \s* , \s* |
114 | 114 | ({EXP\d+})', |
115 | - '\1|\2', |
|
116 | - 'EXP', |
|
117 | - true ] |
|
115 | + '\1|\2', |
|
116 | + 'EXP', |
|
117 | + true ] |
|
118 | 118 | ]; |
119 | 119 | |
120 | 120 | 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,81 +40,81 @@ 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 | // *|A |
52 | - [ '\* # Namespace wildcard |
|
52 | + ['\* # Namespace wildcard |
|
53 | 53 | \| |
54 | 54 | (\w+)', |
55 | 55 | '*[local-name() = \'\1\']', |
56 | 56 | 'NS', |
57 | - false ], |
|
57 | + false], |
|
58 | 58 | // :root |
59 | - [ ':root\b', |
|
59 | + [':root\b', |
|
60 | 60 | '/*', |
61 | 61 | 'TAG', |
62 | - false ], |
|
62 | + false], |
|
63 | 63 | // A |
64 | - [ '(?<=^|\s|\}) |
|
64 | + ['(?<=^|\s|\}) |
|
65 | 65 | ( [\w\-]+ | \* )', |
66 | 66 | '\1', |
67 | 67 | 'TAG', |
68 | - false ], |
|
68 | + false], |
|
69 | 69 | // Aggregates the components of a tag in an expression. |
70 | - [ '({NS\d+})? |
|
70 | + ['({NS\d+})? |
|
71 | 71 | ({TAG\d+}) |
72 | 72 | ((?:{ATTR\d+})*|) |
73 | 73 | ((?:{ID\d+})*|) |
74 | 74 | ((?:{CLASS\d+})*|)', |
75 | 75 | '\1\2\3\4\5', |
76 | 76 | 'EXP', |
77 | - false ], |
|
78 | - [ '({EXP\d+}) |
|
77 | + false], |
|
78 | + ['({EXP\d+}) |
|
79 | 79 | :first-child', |
80 | 80 | '*[1]/self::\1', |
81 | 81 | 'EXP', |
82 | - false ], |
|
82 | + false], |
|
83 | 83 | // {} + {} |
84 | - [ '({EXP\d+}) |
|
84 | + ['({EXP\d+}) |
|
85 | 85 | \s* \+ \s* |
86 | 86 | ({EXP\d+})', |
87 | 87 | '\1/following-sibling::*[1]/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/following-sibling::*/self::\2', |
95 | 95 | 'EXP', |
96 | - true ], |
|
96 | + true], |
|
97 | 97 | // {} > {} |
98 | - [ '({EXP\d+}) |
|
98 | + ['({EXP\d+}) |
|
99 | 99 | \s* > \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+ |
107 | 107 | ({EXP\d+})', |
108 | 108 | '\1//\2', |
109 | 109 | 'EXP', |
110 | - true ], |
|
110 | + true], |
|
111 | 111 | // {}, {} |
112 | - [ '({EXP\d+}) |
|
112 | + ['({EXP\d+}) |
|
113 | 113 | \s* , \s* |
114 | 114 | ({EXP\d+})', |
115 | 115 | '\1|\2', |
116 | 116 | 'EXP', |
117 | - true ] |
|
117 | + true] |
|
118 | 118 | ]; |
119 | 119 | |
120 | 120 | public static function xpath($css) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $xpath = \trim($xpath); |
141 | 141 | $xpath = ".//$xpath"; |
142 | - $xpath = \str_replace('|', '|.//', $xpath); |
|
142 | + $xpath = \str_replace('|', '|.//', $xpath); |
|
143 | 143 | $xpath = \str_replace('.///', '/', $xpath); |
144 | 144 | |
145 | 145 | return $xpath; |