DoorsRepository.php 2.13 KB
Newer Older
1
2
3
4
5
<?php


namespace Source\Gateways\Doors;

6
use Carbon\Carbon;
7
use Source\Entities\Door;
8
use Source\Entities\HashedSearchable;
9

Jacob Priddy's avatar
Jacob Priddy committed
10
11
interface DoorsRepository
{
12
13
14
    /**
     * Create a new door
     *
Jacob Priddy's avatar
Jacob Priddy committed
15
     * @param \Source\Entities\Door $door
16
     * @return \Source\Entities\Door
Jacob Priddy's avatar
Jacob Priddy committed
17
     * @throws \Source\Exceptions\EntityExistsException
18
     */
Jacob Priddy's avatar
Jacob Priddy committed
19
    public function create(Door $door): Door;
20

Jacob Priddy's avatar
Jacob Priddy committed
21
    /**
22
     * Queries doors, if query is empty or null it gets all doors.
Jacob Priddy's avatar
Jacob Priddy committed
23
     *
24
     * @param string|null $query
Jacob Priddy's avatar
Jacob Priddy committed
25
26
     * @return Door[]
     */
27
    public function search(?string $query = null): array;
Jacob Priddy's avatar
Jacob Priddy committed
28

29
30
31
    /**
     * Attempt to find a door by a token
     *
32
     * @param \Source\Entities\HashedSearchable|null $token
33
34
     * @return Door|null
     */
35
36
    public function getByToken(?HashedSearchable $token): ?Door;

37
38
39
40
41
42
43
    /**
     * @param string         $doorId
     * @param \Carbon\Carbon $seen
     * @param string|null    $version
     */
    public function touch(string $doorId, Carbon $seen, ?string $version): void;

44
45
46
47
48
49
50
    /**
     * Get a door by ID
     *
     * @param string $doorId
     * @return \Source\Entities\Door|null
     */
    public function get(string $doorId): ?Door;
Jacob Priddy's avatar
Jacob Priddy committed
51
52
53
54
55
56

    /**
     * @param string|null $name
     * @return \Source\Entities\Door|null
     */
    public function findByName(?string $name): ?Door;
57
58
59
60

    /**
     * @param string                $doorId
     * @param \Source\Entities\Door $door
61
     * @return \Source\Entities\Door
62
     * @throws \Source\Exceptions\EntityExistsException
Jacob Priddy's avatar
Jacob Priddy committed
63
     * @throws \Source\Exceptions\EntityNotFoundException
64
     */
Jacob Priddy's avatar
Jacob Priddy committed
65
    public function update(string $doorId, Door $door): Door;
Jacob Priddy's avatar
Jacob Priddy committed
66
67
68
69
70

    /**
     * Deletes a door
     *
     * @param string $doorId
Jacob Priddy's avatar
Jacob Priddy committed
71
     * @return int number of doors deleted
Jacob Priddy's avatar
Jacob Priddy committed
72
     */
Jacob Priddy's avatar
Jacob Priddy committed
73
    public function delete(string $doorId): int;
74
75
76
77
78
79
80
81

    /**
     * Checks a door for existence.
     *
     * @param string $doorId
     * @return bool
     */
    public function exists(string $doorId): bool;
82
83
84
85
86
87
88
89

    /**
     * Retrieves doors who have not contacted the API in the last x seconds.
     *
     * @param int $seconds
     * @return \Source\Entities\Door[]
     */
    public function awolFor(int $seconds): array;
90
}