callables = $callables; $this->args = $args; } /** * Callables in order that they should be executed. * * @return array Sequential list of callables. */ public function getCallables(): array { return $this->callables; } /** * Arguments to be sent to each callable. * * @return array Sequential argument list for the callables. */ public function getArguments(): array { return $this->args; } /** * Runs all callables and returns their returns as an array. * * @return array Results from the callables. */ public function runAll(): array { $results = []; foreach($this->callables as $callable) { $result = $callable(...$this->args); if($result !== null) $results[] = $result; } return $results; } /** * Runs all callables unless one returns something. * * @return mixed Result from the returning callable. */ public function run(): mixed { foreach($this->callables as $callable) { $result = $callable(...$this->args); if($result !== null) return $result; } return null; } }