-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
StrategyWasAdded.php
85 lines (74 loc) · 2.28 KB
/
StrategyWasAdded.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace Pheature\Core\Toggle\Write\Event;
use Pheature\Core\Toggle\Write\FeatureId;
use DatetimeImmutable;
use Pheature\Core\Toggle\Write\Payload;
use Pheature\Core\Toggle\Write\Segment;
use Pheature\Core\Toggle\Write\SegmentId;
use Pheature\Core\Toggle\Write\SegmentType;
use Pheature\Core\Toggle\Write\StrategyId;
use Pheature\Core\Toggle\Write\StrategyType;
/**
* @phpstan-import-type WriteSegment from Segment
*/
final class StrategyWasAdded
{
private string $featureId;
private DatetimeImmutable $occurredAt;
private string $strategyId;
private string $strategyType;
/** @var WriteSegment[] */
private array $segments;
/** @param WriteSegment[] $segments */
public function __construct(
string $featureId,
string $strategyId,
string $strategyType,
array $segments,
DatetimeImmutable $occurredAt
) {
$this->featureId = $featureId;
$this->strategyId = $strategyId;
$this->strategyType = $strategyType;
$this->segments = $segments;
$this->occurredAt = $occurredAt;
}
/** @param WriteSegment[] $segments */
public static function occur(string $featureId, string $strategyId, string $strategyType, array $segments): self
{
return new self($featureId, $strategyId, $strategyType, $segments, new DatetimeImmutable());
}
public function featureId(): FeatureId
{
return FeatureId::fromString($this->featureId);
}
public function strategyId(): StrategyId
{
return StrategyId::fromString($this->strategyId);
}
public function strategyType(): StrategyType
{
return StrategyType::fromString($this->strategyType);
}
public function occurredAt(): DatetimeImmutable
{
return $this->occurredAt;
}
/**
* @return Segment[]
*/
public function segments(): array
{
return array_map(
static function (array $segment): Segment {
return new Segment(
SegmentId::fromString($segment['segment_id']),
SegmentType::fromString($segment['segment_type']),
Payload::fromArray($segment['criteria'])
);
},
$this->segments
);
}
}