Fix bin/publish: copy docs.dist from project root

Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 02:08:33 +00:00
commit f6fac6c4bc
79758 changed files with 10547827 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Builder;
use Tree\Node\Node;
use Tree\Node\NodeInterface;
/**
* Main implementation of the NodeBuilderInterface.
*/
class NodeBuilder implements NodeBuilderInterface
{
/**
* @var array<int, NodeInterface>
*/
private array $nodeStack = [];
public function __construct(?NodeInterface $node = null)
{
$this->setNode($node ?: $this->nodeInstanceByValue());
}
public function setNode(NodeInterface $node): static
{
$this
->emptyStack()
->pushNode($node);
return $this;
}
public function getNode(): NodeInterface
{
$count = \count($this->nodeStack);
if (0 === $count) {
throw new \LogicException('The node builder currently does not manage any nodes.');
}
return $this->nodeStack[$count - 1];
}
public function leaf(mixed $value = null): static
{
$this->getNode()->addChild(
$this->nodeInstanceByValue($value),
);
return $this;
}
public function leafs(mixed ...$values): static
{
foreach ($values as $value) {
$this->leaf($value);
}
return $this;
}
public function tree(mixed $value = null): static
{
$node = $this->nodeInstanceByValue($value);
$this->getNode()->addChild($node);
$this->pushNode($node);
return $this;
}
public function end(): ?static
{
$this->popNode();
return $this;
}
public function nodeInstanceByValue(mixed $value = null): NodeInterface
{
return new Node($value);
}
public function value(mixed $value): static
{
$this->getNode()->setValue($value);
return $this;
}
private function emptyStack(): static
{
$this->nodeStack = [];
return $this;
}
private function pushNode(NodeInterface $node): static
{
$this->nodeStack[] = $node;
return $this;
}
private function popNode(): void
{
\array_pop($this->nodeStack);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Builder;
use Tree\Node\NodeInterface;
/**
* Interface that allows a fluent tree building.
*
* @author Nicolò Martini <nicmartnic@gmail.com>
*/
interface NodeBuilderInterface
{
/**
* Set the node the builder will manage.
*/
public function setNode(NodeInterface $node): static;
/**
* Get the node the builder manages.
*
* @throws \LogicException
*/
public function getNode(): NodeInterface;
/**
* Set the value of the underlaying node.
*/
public function value(mixed $value): static;
/**
* Add a leaf to the node.
*/
public function leaf(mixed $value = null): static;
/**
* Add several leafs to the node.
*/
public function leafs(mixed ...$values): static;
/**
* Add a child to the node enter in its scope.
*/
public function tree(mixed $value = null): static;
/**
* Goes up to the parent node context.
*/
public function end(): ?static;
/**
* Return a node instance set with the given value. Implementation can follow their own logic
* in choosing the NodeInterface implmentation taking into account the value.
*/
public function nodeInstanceByValue(mixed $value = null): NodeInterface;
}

33
vendor/nicmart/tree/src/Node/Node.php vendored Executable file
View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Node;
class Node implements NodeInterface
{
use NodeTrait;
/**
* @param array<int, NodeInterface> $children
*/
public function __construct(
mixed $value = null,
array $children = [],
) {
$this->setValue($value);
if ([] === $children) {
return;
}
$this->setChildren($children);
}
}

139
vendor/nicmart/tree/src/Node/NodeInterface.php vendored Executable file
View File

@@ -0,0 +1,139 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Node;
use Tree\Visitor\Visitor;
/**
* Interface for tree nodes.
*
* @author Nicolò Martini <nicmartnic@gmail.com>
*/
interface NodeInterface
{
/**
* Set the value of the current node.
*/
public function setValue(mixed $value): static;
/**
* Get the current node value.
*/
public function getValue(): mixed;
/**
* Add a child.
*
* @return mixed
*/
public function addChild(self $child): static;
/**
* Remove a node from children.
*/
public function removeChild(self $child): static;
/**
* Remove all children.
*/
public function removeAllChildren(): static;
/**
* Return the array of children.
*
* @return array<int, NodeInterface>
*/
public function getChildren(): array;
/**
* Replace the children set with the given one.
*
* @param array<int, NodeInterface> $children
*
* @return mixed
*/
public function setChildren(array $children): static;
/**
* Set the parent node.
*/
public function setParent(?self $parent = null): void;
/**
* Return the parent node.
*/
public function getParent(): ?static;
/**
* Retrieves all ancestors of node excluding current node.
*/
public function getAncestors(): array;
/**
* Retrieves all ancestors of node as well as the node itself.
*
* @return array<int, Node>
*/
public function getAncestorsAndSelf(): array;
/**
* Retrieves all neighboring nodes, excluding the current node.
*/
public function getNeighbors(): array;
/**
* Returns all neighboring nodes, including the current node.
*
* @return array<int, NodeInterface>
*/
public function getNeighborsAndSelf(): array;
/**
* Return true if the node is the root, false otherwise.
*/
public function isRoot(): bool;
/**
* Return true if the node is a child, false otherwise.
*/
public function isChild(): bool;
/**
* Return true if the node has no children, false otherwise.
*/
public function isLeaf(): bool;
/**
* Find the root of the node.
*/
public function root(): static;
/**
* Return the distance from the current node to the root.
*/
public function getDepth(): int;
/**
* Return the height of the tree whose root is this node.
*/
public function getHeight(): int;
/**
* Return the number of nodes in a tree.
*/
public function getSize(): int;
/**
* Accept method for the visitor pattern (see http://en.wikipedia.org/wiki/Visitor_pattern).
*/
public function accept(Visitor $visitor): mixed;
}

214
vendor/nicmart/tree/src/Node/NodeTrait.php vendored Executable file
View File

@@ -0,0 +1,214 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Node;
use Tree\Visitor\Visitor;
trait NodeTrait
{
private mixed $value = null;
private ?NodeInterface $parent = null;
/**
* @var array<int, NodeInterface>
*/
private array $children = [];
public function setValue(mixed $value): static
{
$this->value = $value;
return $this;
}
public function getValue(): mixed
{
return $this->value;
}
public function addChild(NodeInterface $child): static
{
$child->setParent($this);
$this->children[] = $child;
return $this;
}
public function removeChild(NodeInterface $child): static
{
foreach ($this->children as $key => $myChild) {
if ($child === $myChild) {
unset($this->children[$key]);
}
}
$this->children = \array_values($this->children);
$child->setParent(null);
return $this;
}
public function removeAllChildren(): static
{
$this->setChildren([]);
return $this;
}
public function getChildren(): array
{
return $this->children;
}
public function setChildren(array $children): static
{
foreach ($this->getChildren() as $child) {
$child->setParent(null);
}
$this->children = [];
foreach ($children as $child) {
$this->addChild($child);
}
return $this;
}
public function setParent(?NodeInterface $parent = null): void
{
$this->parent = $parent;
}
public function getParent(): ?static
{
return $this->parent;
}
public function getAncestors(): array
{
$parents = [];
$node = $this;
while (($parent = $node->getParent()) instanceof NodeInterface) {
\array_unshift($parents, $parent);
$node = $parent;
}
return $parents;
}
public function getAncestorsAndSelf(): array
{
return \array_merge($this->getAncestors(), [$this]);
}
public function getNeighbors(): array
{
if (null === $this->parent) {
return [];
}
$neighbors = $this->parent->getChildren();
$that = $this;
return \array_values(\array_filter($neighbors, static function (NodeInterface $node) use ($that): bool {
return $node !== $that;
}));
}
public function getNeighborsAndSelf(): array
{
if (null === $this->parent) {
return [
$this,
];
}
return $this->parent->getChildren();
}
public function isRoot(): bool
{
return null === $this->parent;
}
public function isChild(): bool
{
return null !== $this->parent;
}
public function isLeaf(): bool
{
return [] === $this->children;
}
public function root(): static
{
$node = $this;
while (($parent = $node->getParent()) instanceof NodeInterface) {
$node = $parent;
}
return $node;
}
/**
* Return the distance from the current node to the root.
*
* Warning, can be expensive, since each descendant is visited
*/
public function getDepth(): int
{
if ($this->isRoot()) {
return 0;
}
return $this->getParent()->getDepth() + 1;
}
/**
* Return the height of the tree whose root is this node.
*/
public function getHeight(): int
{
if ($this->isLeaf()) {
return 0;
}
$heights = [];
foreach ($this->getChildren() as $child) {
$heights[] = $child->getHeight();
}
return \max($heights) + 1;
}
public function getSize(): int
{
$size = 1;
foreach ($this->getChildren() as $child) {
$size += $child->getSize();
}
return $size;
}
public function accept(Visitor $visitor): mixed
{
return $visitor->visit($this);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Visitor;
use Tree\Node\NodeInterface;
class PostOrderVisitor implements Visitor
{
/**
* @return array<int, NodeInterface> $node
*/
public function visit(NodeInterface $node): mixed
{
$nodes = [];
foreach ($node->getChildren() as $child) {
$nodes = \array_merge(
$nodes,
$child->accept($this),
);
}
$nodes[] = $node;
return $nodes;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Visitor;
use Tree\Node\NodeInterface;
class PreOrderVisitor implements Visitor
{
/**
* @return array<int, NodeInterface> $node
*/
public function visit(NodeInterface $node): array
{
$nodes = [
$node,
];
foreach ($node->getChildren() as $child) {
$nodes = \array_merge(
$nodes,
$child->accept($this),
);
}
return $nodes;
}
}

24
vendor/nicmart/tree/src/Visitor/Visitor.php vendored Executable file
View File

@@ -0,0 +1,24 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Visitor;
use Tree\Node\NodeInterface;
/**
* Visitor interface for Nodes.
*
* @author Nicolò Martini <nicmartnic@gmail.com>
*/
interface Visitor
{
public function visit(NodeInterface $node): mixed;
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Copyright (c) 2013-2024 Nicolò Martini
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/nicmart/Tree
*/
namespace Tree\Visitor;
use Tree\Node\NodeInterface;
class YieldVisitor implements Visitor
{
/**
* @return array<int, NodeInterface>
*/
public function visit(NodeInterface $node): mixed
{
if ($node->isLeaf()) {
return [$node];
}
$yield = [];
foreach ($node->getChildren() as $child) {
$yield = \array_merge($yield, $child->accept($this));
}
return $yield;
}
}