1 | <?php |
||
16 | trait EntitySpecificationRepositoryTrait |
||
17 | { |
||
18 | /** |
||
19 | * @var string alias |
||
20 | */ |
||
21 | private $alias = 'e'; |
||
22 | |||
23 | /** |
||
24 | * Get results when you match with a Specification. |
||
25 | * |
||
26 | * @param Filter|QueryModifier $specification |
||
27 | * @param ResultModifier|null $modifier |
||
28 | * |
||
29 | * @return mixed[] |
||
30 | */ |
||
31 | public function match($specification, ResultModifier $modifier = null) |
||
37 | |||
38 | /** |
||
39 | * Get single result when you match with a Specification. |
||
40 | * |
||
41 | * @param Filter|QueryModifier $specification |
||
42 | * @param ResultModifier|null $modifier |
||
43 | * |
||
44 | * @throw Exception\NonUniqueException If more than one result is found |
||
45 | * @throw Exception\NoResultException If no results found |
||
46 | * |
||
47 | * @return mixed |
||
48 | */ |
||
49 | public function matchSingleResult($specification, ResultModifier $modifier = null) |
||
61 | |||
62 | /** |
||
63 | * Get single result or null when you match with a Specification. |
||
64 | * |
||
65 | * @param Filter|QueryModifier $specification |
||
66 | * @param ResultModifier|null $modifier |
||
67 | * |
||
68 | * @throw Exception\NonUniqueException If more than one result is found |
||
69 | * |
||
70 | * @return mixed|null |
||
71 | */ |
||
72 | public function matchOneOrNullResult($specification, ResultModifier $modifier = null) |
||
80 | |||
81 | /** |
||
82 | * Get single scalar result when you match with a Specification. |
||
83 | * |
||
84 | * @param Filter|QueryModifier $specification |
||
85 | * @param ResultModifier|null $modifier |
||
86 | * |
||
87 | * @throw Exception\NonUniqueException If more than one result is found |
||
88 | * @throw Exception\NoResultException If no results found |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function matchSingleScalarResult($specification, ResultModifier $modifier = null) |
||
102 | |||
103 | /** |
||
104 | * Get scalar result when you match with a Specification. |
||
105 | * |
||
106 | * @param Filter|QueryModifier $specification |
||
107 | * @param ResultModifier|null $modifier |
||
108 | * |
||
109 | * @throw Exception\NonUniqueException If more than one result is found |
||
110 | * @throw Exception\NoResultException If no results found |
||
111 | * |
||
112 | * @return mixed |
||
113 | */ |
||
114 | public function matchScalarResult($specification, ResultModifier $modifier = null) |
||
120 | |||
121 | /** |
||
122 | * Prepare a Query with a Specification. |
||
123 | * |
||
124 | * @param Filter|QueryModifier $specification |
||
125 | * @param ResultModifier|null $modifier |
||
126 | * |
||
127 | * @return Query |
||
128 | */ |
||
129 | public function getQuery($specification, ResultModifier $modifier = null) |
||
139 | |||
140 | /** |
||
141 | * @param Filter|QueryModifier $specification |
||
142 | * @param string|null $alias |
||
143 | * |
||
144 | * @return QueryBuilder |
||
145 | */ |
||
146 | public function getQueryBuilder($specification, $alias = null) |
||
153 | |||
154 | /** |
||
155 | * Iterate results when you match with a Specification. |
||
156 | * |
||
157 | * @param Filter|QueryModifier $specification |
||
158 | * @param ResultModifier|null $modifier |
||
159 | * |
||
160 | * @return mixed[]|\Generator |
||
161 | */ |
||
162 | public function iterate($specification, ResultModifier $modifier = null) |
||
168 | |||
169 | /** |
||
170 | * @param string $alias |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function setAlias($alias) |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function getAlias() |
||
188 | |||
189 | /** |
||
190 | * @param QueryBuilder $queryBuilder |
||
191 | * @param Filter|QueryModifier $specification |
||
192 | * @param string $alias |
||
193 | * |
||
194 | * @throws \InvalidArgumentException |
||
195 | */ |
||
196 | protected function applySpecification(QueryBuilder $queryBuilder, $specification = null, $alias = null) |
||
221 | } |
||
222 |
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.