unrealmanu/abstract-walker

walker recursive abstract helper

0.0.4 2020-03-22 11:44 UTC

This package is auto-updated.

Last update: 2024-04-22 21:18:55 UTC


README

Manuel Trebbi unrealmanumaster@gmail.com

Walk on the deepest level of object or array with filter by instance and control of deep level

CMD LIST

Launch TEST:

composer test tests

Fix LINT

composer fix tests
composer fix src

Install GIT-HOOK

./scripts/install-hook.bash

USAGE

Extends unrealmanu\Walker\AbstractWalker
example:
  • ./tests/Walk.php

Necessary Method

    abstract function loadChildren(array $parent): array;

    /**
     * @param $parent
     * @return array
     */
    public function walk($parent): array;

    /**
     * @param $parent
     * @return Generator
     */
    public function walkGen($parent): Generator;

METHOD

Define action to get object/array childrens and return this

LoadChidren($parent)

Return array of walked elements

walk($parent) [low performance - easy to use and check]

Return the "raw" generator used for walking in the deepest of elements...

walkGen($parent) [best perfomance]

OPTIONS

unrealmanu\Walker\DTO\WalkOptions (predefined)
unrealmanu\Walker\DTO\WalkOptionsInterface (for future implementation)

true = recursive, false = stop in first depth level

    public function setRecursiveProcessStatus(bool $status = true): bool;

Set Class instance for filter the children in walking process

    public function setFilterInstance(array $class): array;

Set the limit of deepest recursion level

    public function setRecursiveDepthLimit(int $recursiveDepthLimit): void;

Make your custom logic filter for item in recursive processes

    public function itemFilter($item): bool