Download the PHP package matthijsbreijer/oaktree without Composer

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

OakTree

Build Status codecov

A tree data structure implementation with support for key-based traversal and custom (un)serialization. Useful implementations could include product trees, file/folder structures, routing trees and a lot more. As a package its written from scratch, mostly derived from nicmart/Tree

Tree structure and tree traversal methods

Node creation

A Node can be passed any type of value during instantiation.

Getting and setting values

A node value can be retrieved and altered using Node::getValue() and Node::setValue(). Note that Node::setValue() is fluent and can be daisy-chained.

Adding children to a Node

One or more children can be added using Node::addChild(). This method is fluent and can be daisy-chained.

Added children to a Node with a specific child key

OakTree keeps track of keys for the Nodes within the tree. As such one can assign a key to a child Node.

Removing a child

Remove the $child1 and $child2 instance from $node 's children. Node::removeChild() is fluent and can be daisy-chained.

Get all direct children of a Node

Get all keys of direct children Nodes

Get a child Node by its key

OakTree keeps keys intact for the Nodes within the tree. As such one can get a child Node by key.

Get the child and remove child from its Node tree

Using Node::pop() one can remove/separate a Node (and its descendants) from a tree and alter it independently.

Set children

Please note that this method removes previously present children. Node::setChildren() sets a (new) array of children Nodes. This method is fluent and can be daisy-chained.

Get the parent node of a child

Get the root Node of a tree

Tree context

Is the Node a leaf?

A leaf is a node with no children.

Is the Node a child?

A child is a node that has a parent.

Is the Node then root Node?

A root Node has no parent.

Tree alterations

OakTree uses the Visitor Pattern to iterate over a tree. The visitor contains the logic to apply on the Nodes in the tree. Visitors must implement the Visitor interface MatthijsBreijer\OakTree\Visitor\VisitorInterface. Visitors return mixed content depending on their purpose.

LeafVisitor

The LeafVisitor returns an array of leaves of a tree ($node's where Node::isLeaf() returns true).

ClosureVisitor

The ClosureVisitor can be passed a function or\Closure argument to define its behavior. The example below mimicks the LeafVisitor.

Serialization / Unserialization

OakTree Nodes have a Node::toArray() and Node::fromArray() method to allow customized (un)serialization of a tree. This can be used to cache data, to quickly pass around information from the tree to an API or vice versa. The nodes also implement PHP's \JsonSerializable interface.

Basic tree to array conversion

Basic array to tree conversion

Using the above example the array result $array can be converted back to a tree as follows.

Closure based tree to array conversion

The Node::toArray() method accepts a second argument for \Closure-based conversion to an array, which in turn can be serialized.

Closure based array to tree conversion

Using the $array variable created in previous example the array result can be converted back to a tree as follows.

Installation

Composer

OakTree can be installed using the PHP Composer package manager using the following command:

Running tests


All versions of oaktree with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 matthijsbreijer/oaktree contains the following files

Loading the files please wait ....