Download the PHP package rezozero/tree-walker without Composer

On this page you can find all versions of the php package rezozero/tree-walker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tree-walker

Tree Walker

Tests status License Packagist

Creates a configurable tree walker using different definitions for each node based on its PHP class or interface.

WalkerInterface implements \Countable in order to use it seamlessly in your PHP code and Twig templates. Each WalkerInterface will carry your node object and its children.

Since v1.1.0 AbstractWalker does not implement \IteratorAggregate in order to be compatible with api-platform normalizer (it normalizes it as a Hydra:Collection). But if you need it in you can add \IteratorAggregate to your custom Walker implementation, getIterator is already implemented.

If your application may introduce cyclic references between objects, you can use AbstractCycleAwareWalker instead of AbstractWalker to keep track of collected items and prevent collecting same item children twice. Collision detection is based on spl_object_id method.

Usage in Twig

Walk forward

Here is an example of a recursive navigation item template using our WalkerInterface:

Walk backward

You can reverse walk (aka moon walking) to display a page breadcrumbs for example:

Configure your Walker

  1. Create a WalkerContextInterface instance to hold every service your callable definitions will use to fetch each tree node children. For example: a Doctrine repository, a QueryBuilder, even your PDO instance.
  2. Create a custom Walker class extending AbstractWalker.
    You’ll notice that AbstractWalker is very strict and prevents overriding its constructor in order to abstract all WalkerInterface instantiations from your business logic. All your custom logic must be included in definitions and countDefinitions.
  3. Add definitions and countDefinitions from your custom Walker. A definition callable must return an array (or an iterable object) of your items. A countDefinition callable must return an int representing your items number. CountDefinitions are optional: AbstractWalker::count() method will fall back on using AbstractWalker::getChildren()->count().
  4. Instantiate your custom Walker with your root item, and your context object

Here is some pseudo PHP code example:

Serialization groups

Any walker interface can be serialized with jms/serializer since they extends AbstractWalker class. You should add serialization groups to ensure you do not fall into an infinite loop:

Obviously, do not use children and walker_parent groups at the same time…

Stoppable definition

You may want to prevent Walker to continue after a given item definition. For example to prevent infinite loops. You can write your definition class implementing StoppableDefinition interface.

If isStoppingCollectionOnceInvoked method return true, then each child won't have any children. It is useful when you want to prevent your tree to go deeper for specific item types. This is more specific than configuring the global maxLevel value on your tree-walker root instance.


All versions of tree-walker with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
psr/cache Version ^1.0 || ^2.0 || ^3.0
jms/serializer Version ^3.7
symfony/serializer Version >=5.4
symfony/cache Version >=5.4
doctrine/collections Version >=1.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rezozero/tree-walker contains the following files

Loading the files please wait ....