1 | <?php |
||
13 | abstract class AbstractSqlRepository implements RepositoryInterface |
||
14 | { |
||
15 | use CollectionBuilderTrait; |
||
16 | use QueryStringParserTrait; |
||
17 | |||
18 | /** |
||
19 | * @var \Percy\Dbal\DbalInterface |
||
20 | */ |
||
21 | protected $dbal; |
||
22 | |||
23 | /** |
||
24 | * Construct. |
||
25 | * |
||
26 | * @param \Percy\Dbal\DbalInterface $dbal |
||
27 | */ |
||
28 | 2 | public function __construct(DbalInterface $dbal) |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 1 | public function countFromRequest(ServerRequestInterface $request) |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 1 | public function getFromRequest(ServerRequestInterface $request) |
|
66 | |||
67 | /** |
||
68 | * Build a base query without sorting and limits from filter rules. |
||
69 | * |
||
70 | * @param array $rules |
||
71 | * @param string $start |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 1 | protected function buildQueryFromRules(array $rules, $start = 'SELECT * FROM ') |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 1 | public function countByField($field, $value) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 1 | public function getByField($field, $value) |
|
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function attachRelationships(Collection $collection, array $relationships = []) |
||
132 | |||
133 | /** |
||
134 | * Attach relationships to a specific entity. |
||
135 | * |
||
136 | * @param string $entityType |
||
137 | * @param string $relationship |
||
138 | * @param \Percy\Entity\EntityInterface $entity |
||
139 | * |
||
140 | * @throws \RuntimeException when relationship has not been properly defined |
||
141 | * |
||
142 | * @return void |
||
143 | */ |
||
144 | protected function attachEntityRelationships($entityType, $relationship, EntityInterface $entity) |
||
174 | |||
175 | /** |
||
176 | * Get possible relationships and the properties attached to them. |
||
177 | * |
||
178 | * @return array |
||
179 | */ |
||
180 | abstract protected function getRelationshipMap(); |
||
181 | |||
182 | /** |
||
183 | * Returns table that repository is reading from. |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | abstract protected function getTable(); |
||
188 | } |
||
189 |