Skip to content

Commit a977060

Browse files
authored
Merge pull request #16 from recognizegroup/override-loader-methods
Allow overriding AbstractEntityLoader methods
2 parents a49b6b2 + 31d76ca commit a977060

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Loader/AbstractEntityLoader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ abstract class AbstractEntityLoader implements EntityLoaderInterface
3939
'eq' => '='
4040
];
4141

42-
private const ENTITY_ALIAS = 'entity';
42+
protected const ENTITY_ALIAS = 'entity';
4343

4444
/** @var ObjectManager */
4545
protected $entityManager;
4646

4747
/** @var PropertyAccessor */
48-
private $propertyAccessor;
48+
protected $propertyAccessor;
4949

5050
/** @var string */
51-
private $protocolVersion;
51+
protected $protocolVersion;
5252

5353
/** @var DataPipelineService */
54-
private $dataPipelineService;
54+
protected $dataPipelineService;
5555

5656
/**
5757
* AbstractEntityLoader constructor.
@@ -150,7 +150,7 @@ public function applyFilters(QueryBuilder $queryBuilder, array $filters)
150150
* @param array $filters
151151
* @return array
152152
*/
153-
private function getAllowedFilters(array $filters): array {
153+
protected function getAllowedFilters(array $filters): array {
154154
$availableFilters = $this->getFilters();
155155
$result = [];
156156

@@ -177,7 +177,7 @@ private function getAllowedFilters(array $filters): array {
177177
* @param RequestFilter $filter
178178
* @param string $parameterName
179179
*/
180-
private function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, RequestFilter $filter, string $parameterName)
180+
protected function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, RequestFilter $filter, string $parameterName)
181181
{
182182
// filters without a field are ignored
183183
if ($baseFilter->getField() === null) {
@@ -210,7 +210,7 @@ private function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, Req
210210
* @param array $usedFilters
211211
* @return array
212212
*/
213-
private function mapList(array $results, array $usedFilters = []): array
213+
protected function mapList(array $results, array $usedFilters = []): array
214214
{
215215
$mapping = $this->getEntityMapping();
216216

@@ -225,7 +225,7 @@ private function mapList(array $results, array $usedFilters = []): array
225225
* @param array $usedFilters
226226
* @return array
227227
*/
228-
private function mapEntity($entity, EntityMapping $mapping, array $usedFilters = []): array
228+
protected function mapEntity($entity, EntityMapping $mapping, array $usedFilters = []): array
229229
{
230230
$result = [];
231231

@@ -247,7 +247,7 @@ private function mapEntity($entity, EntityMapping $mapping, array $usedFilters =
247247
* @param array $usedFilters
248248
* @return array|mixed|null
249249
*/
250-
private function mapField($entity, FieldMapping $field, array $usedFilters = []) {
250+
protected function mapField($entity, FieldMapping $field, array $usedFilters = []) {
251251
$name = $field->getName();
252252
$type = $field->getType();
253253

@@ -325,7 +325,7 @@ private function mapField($entity, FieldMapping $field, array $usedFilters = [])
325325
* @param BaseOptions $options
326326
* @return QueryBuilder
327327
*/
328-
private function createQueryBuilder(BaseOptions $options): QueryBuilder
328+
protected function createQueryBuilder(BaseOptions $options): QueryBuilder
329329
{
330330
/** @var EntityRepository $repository */
331331
$repository = $this->entityManager->getRepository($this->getEntityType());

Service/DocumentationService.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,32 @@ private function addSchema(string $name, EntityMapping $mapping, array &$compone
256256
}
257257
}
258258

259+
$newSchema = new OASv3\Schema(['properties' => $properties]);
260+
259261
// try to find a name that has not been used yet
260262
if (isset($components[$name])) {
261-
$appendix = 2;
263+
/** @var OASv3\Schema $existingSchema */
264+
$existingSchema = $components[$name];
262265

266+
if ($existingSchema->toJson() === $newSchema->toJson()) {
267+
// schema already exists, return existing name
268+
return $name;
269+
}
270+
271+
$appendix = 2;
263272
while (true) {
264-
$name = $name.'_'.$appendix;
273+
$newName = $name.'_'.$appendix;
265274

266-
if (!isset($components[$name])) {
275+
if (!isset($components[$newName])) {
276+
$name = $newName;
267277
break;
268278
}
269279

270280
$appendix++;
271281
}
272282
}
273283

274-
$components[$name] = new OASv3\Schema(['properties' => $properties]);
284+
$components[$name] = $newSchema;
275285

276286
return $name;
277287
}

0 commit comments

Comments
 (0)