tomzx / abstract-parser
PHP 编写的抽象解析器
v0.1.0
2016-01-24 13:33 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4
This package is auto-updated.
Last update: 2024-09-10 06:35:18 UTC
README
PHP 编写的抽象解析器。基于 nikic的PHP解析器。
入门指南
抽象解析器
提供了2个接口,您需要实现它们
NodeInterface
:您树状数据结构中所有元素的基接口。NodeVisitorInterface
:在进入/退出NodeInterface
元素或在遍历的开始/结束时执行的动作。
一旦您为您的数据元素实现了 NodeInterface
,您可以使用类似以下的方式遍历它们
<?php $rootElement = ...; // Root element of your data structure $traverser = new NodeTraverser(); $traverser->addVisitor(new MyVisitor()); $traverser->traverse([$rootElement]);