|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Minotaur |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
7
|
|
|
* use this file except in compliance with the License. You may obtain a copy of |
|
8
|
|
|
* the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
15
|
|
|
* License for the specific language governing permissions and limitations under |
|
16
|
|
|
* the License. |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright 2015-2017 Appertly |
|
19
|
|
|
* @license Apache-2.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace Minotaur\Db; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Basic interface for entity services. |
|
25
|
|
|
*/ |
|
26
|
|
|
interface EntityRepo |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Gets the type of entity produced, mainly for ACL reasons. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string The entity type |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getType(): string; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Gets a Map that relates identifier to instance |
|
37
|
|
|
* |
|
38
|
|
|
* @param iterable<mixed> $entities The entities to "zip" |
|
|
|
|
|
|
39
|
|
|
* @return array<string,mixed> The instances keyed by identifier |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getInstanceMap(iterable $entities): array; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Finds a single record by some arbitrary criteria. |
|
45
|
|
|
* |
|
46
|
|
|
* @param array<string,mixed> $criteria Field to value pairs |
|
47
|
|
|
* @return mixed|null The object found or null if none |
|
48
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
49
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the result cannot be returned |
|
50
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
51
|
|
|
*/ |
|
52
|
|
|
public function findOne(array $criteria); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Counts several records by some arbitrary criteria. |
|
56
|
|
|
* |
|
57
|
|
|
* @param array<string,mixed> $criteria Field to value pairs |
|
58
|
|
|
* @return int The count of the documents |
|
59
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
60
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the result cannot be returned |
|
61
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
62
|
|
|
*/ |
|
63
|
|
|
public function countAll(array $criteria): int; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Finds several records by some arbitrary criteria. |
|
67
|
|
|
* |
|
68
|
|
|
* @param array<string,mixed> $criteria Field to value pairs |
|
69
|
|
|
* @param $pagination - Optional pagination parameters |
|
70
|
|
|
* @param bool $totalCount Return a `CursorSubset` that includes the total |
|
71
|
|
|
* number of records. This is only done if `$pagination` is not using |
|
72
|
|
|
* the defaults. |
|
73
|
|
|
* @return iterable<mixed> The objects found or null if none |
|
|
|
|
|
|
74
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
75
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the result cannot be returned |
|
76
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
77
|
|
|
*/ |
|
78
|
|
|
public function findAll(array $criteria, \Caridea\Http\Pagination $pagination = null, bool $totalCount = false): iterable; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Gets a single document by ID. |
|
82
|
|
|
* |
|
83
|
|
|
* @param $id - The document identifier |
|
84
|
|
|
* @return mixed|null The entity, or `null` |
|
85
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
86
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the result cannot be returned |
|
87
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
88
|
|
|
*/ |
|
89
|
|
|
public function findById($id); |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Gets a single document by ID, throwing an exception if it's not found. |
|
93
|
|
|
* |
|
94
|
|
|
* @param $id - The document identifier |
|
95
|
|
|
* @return mixed The entity, never `null`. |
|
96
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
97
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the document doesn't exist |
|
98
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
99
|
|
|
*/ |
|
100
|
|
|
public function get($id); |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Gets several documents by ID. |
|
104
|
|
|
* |
|
105
|
|
|
* @param iterable<mixed> $ids List of identifiers |
|
|
|
|
|
|
106
|
|
|
* @return iterable<mixed> The results |
|
|
|
|
|
|
107
|
|
|
* @throws \Caridea\Dao\Exception\Unreachable If the connection fails |
|
108
|
|
|
* @throws \Caridea\Dao\Exception\Unretrievable If the result cannot be returned |
|
109
|
|
|
* @throws \Caridea\Dao\Exception\Generic If any other database problem occurs |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getAll(iterable $ids): iterable; |
|
112
|
|
|
} |
|
113
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.