mirror of
https://github.com/danog/Valinor.git
synced 2025-01-10 14:48:20 +01:00
36 lines
837 B
PHP
36 lines
837 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Fake\Mapper\Tree\Builder;
|
|
|
|
use CuyZ\Valinor\Mapper\Tree\Builder\NodeBuilder;
|
|
use CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder;
|
|
use CuyZ\Valinor\Mapper\Tree\Node;
|
|
use CuyZ\Valinor\Mapper\Tree\Shell;
|
|
|
|
final class FakeNodeBuilder implements NodeBuilder
|
|
{
|
|
/** @var null|callable(Shell): Node */
|
|
private $callback;
|
|
|
|
/**
|
|
* @param null|callable(Shell): Node $callback
|
|
*/
|
|
public function __construct(callable $callback = null)
|
|
{
|
|
if ($callback) {
|
|
$this->callback = $callback;
|
|
}
|
|
}
|
|
|
|
public function build(Shell $shell, RootNodeBuilder $rootBuilder): Node
|
|
{
|
|
if (isset($this->callback)) {
|
|
return ($this->callback)($shell);
|
|
}
|
|
|
|
return Node::leaf($shell, $shell->value());
|
|
}
|
|
}
|