|
@@ 130-139 (lines=10) @@
|
| 127 |
|
* @param mixed $nodeName The name of the 'name' property or a function that returns the name of a node. |
| 128 |
|
* @return array |
| 129 |
|
*/ |
| 130 |
|
public static function ls($node, $callback, $nodeName = 'nodeName') |
| 131 |
|
{ |
| 132 |
|
$result = []; |
| 133 |
|
foreach ($node->childNodes as $child) { |
| 134 |
|
$name = self::getNodeName( $child, $nodeName ); |
| 135 |
|
$result[ $name ] = call_user_func( $callback, $child ); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
return $result; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
/** |
| 142 |
|
* Calls the callback method on each child of the current node, including the node itself, until a non-null |
|
@@ 197-205 (lines=9) @@
|
| 194 |
|
* @param mixed $initial The value to pass to the first callback call. |
| 195 |
|
* @return mixed |
| 196 |
|
*/ |
| 197 |
|
public static function reduce($node, $callback, $initial = null) |
| 198 |
|
{ |
| 199 |
|
$result = call_user_func( $callback, $initial, $node ); |
| 200 |
|
foreach ($node->childNodes as $child) { |
| 201 |
|
$result = self::reduce( $child, $callback, $result ); |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
return $result; |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
/** |
| 208 |
|
* Filters the tree using a callback method. If the callback method returns true, the node's value is included |