Download the PHP package nicmart/tree without Composer

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

Tree

Integrate Release

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

In Tree you can find a basic but flexible tree data structure for php together with and an handful Builder class, that enables you to build tree in a fluent way.

The tree data structure

The Tree\Node\NodeInterface interface abstracts the concept of a tree node. In Tree a Node has essentially two things: a set of children (that implements the same NodeInterface interface) and a value.

On the other hand, the Tree\Node\Node gives a straight implementation for that interface.

Creating a node

Getting and setting the value of a node

Each node has a value property, that can be any php value.

Adding one or more children

Removing a child

Getting the array of all children

Overwriting the children set

Removing all children

Getting if the node is a leaf or not

A leaf is a node with no children.

Getting if the node is a child or not

A child is a node that has a parent.

Getting the parent of a node

Reference to the parent node is automatically managed by child-modifiers methods

Getting the ancestors of a node

Related Methods

Getting the root of a node

Getting the neighbors of a node

Related Methods

Getting the number of nodes in the tree

Getting the depth of a node

Getting the height of a node

The Builder

The builder provides a convenient way to build trees. It is provided by the class, but you can implement your own builder making an implementation of the class.

Example

Let's see how to build the following tree, where the nodes label are represents nodes values:

And here is the code:

The example should be self-explanatory, but here you are a brief description of the methods used above.

Builder::value($value)

Set the value of the current node to

Builder::leaf($value)

Add to the current node a new child whose value is .

Builder::tree($value)

Add to the current node a new child whose value is , and set the new node as the builder current node.

Builder::end()

Returns to the context the builder was before the call to method, i.e. make the builder go one level up.

Builder::getNode()

Returns the current node.

Traversing a tree

Yield

You can obtain the yield of a tree (i.e. the list of leaves in a pre-order traversal) using the YieldVisitor.

For example, if $node is the tree built above, then

Pre-order Traversal

You can walk a tree in pre-order:

Post-order Traversal

You can walk a tree in post-order:

Install

Run

Tests

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.


All versions of tree with dependencies

PHP Build Version
Package Version
Requires php Version ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.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 nicmart/tree contains the following files

Loading the files please wait ....