-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStatEventBuilder.php
114 lines (94 loc) · 2.55 KB
/
StatEventBuilder.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace Abrouter\Client\Builders;
use Abrouter\Client\DTO\BaseEventDTO;
use Abrouter\Client\DTO\EventDTOInterface;
use Abrouter\Client\DTO\IncrementalEventDTO;
use Abrouter\Client\DTO\SummarizeEventDTO;
class StatEventBuilder
{
private const EVENT_TYPE_INCREMENTAL = 1;
private const EVENT_TYPE_SUMMARIZE = 2;
private ?string $temporaryUserId = null;
private ?string $userId = null;
private ?string $event = null;
private ?string $referrer = null;
private ?array $meta = null;
private ?string $tag = null;
private ?string $ip = null;
private ?string $createdAt = null;
private ?string $value = null;
private int $type = self::EVENT_TYPE_INCREMENTAL;
public function setTemporaryUserId(string $temporaryUserId): self
{
$this->temporaryUserId = $temporaryUserId;
return $this;
}
public function setUserId(string $userId): self
{
$this->userId = $userId;
return $this;
}
public function event(string $event): self
{
$this->event = $event;
return $this;
}
public function setReferrer(string $referrer): self
{
$this->referrer = $referrer;
return $this;
}
public function setTag(string $tag): self
{
$this->tag = $tag;
return $this;
}
public function setMeta(array $meta): self
{
$this->meta = $meta;
return $this;
}
public function setIp(string $ip): self
{
$this->ip = $ip;
return $this;
}
public function setCreatedAt(string $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function setValue($value): self
{
$this->value = (string) $value;
return $this;
}
public function incremental(): self
{
$this->type = self::EVENT_TYPE_INCREMENTAL;
return $this;
}
public function summarize(): self
{
$this->type = self::EVENT_TYPE_SUMMARIZE;
return $this;
}
public function build(): EventDTOInterface
{
$baseEventDTO = new BaseEventDTO(
$this->temporaryUserId,
$this->userId,
$this->event,
$this->tag,
$this->referrer,
$this->meta,
$this->ip,
$this->createdAt
);
if ($this->type === self::EVENT_TYPE_INCREMENTAL) {
return new IncrementalEventDTO($baseEventDTO);
}
return new SummarizeEventDTO($this->value, $baseEventDTO);
}
}