unrealmanu / abstract-walker
递归抽象辅助器
0.0.4
2020-03-22 11:44 UTC
Requires
- php: ^7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.1
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-22 22:15:42 UTC
README
Manuel Trebbi unrealmanumaster@gmail.com
遍历对象或数组的深层,通过实例过滤和控制深度级别
命令列表
启动测试
composer test tests
修复LINT
composer fix tests
composer fix src
安装GIT-HOOK
./scripts/install-hook.bash
用法
扩展unrealmanu\Walker\AbstractWalker
示例
- ./tests/Walk.php
必要方法
abstract function loadChildren(array $parent): array; /** * @param $parent * @return array */ public function walk($parent): array; /** * @param $parent * @return Generator */ public function walkGen($parent): Generator;
方法
定义动作以获取对象/数组的子项并返回
LoadChidren($parent)
返回遍历元素的数组
walk($parent) [low performance - easy to use and check]
返回用于在元素最深层遍历的"原始"生成器...
walkGen($parent) [best perfomance]
选项
unrealmanu\Walker\DTO\WalkOptions (预定义)
unrealmanu\Walker\DTO\WalkOptionsInterface (用于未来实现)
true = 递归, false = 在第一深度级别停止
public function setRecursiveProcessStatus(bool $status = true): bool;
设置类实例以过滤遍历过程中的子项
public function setFilterInstance(array $class): array;
设置最深递归级别的限制
public function setRecursiveDepthLimit(int $recursiveDepthLimit): void;
在递归过程中为项目创建自定义逻辑过滤器
public function itemFilter($item): bool