-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.php
More file actions
67 lines (59 loc) · 1.48 KB
/
Action.php
File metadata and controls
67 lines (59 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @author enea dhack <contact@vaened.dev>
* @link https://vaened.dev DevFolio
*/
declare(strict_types=1);
namespace Vaened\DeltaOrchestrator;
use Closure;
use Vaened\DeltaOrchestrator\Bindings\Behavior;
use Vaened\DeltaOrchestrator\Exceptions\InvalidActionDefinition;
use Vaened\DeltaOrchestrator\Rules\Rule;
final readonly class Action
{
/**
* @param array<int, Field|Behavior> $fields
* @param Closure(Field ...$fields): mixed $apply
* @param (Closure(Field ...$fields): Rule)|null $when
* @param string|null $description
*/
public function __construct(
private array $fields,
private Closure $apply,
private ?Closure $when = null,
private ?string $description = null,
)
{
if ($this->fields === []) {
throw new InvalidActionDefinition(
reason : 'Action fields cannot be empty',
description: $this->description,
);
}
}
/**
* @return array<int, Field|Behavior>
*/
public function fields(): array
{
return $this->fields;
}
/**
* @return Closure(Field ...$fields): mixed
*/
public function apply(): Closure
{
return $this->apply;
}
/**
* @return (Closure(Field ...$fields): Rule)|null
*/
public function when(): ?Closure
{
return $this->when;
}
public function description(): ?string
{
return $this->description;
}
}