Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5985952
DOMPostOrder.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
DOMPostOrder.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Wikimedia\Parsoid\Utils
;
use
Wikimedia\Parsoid\DOM\Node
;
/**
* Non-recursive post-order traversal of a DOM tree.
*/
class
DOMPostOrder
{
/**
* @suppress PhanEmptyPrivateMethod
*/
private
function
__construct
()
{
/* Not meant to be instantiated. */
}
/**
* Non-recursive post-order traversal of a DOM tree.
* @param Node $root
* @param callable $visitFunc Called in post-order on each node.
*/
public
static
function
traverse
(
Node
$root
,
callable
$visitFunc
):
void
{
$node
=
$root
;
while
(
true
)
{
// Find leftmost (grand)child, and visit that first.
while
(
$node
->
firstChild
)
{
$node
=
$node
->
firstChild
;
}
while
(
true
)
{
$visitFunc
(
$node
);
if
(
$node
===
$root
)
{
return
;
// Visiting the root is the last thing we do.
}
/* Look for right sibling to continue traversal. */
if
(
$node
->
nextSibling
)
{
$node
=
$node
->
nextSibling
;
/* Loop back and visit its leftmost (grand)child first. */
break
;
}
/* Visit parent only after we've run out of right siblings. */
$node
=
$node
->
parentNode
;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 23:57 (2 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2d/43/f46291477ec3478d3e79602ebf58
Default Alt Text
DOMPostOrder.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment