Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeraymonddowning committed Feb 26, 2024
1 parent c6ee81f commit 73351b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function __construct(

/**
* Execute this step.
*
* @param array<mixed> $responses
*/
public function run(array $responses): mixed
{
Expand All @@ -27,15 +29,17 @@ public function run(array $responses): mixed
*/
public function canRevert(): bool
{
return $this->previous?->revert !== false;
return $this->previous?->revert instanceof Closure;
}

/**
* Revert to the previous step.
*
* @param array<mixed> $responses
*/
public function revert(array $responses): void
{
if ($this->canRevert()) {
if ($this->previous?->revert instanceof Closure) {
($this->previous->revert)($responses);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/StepBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ class StepBuilder
{
/**
* Each step that should be executed.
*
* @var array<int, \Laravel\Prompts\Step>
*/
protected array $steps = [];

/**
* The responses provided by each step.
*
* @var array<mixed>
*/
protected array $responses = [];

/**
* Add a new step.
*/
public function add(Closure $step, Closure|false|null $revert = null, ?string $key = null)
public function add(Closure $step, Closure|false|null $revert = null, ?string $key = null): self
{
if ($revert === null) {
$revert = fn () => null;
Expand All @@ -33,6 +37,8 @@ public function add(Closure $step, Closure|false|null $revert = null, ?string $k

/**
* Run all of the given steps.
*
* @return array<mixed>
*/
public function run(): array
{
Expand Down

0 comments on commit 73351b3

Please sign in to comment.