1 | <?php |
||
31 | trait EntitySpecificationRepositoryTrait |
||
32 | { |
||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $alias = 'root'; |
||
37 | |||
38 | /** |
||
39 | * Get results when you match with a Specification. |
||
40 | * |
||
41 | * @param Filter|QueryModifier $specification |
||
42 | * @param ResultModifier|null $modifier |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function match($specification, ?ResultModifier $modifier = null) |
||
52 | |||
53 | /** |
||
54 | * Get single result when you match with a Specification. |
||
55 | * |
||
56 | * @param Filter|QueryModifier $specification |
||
57 | * @param ResultModifier|null $modifier |
||
58 | * |
||
59 | * @throw Exception\NonUniqueException If more than one result is found |
||
60 | * @throw Exception\NoResultException If no results found |
||
61 | * |
||
62 | * @return mixed |
||
63 | */ |
||
64 | public function matchSingleResult($specification, ?ResultModifier $modifier = null) |
||
76 | |||
77 | /** |
||
78 | * Get single result or null when you match with a Specification. |
||
79 | * |
||
80 | * @param Filter|QueryModifier $specification |
||
81 | * @param ResultModifier|null $modifier |
||
82 | * |
||
83 | * @throw Exception\NonUniqueException If more than one result is found |
||
84 | * |
||
85 | * @return mixed|null |
||
86 | */ |
||
87 | public function matchOneOrNullResult($specification, ?ResultModifier $modifier = null) |
||
95 | |||
96 | /** |
||
97 | * Get single scalar result when you match with a Specification. |
||
98 | * |
||
99 | * @param Filter|QueryModifier $specification |
||
100 | * @param ResultModifier|null $modifier |
||
101 | * |
||
102 | * @throw Exception\NonUniqueException If more than one result is found |
||
103 | * @throw Exception\NoResultException If no results found |
||
104 | * |
||
105 | * @return mixed |
||
106 | */ |
||
107 | public function matchSingleScalarResult($specification, ?ResultModifier $modifier = null) |
||
117 | |||
118 | /** |
||
119 | * Get scalar result when you match with a Specification. |
||
120 | * |
||
121 | * @param Filter|QueryModifier $specification |
||
122 | * @param ResultModifier|null $modifier |
||
123 | * |
||
124 | * @throw Exception\NonUniqueException If more than one result is found |
||
125 | * @throw Exception\NoResultException If no results found |
||
126 | * |
||
127 | * @return mixed |
||
128 | */ |
||
129 | public function matchScalarResult($specification, ?ResultModifier $modifier = null) |
||
135 | |||
136 | /** |
||
137 | * Prepare a Query with a Specification. |
||
138 | * |
||
139 | * @param Filter|QueryModifier $specification |
||
140 | * @param ResultModifier|null $modifier |
||
141 | * |
||
142 | * @return Query |
||
143 | */ |
||
144 | public function getQuery($specification, ?ResultModifier $modifier = null): AbstractQuery |
||
154 | |||
155 | /** |
||
156 | * @param Filter|QueryModifier $specification |
||
157 | * @param string|null $alias |
||
158 | * |
||
159 | * @return QueryBuilder |
||
160 | */ |
||
161 | public function getQueryBuilder($specification, ?string $alias = null): QueryBuilder |
||
168 | |||
169 | /** |
||
170 | * Iterate results when you match with a Specification. |
||
171 | * |
||
172 | * @param Filter|QueryModifier $specification |
||
173 | * @param ResultModifier|null $modifier |
||
174 | * |
||
175 | * @return \Traversable<mixed> |
||
176 | */ |
||
177 | public function iterate($specification, ?ResultModifier $modifier = null): \Traversable |
||
183 | |||
184 | /** |
||
185 | * @param string $alias |
||
186 | */ |
||
187 | public function setAlias(string $alias): void |
||
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getAlias(): string |
||
199 | |||
200 | /** |
||
201 | * @param QueryBuilder $queryBuilder |
||
202 | * @param Filter|QueryModifier $specification |
||
203 | * @param string|null $alias |
||
204 | * |
||
205 | * @throws \InvalidArgumentException |
||
206 | */ |
||
207 | protected function applySpecification( |
||
225 | } |
||
226 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.