Skip to content

Commit

Permalink
Merge pull request #16 from recognizegroup/override-loader-methods
Browse files Browse the repository at this point in the history
Allow overriding AbstractEntityLoader methods
  • Loading branch information
wslaghekke authored Nov 15, 2024
2 parents a49b6b2 + 31d76ca commit a977060
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
20 changes: 10 additions & 10 deletions Loader/AbstractEntityLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ abstract class AbstractEntityLoader implements EntityLoaderInterface
'eq' => '='
];

private const ENTITY_ALIAS = 'entity';
protected const ENTITY_ALIAS = 'entity';

/** @var ObjectManager */
protected $entityManager;

/** @var PropertyAccessor */
private $propertyAccessor;
protected $propertyAccessor;

/** @var string */
private $protocolVersion;
protected $protocolVersion;

/** @var DataPipelineService */
private $dataPipelineService;
protected $dataPipelineService;

/**
* AbstractEntityLoader constructor.
Expand Down Expand Up @@ -150,7 +150,7 @@ public function applyFilters(QueryBuilder $queryBuilder, array $filters)
* @param array $filters
* @return array
*/
private function getAllowedFilters(array $filters): array {
protected function getAllowedFilters(array $filters): array {
$availableFilters = $this->getFilters();
$result = [];

Expand All @@ -177,7 +177,7 @@ private function getAllowedFilters(array $filters): array {
* @param RequestFilter $filter
* @param string $parameterName
*/
private function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, RequestFilter $filter, string $parameterName)
protected function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, RequestFilter $filter, string $parameterName)
{
// filters without a field are ignored
if ($baseFilter->getField() === null) {
Expand Down Expand Up @@ -210,7 +210,7 @@ private function applyFilter(QueryBuilder $queryBuilder, Filter $baseFilter, Req
* @param array $usedFilters
* @return array
*/
private function mapList(array $results, array $usedFilters = []): array
protected function mapList(array $results, array $usedFilters = []): array
{
$mapping = $this->getEntityMapping();

Expand All @@ -225,7 +225,7 @@ private function mapList(array $results, array $usedFilters = []): array
* @param array $usedFilters
* @return array
*/
private function mapEntity($entity, EntityMapping $mapping, array $usedFilters = []): array
protected function mapEntity($entity, EntityMapping $mapping, array $usedFilters = []): array
{
$result = [];

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

Expand Down Expand Up @@ -325,7 +325,7 @@ private function mapField($entity, FieldMapping $field, array $usedFilters = [])
* @param BaseOptions $options
* @return QueryBuilder
*/
private function createQueryBuilder(BaseOptions $options): QueryBuilder
protected function createQueryBuilder(BaseOptions $options): QueryBuilder
{
/** @var EntityRepository $repository */
$repository = $this->entityManager->getRepository($this->getEntityType());
Expand Down
18 changes: 14 additions & 4 deletions Service/DocumentationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,32 @@ private function addSchema(string $name, EntityMapping $mapping, array &$compone
}
}

$newSchema = new OASv3\Schema(['properties' => $properties]);

// try to find a name that has not been used yet
if (isset($components[$name])) {
$appendix = 2;
/** @var OASv3\Schema $existingSchema */
$existingSchema = $components[$name];

if ($existingSchema->toJson() === $newSchema->toJson()) {
// schema already exists, return existing name
return $name;
}

$appendix = 2;
while (true) {
$name = $name.'_'.$appendix;
$newName = $name.'_'.$appendix;

if (!isset($components[$name])) {
if (!isset($components[$newName])) {
$name = $newName;
break;
}

$appendix++;
}
}

$components[$name] = new OASv3\Schema(['properties' => $properties]);
$components[$name] = $newSchema;

return $name;
}
Expand Down

0 comments on commit a977060

Please sign in to comment.