Skip to content

Commit

Permalink
Adding Statement::when conditionable
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 24, 2024
1 parent 07cf24b commit bf70531
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ public function limit(int $limit): self
return $clone;
}

/**
* @template TWhenParameter
*
* @param (Closure($this): TWhenParameter)|TWhenParameter $value
* @param callable($this, TWhenParameter): ($this|null) $callback
*/
public function when($value, callable $callback): self
{
if ($value instanceof Closure) {
$value = $value($this);
}

if (!$value) {
return $this;
}

return $callback($this, $value) ?? $this;
}

/**
* Executes the prepared Statement on the {@link TabularDataReader} object.
*
Expand Down Expand Up @@ -437,7 +456,6 @@ protected function buildOrderBy(Iterator $iterator): Iterator
return $cmp ?? 0;
};


$class = new class () extends ArrayIterator {
public function seek(int $offset): void
{
Expand Down

0 comments on commit bf70531

Please sign in to comment.