Download the PHP package webhappens/traverser without Composer

On this page you can find all versions of the php package webhappens/traverser. 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 traverser

tests

Traverser

Easily traverse nested object structures without worrying about recursion. Great for building menus, navigation, sitemaps and more!

Installation

Install via composer:

Import the class into your namespace:

Getting started

In order for the traverser to understand your hierarchy, you must ensure it can resolve "id", "parent" and "children" for each class in that hierarchy.

By default, it will look for "methods" or "properties" (in that order) by each of these names. If your classes extend from Illuminate\Database\Eloquent\Model it will resolve the "id" automatically from the getKey method.

Your classes should typically look something like this:

Next, create a new instance of the traverser class and pass in an instance of the class you'd like to use as your starting point for traversal.

You can now call the various traversal methods on this instance.

As a convenience you might want to put this on a base class or trait:

And then call it like this:

For a deeper insight on using the traverser you should take a look at the tests.

Custom mapping names

You may override the default "id", "parent" and "children" mapping names for each class if you want to.

To do this pass a second argument into the constructor containing a custom mapping array.

If you're using Laravel you may want to bind this to the Service Container.

And then resolve it like this:

Note that you can construct a new traverser instance without passing any arguments and use the maps and current methods instead.

Inferring parent and children

In most situations your objects will only have data about who their "parent" is or who their "children" are, not both. For this reason the traverser allows you to easily infer one from the other.

To infer parent you should pass an array of all possible parents into the inferParent method. Each of these objects must be able to resolve its own children.

To infer children you should pass an array of all possible children into the inferChildren method. Each of these objects must be able to resolve its own parent.

Traversal methods

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of traverser with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0
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 webhappens/traverser contains the following files

Loading the files please wait ....