previousnext / nested-set
A PHP Doctrine DBAL implementation for Nested Sets.
Installs: 831 392
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 13
Forks: 8
Open Issues: 8
Requires
- php: >=8.0
- doctrine/dbal: ^3.3
Requires (Dev)
- ext-pdo_sqlite: *
- dealerdirect/phpcodesniffer-composer-installer: ^0.7
- drupal/coder: ^8.3.12
- pear/console_table: ^1.3
- phpcompatibility/php-compatibility: ^9.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-deprecation-rules: ^1.0
- phpunit/phpunit: ^8.5 || ^9.3
- squizlabs/php_codesniffer: ^3.7.1
README
A PHP Doctrine DBAL implementation for Nested Sets.
Using
Create table schema
Create the table schema, passing in a a DBAL connection and table name (defaults to 'tree').
$schema = new DbalNestedSetSchema($connection, 'my_tree'); schema->create();
Set up the nested set client
Create a new DbalNestedSet
passing in the DBAL connection and the table name.
$nestedSet = new DbalNestedSet($connection, 'my_tree');
Add a root node
A NodeKey represents a unique ID for a node in the tree. It supports the idea of a node ID and a revision ID, mostly for compatibility with Drupal.
$nodeKey = new NodeKey($id, $revisionId); $rootNode = $nestedSet->addRootNode($nodeKey);
Add a child node
To add a child node, you provide the parent node, and a child node key.
$nodeKey = new NodeKey($id, $revisionId); $nestedSet->addNodeBelow($rootNode, $nodeKey);
Find Descendants
To find descendents, you provide the parent node key.
$nodeKey = new NodeKey($id, $revisionId); $descendants = $this->nestedSet->findDescendants($nodeKey);
Find ancestors
To find ancestors, you provide the child node key.
$nodeKey = new NodeKey($id, $revisionId); $ancestors = $this->nestedSet->findAncestors($nodeKey);
See \PNX\NestedSet\NestedSetInterface
for many more methods that can be used for interacting with the nested set.
Developing
Dependencies
To install all dependencies, run:
make init
Linting
Uses the Drupal coding standard.
To validate code sniffs run:
make lint-php
To automatically fix code sniff issues, run:
make fix-php
Testing
To run all phpunit tests, run:
make test