InMemoryDoorScheduleRepository.php 1.09 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
<?php


namespace Source\Gateways\DoorSchedule;

Jacob Priddy's avatar
Jacob Priddy committed
6
use Carbon\Carbon;
Jacob Priddy's avatar
Jacob Priddy committed
7
8
9
10
11
use Source\Entities\Schedule;

class InMemoryDoorScheduleRepository implements DoorScheduleRepository
{
    /**
12
     * @var array
Jacob Priddy's avatar
Jacob Priddy committed
13
     */
14
    protected array $doorScheduleMap = [];
Jacob Priddy's avatar
Jacob Priddy committed
15

16
    public function attachScheduleToDoor(string $doorId, Schedule $schedule): void
Jacob Priddy's avatar
Jacob Priddy committed
17
    {
18
19
20
21
22
        if (isset($this->doorScheduleMap[$doorId])) {
            $this->doorScheduleMap[$doorId][] = $schedule;
        } else {
            $this->doorScheduleMap[$doorId] = [$schedule];
        }
Jacob Priddy's avatar
Jacob Priddy committed
23
24
25
26
27
28
29
    }

    /**
     * @inheritDoc
     */
    public function getActiveSchedulesForDoor(string $doorId): array
    {
30
31
        if (!isset($this->doorScheduleMap[$doorId])) {
            return [];
Jacob Priddy's avatar
Jacob Priddy committed
32
33
        }

34
        return $this->doorScheduleMap[$doorId];
Jacob Priddy's avatar
Jacob Priddy committed
35
    }
Jacob Priddy's avatar
Jacob Priddy committed
36
37
38
39

    /**
     * @inheritDoc
     */
40
    public function getSchedulesForDoorBetween(string $doorId, Carbon $begin, Carbon $end, int $type = Schedule::TYPE_OPEN_MODE): array
Jacob Priddy's avatar
Jacob Priddy committed
41
42
43
44
45
46
47
    {
        if (!isset($this->doorScheduleMap[$doorId])) {
            return [];
        }

        return $this->doorScheduleMap[$doorId];
    }
Jacob Priddy's avatar
Jacob Priddy committed
48
}