. */ namespace SP\Util; use Closure; /** * Class Chainable */ final class Chainable { private array $args; public function __construct(private readonly Closure $next, private readonly object $bindTo, ...$args) { $this->args = $args; } public function next(Closure $next): Chainable { $resolved = $this->next->call($this->bindTo, ...$this->args); return new self($next, $this->bindTo, $resolved); } public function resolve(): mixed { return $this->next->call($this->bindTo, ...$this->args); } }