Skip to content

Version 0.5.0

Compare
Choose a tag to compare
@veewee veewee released this 21 Apr 05:46
v0.5.0
95ddbcd

We've got visitors

Total issues resolved: 5

Some highlights:

Node Collections

$total = $xml->locate(elements_with_tagname('products'))
     ->children()
     ->filter(
         static fn(DOMElement $element)
            => $element->getAttribute('active') === 'yes'
     )
     ->query('./price')
     ->reduce(
         static fn(int $total, DOMElement $price)
            => $total + value($price, Type\int()),
         0
     );

Traversable node visitors

$doc = Document::fromXmlFile(
    $file,
    traverse(
        new WazzupVisitor(),
    )
);
class WazzupVisitor extends AbstractVisitor
{
    public function onNodeLeave(DOMNode $node) : Action
    {
        if (!is_attribute($node)) {
            return new Action\Noop();
        }

        attribute($node->nodeName, 'WAZZUP')($node->parentNode);

        return new Action\Noop();
    }
}