-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Strategy.php
57 lines (47 loc) · 1.35 KB
/
Strategy.php
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
<?php
declare(strict_types=1);
namespace Pheature\Core\Toggle\Write;
use JsonSerializable;
use function array_map;
/**
* @psalm-import-type WriteSegment from Segment
* @psalm-type WriteStrategy array{strategy_id: string, strategy_type: string, segments: WriteSegment[]}
*/
final class Strategy implements JsonSerializable
{
private StrategyId $strategyId;
private StrategyType $strategyType;
/** @var Segment[] */
private array $segments;
/** @param Segment[] $segments */
public function __construct(StrategyId $strategyId, StrategyType $strategyType, array $segments = [])
{
$this->strategyId = $strategyId;
$this->strategyType = $strategyType;
$this->segments = $segments;
}
public function id(): StrategyId
{
return $this->strategyId;
}
public function type(): StrategyType
{
return $this->strategyType;
}
/**
* @return Segment[]
*/
public function segments(): array
{
return $this->segments;
}
/** @return WriteStrategy */
public function jsonSerialize(): array
{
return [
'strategy_id' => $this->strategyId->value(),
'strategy_type' => $this->type()->value(),
'segments' => array_map(static fn(Segment $segment) => $segment->jsonSerialize(), $this->segments()),
];
}
}