nayjest / tree
Tree data structure for PHP
Installs: 73 339
Dependents: 5
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 0
Open Issues: 2
Requires
- php: >=5.4.0
- nayjest/collection: ^2.1
Requires (Dev)
- phpunit/phpunit: ^4.6
README
Tree data structure for PHP
Requirements
- php 5.4+
Installation
The recommended way of installing the component is through Composer.
Run following command:
composer require nayjest/tree
Overview
Tree Nodes
Nodes are basic tree elements. This package represents tree nodes as instances of Nayjest\Tree\Node. Since nodes here don't holds any functionality beyond the scope of organizing into a trees, the package is designed for extending its components functionality in different ways:
- Extend base classes (Node, ReadonlyNode)
- Provide your own implementations of ParentNodeInterface and ChildNodeInterface
- Use traits (NodeTrait, ChildNodeTrait, ParentNodeTrait, ReadonlyNodeTrait) and interfaces if you can't use node classes as base classes
Node Collections
Each node stores its children inside instance of Nayjest\Tree\NodeCollection.
This package uses nayjest/collections for working with collections.
Class Nayjest\Tree\NodeCollection provides consistency of parent-child node relations.
It means that if you will add node to collection, this node will be automatically attached to parent node associated with collection, if you will remove node from collection, node will be detached from parent node.
Trees
Class Nayjest\Tree\Tree allows to:
- organize trees with named nodes (nodes itself don't store information about its name, class Tree works with any objects that implements NodeInterface)
- build tree based on hierarchy configuration (multidimantional array containing only node names) and registry of nodes(associative array where keys are names and values are nodes)
- manipulate named nodes in convenient way (Tree API)
- protect tree structure from modifying via Node API methods to avoid inconsistency of node relations.
Nayjest\Tree\Utils
This class is a facade for helper functions.
Testing
Run following command:
phpunit
License
© 2014—2016 Vitalii Stepanenko
Licensed under the MIT License.
Please see License File for more information.