@@ -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) |
@@ -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())]'; |
@@ -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,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; |
@@ -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 | |
@@ -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 | { |