1 | <?php |
||
29 | trait EntitySpecificationRepositoryTrait |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $alias = 'root'; |
||
35 | |||
36 | /** |
||
37 | * Get results when you match with a Specification. |
||
38 | * |
||
39 | * @param Filter|QueryModifier $specification |
||
40 | * @param ResultModifier|null $modifier |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function match($specification, ?ResultModifier $modifier = null) |
||
50 | |||
51 | /** |
||
52 | * Get single result when you match with a Specification. |
||
53 | * |
||
54 | * @param Filter|QueryModifier $specification |
||
55 | * @param ResultModifier|null $modifier |
||
56 | * |
||
57 | * @throw Exception\NonUniqueException If more than one result is found |
||
58 | * @throw Exception\NoResultException If no results found |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function matchSingleResult($specification, ?ResultModifier $modifier = null) |
||
74 | |||
75 | /** |
||
76 | * Get single result or null when you match with a Specification. |
||
77 | * |
||
78 | * @param Filter|QueryModifier $specification |
||
79 | * @param ResultModifier|null $modifier |
||
80 | * |
||
81 | * @throw Exception\NonUniqueException If more than one result is found |
||
82 | * |
||
83 | * @return mixed|null |
||
84 | */ |
||
85 | public function matchOneOrNullResult($specification, ?ResultModifier $modifier = null) |
||
93 | |||
94 | /** |
||
95 | * Get single scalar result when you match with a Specification. |
||
96 | * |
||
97 | * @param Filter|QueryModifier $specification |
||
98 | * @param ResultModifier|null $modifier |
||
99 | * |
||
100 | * @throw Exception\NonUniqueException If more than one result is found |
||
101 | * @throw Exception\NoResultException If no results found |
||
102 | * |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function matchSingleScalarResult($specification, ?ResultModifier $modifier = null) |
||
115 | |||
116 | /** |
||
117 | * Get scalar result when you match with a Specification. |
||
118 | * |
||
119 | * @param Filter|QueryModifier $specification |
||
120 | * @param ResultModifier|null $modifier |
||
121 | * |
||
122 | * @throw Exception\NonUniqueException If more than one result is found |
||
123 | * @throw Exception\NoResultException If no results found |
||
124 | * |
||
125 | * @return mixed |
||
126 | */ |
||
127 | public function matchScalarResult($specification, ?ResultModifier $modifier = null) |
||
133 | |||
134 | /** |
||
135 | * Prepare a Query with a Specification. |
||
136 | * |
||
137 | * @param Filter|QueryModifier $specification |
||
138 | * @param ResultModifier|null $modifier |
||
139 | * |
||
140 | * @return Query |
||
141 | */ |
||
142 | public function getQuery($specification, ?ResultModifier $modifier = null): AbstractQuery |
||
152 | |||
153 | /** |
||
154 | * @param Filter|QueryModifier $specification |
||
155 | * @param string|null $alias |
||
156 | * |
||
157 | * @return QueryBuilder |
||
158 | */ |
||
159 | public function getQueryBuilder($specification, ?string $alias = null): QueryBuilder |
||
166 | |||
167 | /** |
||
168 | * Iterate results when you match with a Specification. |
||
169 | * |
||
170 | * @param Filter|QueryModifier $specification |
||
171 | * @param ResultModifier|null $modifier |
||
172 | * |
||
173 | * @return \Traversable<mixed> |
||
174 | */ |
||
175 | public function iterate($specification, ?ResultModifier $modifier = null): \Traversable |
||
181 | |||
182 | /** |
||
183 | * @param string $alias |
||
184 | */ |
||
185 | public function setAlias(string $alias): void |
||
189 | |||
190 | /** |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getAlias(): string |
||
197 | |||
198 | /** |
||
199 | * @param QueryBuilder $queryBuilder |
||
200 | * @param Filter|QueryModifier $specification |
||
201 | * @param string|null $alias |
||
202 | * |
||
203 | * @throws \InvalidArgumentException |
||
204 | */ |
||
205 | protected function applySpecification( |
||
223 | } |
||
224 |
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.