Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serialize_rejection to the yaml key #131

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 9 additions & 1 deletion src/Plugin/Filtering/Builder/Reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class Reject implements StepBuilderInterface
private ?Node\Expr $logger = null;
private ?Node\Expr $rejection = null;
private ?Node\Expr $state = null;
private ?Node\Expr $serialize_rejection = null;
/** @var list<?Node\Expr> */
private array $exclusions = [];

Expand All @@ -42,6 +43,13 @@ public function withState(Node\Expr $state): self
return $this;
}

public function withSerialiazeRejection(Node\Expr $serialize_rejection): self
{
$this->serialize_rejection = $serialize_rejection;

return $this;
}

public function withExclusions(Node\Expr ...$exclusions): self
{
array_push($this->exclusions, ...$exclusions);
Expand Down Expand Up @@ -125,7 +133,7 @@ class: new Node\Stmt\Class_(null, [
new Node\Expr\New_(
new Node\Name\FullyQualified(RejectionResultBucket::class),
[
new Node\Arg(new Node\Expr\Variable('input')),
$this->serialize_rejection !== null ? new Node\Arg($this->serialize_rejection) : new Node\Arg(new Node\Expr\Variable('input'))
]
),
),
Expand Down
7 changes: 7 additions & 0 deletions src/Plugin/Filtering/Configuration/Reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public function getConfigTreeBuilder(): TreeBuilder
->then(asExpression())
->end()
->end()
->scalarNode('serialize_rejection')
->cannotBeEmpty()
->validate()
->ifTrue(isExpression())
->then(asExpression())
->end()
->end()
JoMessina marked this conversation as resolved.
Show resolved Hide resolved
->end()
->end()
;
Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/Filtering/Factory/Reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function compile(array $config): Repository\Reject
$builder->withExclusions(
compileExpression($interpreter, $condition['when'])
);
if (array_key_exists('serialize_rejection', $condition)) {
$builder->withSerialiazeRejection(compileExpression($interpreter, $condition['serialize_rejection']));
}
}

return $repository;
Expand Down
Loading