Skip to content

Commit

Permalink
Reflect ParamsProvider and TargetProvider in builder
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Mar 13, 2024
1 parent eb01ca4 commit 71e2d4c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/RecordBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use JuniWalk\Nestor\Entity\Record;
use JuniWalk\Nestor\Enums\Type;
use JuniWalk\Nestor\Exceptions\RecordNotValidException;
use JuniWalk\Nestor\Interfaces\ParamsProvider;
use JuniWalk\Nestor\Interfaces\TargetRelatedProvider;
use JuniWalk\Utils\Format;
use JuniWalk\Utils\Enums\Color;
use JuniWalk\Utils\Strings;
Expand Down Expand Up @@ -108,6 +110,14 @@ public function withEvent(?string $event): static

public function withTarget(object $target): static
{
if ($target instanceof ParamsProvider) {
$this->withParams($target->getRecordParams());
}

if ($target instanceof TargetProvider) {
$target = $target->getRecordTarget();
}

$this->record['target'] = $target;
return $this;
}
Expand Down Expand Up @@ -155,7 +165,8 @@ public function withParams(array $params): static
unset($params[$key]);
}

$this->record['params'] = $params;
$this->record['params'] ??= [];
$this->record['params'] += $params;
return $this;
}

Expand All @@ -165,4 +176,11 @@ public function withParam(string $name, mixed $value): static
$this->record['params'][$name] = $value;
return $this;
}


public function clearParams(): static
{
unset($this->record['params']);
return $this;
}
}

0 comments on commit 71e2d4c

Please sign in to comment.