Repository navigation
Expand file tree
/
Copy pathTaskEventList.php
More file actions
91 lines (77 loc) · 2.28 KB
/
Copy pathTaskEventList.php
File metadata and controls
91 lines (77 loc) · 2.28 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace SchedulerBundle\Event;
use Countable;
use SchedulerBundle\Task\ProbeTask;
use function array_filter;
use function count;
/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
final class TaskEventList implements Countable
{
/**
* @var TaskEventInterface[]
*/
private array $events = [];
public function addEvent(TaskEventInterface $taskEvent): void
{
$this->events[] = $taskEvent;
}
/**
* @return TaskEventInterface[]
*/
public function getEvents(): array
{
return $this->events;
}
/**
* @return array<int, TaskScheduledEvent>
*/
public function getScheduledTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskScheduledEvent);
}
/**
* @return array<int, TaskUnscheduledEvent>
*/
public function getUnscheduledTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskUnscheduledEvent);
}
/**
* @return array<int, TaskExecutedEvent>
*/
public function getExecutedTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskExecutedEvent);
}
/**
* @return array<int, TaskFailedEvent>
*/
public function getFailedTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskFailedEvent);
}
/**
* @return array<int, TaskScheduledEvent>
*/
public function getQueuedTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskScheduledEvent && $event->getTask()->isQueued());
}
/**
* @return array<int, TaskScheduledEvent>
*/
public function getProbeTaskEvents(): array
{
return array_filter($this->events, static fn (TaskEventInterface $event): bool => $event instanceof TaskScheduledEvent && $event->getTask() instanceof ProbeTask);
}
/**
* {@inheritdoc}
*/
public function count(): int
{
return count($this->events);
}
}