@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param array $arguments Options that influence the construction of the XML document. |
| 71 | 71 | * |
| 72 | - * @return FluidXml A new FluidXml instance. |
|
| 72 | + * @return FluidContext A new FluidXml instance. |
|
| 73 | 73 | */ |
| 74 | 74 | function fluidify(...$arguments) |
| 75 | 75 | { |
@@ -86,6 +86,9 @@ discard block |
||
| 86 | 86 | return new FluidNamespace(...$arguments); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | +/** |
|
| 90 | + * @param string $string |
|
| 91 | + */ |
|
| 89 | 92 | function is_an_xml_string($string) |
| 90 | 93 | { |
| 91 | 94 | // Removes any empty new line at the beginning, |
@@ -536,7 +539,7 @@ discard block |
||
| 536 | 539 | * $xml->query("/doc")->query("book[@id='123']"); |
| 537 | 540 | * ``` |
| 538 | 541 | * |
| 539 | - * @param string $xpath The XPath to execute. |
|
| 542 | + * @param string[] $xpath The XPath to execute. |
|
| 540 | 543 | * |
| 541 | 544 | * @return FluidContext The context associated to the DOMNodeList. |
| 542 | 545 | */ |
@@ -558,9 +561,6 @@ discard block |
||
| 558 | 561 | * ``` |
| 559 | 562 | * |
| 560 | 563 | * @param string|array $child The child/children to add. |
| 561 | - * @param string $value The child text content. |
|
| 562 | - * @param bool $switchContext Whether to return the current context |
|
| 563 | - * or the context of the created node. |
|
| 564 | 564 | * |
| 565 | 565 | * @return FluidContext The context associated to the DOMNodeList. |
| 566 | 566 | */ |
@@ -575,6 +575,10 @@ discard block |
||
| 575 | 575 | public function remove(...$xpath); |
| 576 | 576 | public function xml($strip = false); |
| 577 | 577 | // Aliases: |
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * @return FluidContext |
|
| 581 | + */ |
|
| 578 | 582 | public function add($child, ...$optionals); |
| 579 | 583 | public function prepend($sibling, ...$optionals); |
| 580 | 584 | public function insertSiblingBefore($sibling, ...$optionals); |
@@ -636,6 +640,9 @@ discard block |
||
| 636 | 640 | private $context; |
| 637 | 641 | private $times; |
| 638 | 642 | |
| 643 | + /** |
|
| 644 | + * @param FluidContext $context |
|
| 645 | + */ |
|
| 639 | 646 | public function __construct($document, $context, $times) |
| 640 | 647 | { |
| 641 | 648 | $this->document = $document; |
@@ -1072,6 +1079,9 @@ discard block |
||
| 1072 | 1079 | return [ $element, $attributes, $switch_context ]; |
| 1073 | 1080 | } |
| 1074 | 1081 | |
| 1082 | + /** |
|
| 1083 | + * @param \Closure $fn |
|
| 1084 | + */ |
|
| 1075 | 1085 | protected function insertElement($element, &$optionals, $fn) |
| 1076 | 1086 | { |
| 1077 | 1087 | list($element, $attributes, $switch_context) = $this->handleOptionals($element, $optionals); |
@@ -1277,6 +1287,10 @@ discard block |
||
| 1277 | 1287 | return $context; |
| 1278 | 1288 | } |
| 1279 | 1289 | |
| 1290 | + /** |
|
| 1291 | + * @param string $k |
|
| 1292 | + * @param string $v |
|
| 1293 | + */ |
|
| 1280 | 1294 | protected function insertSpecialContent($parent, $k, $v) |
| 1281 | 1295 | { |
| 1282 | 1296 | // The user has passed an element text content: |
@@ -1294,6 +1308,10 @@ discard block |
||
| 1294 | 1308 | return []; |
| 1295 | 1309 | } |
| 1296 | 1310 | |
| 1311 | + /** |
|
| 1312 | + * @param string $k |
|
| 1313 | + * @param string $v |
|
| 1314 | + */ |
|
| 1297 | 1315 | protected function insertSpecialAttribute($parent, $k, $v) |
| 1298 | 1316 | { |
| 1299 | 1317 | // The user has passed an attribute name and an attribute value: |
@@ -1305,6 +1323,10 @@ discard block |
||
| 1305 | 1323 | return []; |
| 1306 | 1324 | } |
| 1307 | 1325 | |
| 1326 | + /** |
|
| 1327 | + * @param string $k |
|
| 1328 | + * @param string $v |
|
| 1329 | + */ |
|
| 1308 | 1330 | protected function insertStringString($parent, $k, $v, $fn) |
| 1309 | 1331 | { |
| 1310 | 1332 | // The user has passed an element name and an element value: |
@@ -1316,6 +1338,9 @@ discard block |
||
| 1316 | 1338 | return [ $el ]; |
| 1317 | 1339 | } |
| 1318 | 1340 | |
| 1341 | + /** |
|
| 1342 | + * @param string $k |
|
| 1343 | + */ |
|
| 1319 | 1344 | protected function insertStringMixed($parent, $k, $v, $fn, &$optionals) |
| 1320 | 1345 | { |
| 1321 | 1346 | // The user has passed one of these two cases: |
@@ -1332,6 +1357,9 @@ discard block |
||
| 1332 | 1357 | return [ $el ]; |
| 1333 | 1358 | } |
| 1334 | 1359 | |
| 1360 | + /** |
|
| 1361 | + * @param integer $k |
|
| 1362 | + */ |
|
| 1335 | 1363 | protected function insertIntegerArray($parent, $k, $v, $fn, &$optionals) |
| 1336 | 1364 | { |
| 1337 | 1365 | // The user has passed a wrapper array: |
@@ -1348,6 +1376,10 @@ discard block |
||
| 1348 | 1376 | return $context; |
| 1349 | 1377 | } |
| 1350 | 1378 | |
| 1379 | + /** |
|
| 1380 | + * @param integer $k |
|
| 1381 | + * @param string $v |
|
| 1382 | + */ |
|
| 1351 | 1383 | protected function insertIntegerString($parent, $k, $v, $fn) |
| 1352 | 1384 | { |
| 1353 | 1385 | // The user has passed a node name without a node value: |
@@ -1359,6 +1391,10 @@ discard block |
||
| 1359 | 1391 | return [ $el ]; |
| 1360 | 1392 | } |
| 1361 | 1393 | |
| 1394 | + /** |
|
| 1395 | + * @param integer $k |
|
| 1396 | + * @param string $v |
|
| 1397 | + */ |
|
| 1362 | 1398 | protected function insertIntegerXml($parent, $k, $v, $fn) |
| 1363 | 1399 | { |
| 1364 | 1400 | // The user has passed an XML document instance: |
@@ -1388,6 +1424,10 @@ discard block |
||
| 1388 | 1424 | return $this->attachNodes($parent, $nodes, $fn); |
| 1389 | 1425 | } |
| 1390 | 1426 | |
| 1427 | + /** |
|
| 1428 | + * @param integer $k |
|
| 1429 | + * @param \DOMDocument $v |
|
| 1430 | + */ |
|
| 1391 | 1431 | protected function insertIntegerDomdocument($parent, $k, $v, $fn) |
| 1392 | 1432 | { |
| 1393 | 1433 | // A DOMDocument can have multiple root nodes. |
@@ -1399,26 +1439,46 @@ discard block |
||
| 1399 | 1439 | // return $this->attachNodes($parent, $v->documentElement, $fn); |
| 1400 | 1440 | } |
| 1401 | 1441 | |
| 1442 | + /** |
|
| 1443 | + * @param integer $k |
|
| 1444 | + * @param \DOMNodeList $v |
|
| 1445 | + */ |
|
| 1402 | 1446 | protected function insertIntegerDomnodelist($parent, $k, $v, $fn) |
| 1403 | 1447 | { |
| 1404 | 1448 | return $this->attachNodes($parent, $v, $fn); |
| 1405 | 1449 | } |
| 1406 | 1450 | |
| 1451 | + /** |
|
| 1452 | + * @param integer $k |
|
| 1453 | + * @param \DOMNode $v |
|
| 1454 | + */ |
|
| 1407 | 1455 | protected function insertIntegerDomnode($parent, $k, $v, $fn) |
| 1408 | 1456 | { |
| 1409 | 1457 | return $this->attachNodes($parent, $v, $fn); |
| 1410 | 1458 | } |
| 1411 | 1459 | |
| 1460 | + /** |
|
| 1461 | + * @param integer $k |
|
| 1462 | + * @param \SimpleXMLElement $v |
|
| 1463 | + */ |
|
| 1412 | 1464 | protected function insertIntegerSimplexml($parent, $k, $v, $fn) |
| 1413 | 1465 | { |
| 1414 | 1466 | return $this->attachNodes($parent, \dom_import_simplexml($v), $fn); |
| 1415 | 1467 | } |
| 1416 | 1468 | |
| 1469 | + /** |
|
| 1470 | + * @param integer $k |
|
| 1471 | + * @param FluidXml $v |
|
| 1472 | + */ |
|
| 1417 | 1473 | protected function insertIntegerFluidxml($parent, $k, $v, $fn) |
| 1418 | 1474 | { |
| 1419 | 1475 | return $this->attachNodes($parent, $v->dom()->documentElement, $fn); |
| 1420 | 1476 | } |
| 1421 | 1477 | |
| 1478 | + /** |
|
| 1479 | + * @param integer $k |
|
| 1480 | + * @param FluidContext $v |
|
| 1481 | + */ |
|
| 1422 | 1482 | protected function insertIntegerFluidcontext($parent, $k, $v, $fn) |
| 1423 | 1483 | { |
| 1424 | 1484 | return $this->attachNodes($parent, $v->asArray(), $fn); |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | class FluidXml implements FluidInterface |
| 134 | 134 | { |
| 135 | 135 | use NewableTrait, |
| 136 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
| 137 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
| 136 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
| 137 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
| 138 | 138 | |
| 139 | 139 | const ROOT_NODE = 'doc'; |
| 140 | 140 | |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | $doc = $this->document; |
| 169 | 169 | |
| 170 | 170 | $defaults = [ 'root' => self::ROOT_NODE, |
| 171 | - 'version' => '1.0', |
|
| 172 | - 'encoding' => 'UTF-8', |
|
| 173 | - 'stylesheet' => null ]; |
|
| 171 | + 'version' => '1.0', |
|
| 172 | + 'encoding' => 'UTF-8', |
|
| 173 | + 'stylesheet' => null ]; |
|
| 174 | 174 | |
| 175 | 175 | if (\is_string($root)) { |
| 176 | 176 | // The root option can be specified as first argument |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | if (! empty($opts['stylesheet'])) { |
| 198 | 198 | $attrs = 'type="text/xsl" ' |
| 199 | - . "encoding=\"{$opts['encoding']}\" " |
|
| 200 | - . 'indent="yes" ' |
|
| 201 | - . "href=\"{$opts['stylesheet']}\""; |
|
| 199 | + . "encoding=\"{$opts['encoding']}\" " |
|
| 200 | + . 'indent="yes" ' |
|
| 201 | + . "href=\"{$opts['stylesheet']}\""; |
|
| 202 | 202 | $stylesheet = new \DOMProcessingInstruction('xml-stylesheet', $attrs); |
| 203 | 203 | |
| 204 | 204 | $doc->dom->insertBefore($stylesheet, $doc->dom->documentElement); |
@@ -447,8 +447,8 @@ discard block |
||
| 447 | 447 | const MODE_EXPLICIT = 1; |
| 448 | 448 | |
| 449 | 449 | private $config = [ self::ID => '', |
| 450 | - self::URI => '', |
|
| 451 | - self::MODE => self::MODE_EXPLICIT ]; |
|
| 450 | + self::URI => '', |
|
| 451 | + self::MODE => self::MODE_EXPLICIT ]; |
|
| 452 | 452 | |
| 453 | 453 | public function __construct($id, $uri, $mode = 1) |
| 454 | 454 | { |
@@ -529,7 +529,6 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | * ```php |
| 531 | 531 | * $xml = fluidxml(); |
| 532 | - |
|
| 533 | 532 | * $xml->query("/doc/book[@id='123']"); |
| 534 | 533 | * |
| 535 | 534 | * // Relative queries are valid. |
@@ -549,7 +548,6 @@ discard block |
||
| 549 | 548 | * |
| 550 | 549 | * ```php |
| 551 | 550 | * $xml = fluidxml(); |
| 552 | - |
|
| 553 | 551 | * $xml->appendChild('title', 'The Theory Of Everything'); |
| 554 | 552 | * $xml->appendChild([ 'author' => 'S. Hawking' ]); |
| 555 | 553 | * |
@@ -664,8 +662,8 @@ discard block |
||
| 664 | 662 | class FluidContext implements FluidInterface, \ArrayAccess, \Iterator |
| 665 | 663 | { |
| 666 | 664 | use NewableTrait, |
| 667 | - ReservedCallTrait, // For compatibility with PHP 5.6. |
|
| 668 | - ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
| 665 | + ReservedCallTrait, // For compatibility with PHP 5.6. |
|
| 666 | + ReservedCallStaticTrait; // For compatibility with PHP 5.6. |
|
| 669 | 667 | |
| 670 | 668 | private $document; |
| 671 | 669 | private $nodes = []; |