Download the PHP package bluem/tree without Composer

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

Build status

Overview

This library provides handling of data that is structured hierarchically using parent ID references. A typical example is a table in a relational database where each record’s “parent” field references the primary key of another record. Of course, usage is not limited to data originating from a database, but anything: you supply the data, and the library uses it, regardless of where the data came from and how it was processed.

It is important to know that the tree structure created by this package is read-only: you can’t use it to perform modifications of the tree nodes.

On the other hand, one nice thing is that it’s pretty fast. This does not only mean the code itself, but also that the constructor takes the input data in a format that is simple to create. For instance, to create a tree from database content, a single SELECT is sufficient, regardless of the depth of the tree and even for thousands of nodes.

Installation

The recommended way to install this library is through Composer: composer require bluem/tree. As the library uses semantic versioning, you can define version a constraint in composer.json which allows all non-major updates.

Alternatively, you can clone the repository using git or download a tagged release.

Usage

Creating a tree

Updating the tree with new data

Retrieving nodes

Getting a node’s parent, siblings, children, ancestors and descendants

Accessing a node’s properties

Example: Using it with literal data

Example: Using it with a self-joined database table

JSON serialization

As Tree implements JsonSerializable, a tree can be serialized to JSON. By default, the resulting JSON represents a flat (non-hierarchical) representation of the tree data, which – once decoded from JSON – can be re-fed into a new Tree instance. In version before 3.0, you had to subclass the Tree and the Node class to customize the JSON output. Now, serialization is extracted to an external helper class which can be changed both by setting a constructor argument or at runtime just before serialization. However, the default serialization result is the same as before, so you won’t notice any change in behavior unless you tweaked JSON serialization.

To control the JSON, you can either pass an option jsonSerializer to an \BlueM\Tree\Options instance you pass the the Tree constructor, which must be an object implementing \BlueM\Tree\Serializer\TreeJsonSerializerInterface. Or you call method setJsonSerializer() on the tree. The latter approach can also be used to re-set serialization behavior to the default by calling it without an argument.

The library comes with two distinct serializers: \BlueM\Tree\Serializer\FlatTreeJsonSerializer is the default, which is used if no serializer is set and which results in the “old”, flat JSON output. Plus, there is \BlueM\Tree\Serializer\HierarchicalTreeJsonSerializer, which creates a hierarchical, depth-first sorted representation of the tree nodes. If you need something else, feel free to write your own serializer.

Handling inconsistent data

If a problem is detected while building the tree (such as a parent reference to the node itself or in invalid parent ID), an exception (subclass of InvalidParentException) is thrown. Often this makes sense, but it might not always. For those cases, you can pass in a callable by setting $buildWarningCallback of a \BlueM\Tree\Options instance which can be given as argument 2 to Tree’s constructor, and which will be called whenever a problem is seen. The signature of the callable is like this:

Running Tests

PHPUnit is configured as a dev dependency, so running tests is a matter of:

Version History

4 (2025-xx-xx)

3.2 (2021-12-30)

3.1 (2019-09-15)

3.0 (2019-03-28)

2.0 (2018-02-04)

1.5.3 (2016-05-20)

1.5.2 (2016-05-10)

1.5.1 (2016-01-16)

1.5 (2015-01-14)

1.4 (2015-01-07)

1.3 (2014-11-07)

1.2 (2014-10-14)

1.1 (2014-09-24)

1.0 (2014-06-26)

Author & License

This code was written by Carsten Blüm (www.bluem.net) and contributors and licensed under the BSD 3-Clause license.


All versions of tree with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3 || >=8.0
ext-json Version *
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 bluem/tree contains the following files

Loading the files please wait ....