Browse Source

Added documentation for DOM walkers

wrapper-classes
Dustin Wilson 3 years ago
parent
commit
eaf51dc738
  1. 9
      lib/traits/Moonwalk.php
  2. 19
      lib/traits/Walk.php

9
lib/traits/Moonwalk.php

@ -1,12 +1,19 @@
<?php <?php
/** @license MIT /** @license MIT
* Copyright 2017 , Dustin Wilson, J. King et al. * Copyright 2017, Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace MensBeam\HTML\DOM; namespace MensBeam\HTML\DOM;
trait Moonwalk { trait Moonwalk {
/**
* Generator which walks backwards through the DOM from the node the method is
* being run on. Nonstandard.
*
* @param ?\Closure $filter - An optional callback function used to filter; if not provided the generator will
* just yield every node.
*/
public function moonwalk(?\Closure $filter = null): \Generator { public function moonwalk(?\Closure $filter = null): \Generator {
$node = $this->parentNode; $node = $this->parentNode;
if ($node !== null) { if ($node !== null) {

19
lib/traits/Walk.php

@ -1,13 +1,19 @@
<?php <?php
/** @license MIT /** @license MIT
* Copyright 2017 , Dustin Wilson, J. King et al. * Copyright 2017, Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details */ * See LICENSE and AUTHORS files for details */
declare(strict_types=1); declare(strict_types=1);
namespace MensBeam\HTML\DOM; namespace MensBeam\HTML\DOM;
trait Walk { trait Walk {
/** Generator which walks down the DOM. Nonstandard. */ /**
* Generator which walks down the DOM from the node the method is being run on.
* Nonstandard.
*
* @param ?\Closure $filter - An optional callback function used to filter; if not provided the generator will
* just yield every node.
*/
public function walk(?\Closure $filter = null): \Generator { public function walk(?\Closure $filter = null): \Generator {
$node = $this->firstChild; $node = $this->firstChild;
if ($node !== null) { if ($node !== null) {
@ -39,11 +45,12 @@ trait Walk {
/** /**
* Generator which just walks through a node's child nodes. Nonstandard. * Generator which just walks through a node's child nodes. Nonstandard.
* *
* @param ?\Closure $filter - A callback function used to filter * @param ?\Closure $filter - An optional callback function used to filter; if not provided the generator will
* @param bool $backwards - An optional setting that if true makes the generator walk backwards through the * just yield every node.
* child nodes. * @param bool $backwards - An optional setting that if true makes the generator instead walk backwards
* through the child nodes.
*/ */
public function walkShallow(?\Closure $filter = null, $backwards = false): \Generator { public function walkShallow(?\Closure $filter = null, bool $backwards = false): \Generator {
$node = (!$this instanceof TemplateElement) ? $this : $this->content; $node = (!$this instanceof TemplateElement) ? $this : $this->content;
if (!$backwards) { if (!$backwards) {

Loading…
Cancel
Save