Saeghe is a difficult name to pronounce. Therefore, Saeghe project has been renamed to phpkg.
This website no longer receives updates.
Please visit phpkg website at phpkg.com
The Tree
class is part of the Datatype package.
You can use this class to define any tree structures.
Here you can see its API and see how to use it.
You can make a new instance of this class by passing a root to the constructor and then use the following methods:
$tree = new Tree('/');
assert_true($tree->root === '/');
assert_true($tree->vertices() instanceof Collection);
assert_true($tree->edges() instanceof Collection);
assert_true(['/'] === $tree->vertices()->items());
assert_true([] === $tree->edges()->items());
Here you can see a list of the available methods on the tree:
public function edge($vertex, $leaf): static
It adds an edge to the tree.
$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true(['/', 'home'] === $tree->vertices()->items());
assert_true([new Pair('/', 'home')] == $tree->edges()->items());
public function edges(): Collection
It returns a collection of defined edges.
$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true([new Pair('/', 'home')] == $tree->edges()->items());
public function vertices(): Collection
It returns a collection of added vertices.
$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true(['/', 'home'] === $tree->vertices()->items());