-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathEntityRepository.php
More file actions
498 lines (424 loc) · 26.5 KB
/
EntityRepository.php
File metadata and controls
498 lines (424 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Orm;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\FieldMapping;
use Doctrine\ORM\Query\Expr\Orx;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\SearchMode;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityRepositoryInterface;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Provider\AdminContextProviderInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDataDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntitySearchEvent;
use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
use EasyCorp\Bundle\EasyAdminBundle\Factory\FormFactory;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\ComparisonType;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class EntityRepository implements EntityRepositoryInterface
{
public function __construct(
private readonly AdminContextProviderInterface $adminContextProvider,
private readonly ManagerRegistry $doctrine,
private readonly EntityFactory $entityFactory,
private readonly FormFactory $formFactory,
private readonly EventDispatcherInterface $eventDispatcher,
) {
}
public function createQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->doctrine->getManagerForClass($entityDto->getFqcn());
$queryBuilder = $entityManager->createQueryBuilder()
->select('entity')
->from($entityDto->getFqcn(), 'entity')
;
if ('' !== $searchDto->getQuery()) {
try {
$databasePlatform = $entityManager->getConnection()->getDatabasePlatform();
} catch (\Throwable) {
$databasePlatform = null;
}
$databasePlatformFqcn = null !== $databasePlatform ? $databasePlatform::class : '';
$this->addSearchClause($queryBuilder, $searchDto, $entityDto, $databasePlatformFqcn);
}
$appliedFilters = $searchDto->getAppliedFilters();
if (null !== $appliedFilters && 0 !== \count($appliedFilters)) {
$this->addFilterClause($queryBuilder, $searchDto, $entityDto, $filters, $fields);
}
$this->addOrderClause($queryBuilder, $searchDto, $entityDto, $fields);
return $queryBuilder;
}
private function addSearchClause(QueryBuilder $queryBuilder, SearchDto $searchDto, EntityDto $entityDto, string $databasePlatformFqcn): void
{
$isPostgreSql = PostgreSQLPlatform::class === $databasePlatformFqcn || is_subclass_of($databasePlatformFqcn, PostgreSQLPlatform::class);
$searchablePropertiesConfig = $this->getSearchablePropertiesConfig($queryBuilder, $searchDto, $entityDto);
$queryTerms = $searchDto->getQueryTerms();
$queryTermIndex = 0;
foreach ($queryTerms as $queryTerm) {
++$queryTermIndex;
$lowercaseQueryTerm = mb_strtolower($queryTerm);
$isNumericQueryTerm = is_numeric($queryTerm);
$isSmallIntegerQueryTerm = ctype_digit($queryTerm) && $queryTerm >= -32768 && $queryTerm <= 32767;
$isIntegerQueryTerm = ctype_digit($queryTerm) && $queryTerm >= -2147483648 && $queryTerm <= 2147483647;
$isUuidQueryTerm = Uuid::isValid($queryTerm);
$isUlidQueryTerm = Ulid::isValid($queryTerm);
$dqlParameters = [
// adding '0' turns the string into a numeric value
'numeric_query' => is_numeric($queryTerm) ? 0 + $queryTerm : $queryTerm,
'uuid_query' => $queryTerm,
'text_query' => '%'.$lowercaseQueryTerm.'%',
];
$queryTermConditions = new Orx();
foreach ($searchablePropertiesConfig as $propertyConfig) {
$entityName = $propertyConfig['entity_name'];
// this complex condition is needed to avoid issues on PostgreSQL databases
if (
($propertyConfig['is_small_integer'] && $isSmallIntegerQueryTerm)
|| ($propertyConfig['is_integer'] && $isIntegerQueryTerm)
|| ($propertyConfig['is_numeric'] && $isNumericQueryTerm)
) {
$parameterName = sprintf('query_for_numbers_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('%s.%s = :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['numeric_query']);
} elseif ($propertyConfig['is_guid'] && $isUuidQueryTerm) {
$parameterName = sprintf('query_for_uuids_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('%s.%s = :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['uuid_query'], 'uuid' === $propertyConfig['property_data_type'] ? 'uuid' : null);
} elseif ($propertyConfig['is_ulid'] && $isUlidQueryTerm) {
$parameterName = sprintf('query_for_ulids_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('%s.%s = :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['uuid_query'], 'ulid');
} elseif ($propertyConfig['is_text']) {
$parameterName = sprintf('query_for_text_%d', $queryTermIndex);
// concatenating an empty string is needed to avoid issues on PostgreSQL databases (https://github.com/EasyCorp/EasyAdminBundle/issues/6290)
$queryTermConditions->add(sprintf('LOWER(CONCAT(%s.%s, \'\')) LIKE :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['text_query']);
} elseif ($propertyConfig['is_json'] && !$isPostgreSql) {
// neither LOWER() nor LIKE() are supported for JSON columns by all PostgreSQL installations
$parameterName = sprintf('query_for_text_%d', $queryTermIndex);
$queryTermConditions->add(sprintf('LOWER(%s.%s) LIKE :%s', $entityName, $propertyConfig['property_name'], $parameterName));
$queryBuilder->setParameter($parameterName, $dqlParameters['text_query']);
}
}
// When no fields are queried, the current condition must not yield any results
if (0 === $queryTermConditions->count()) {
$queryTermConditions->add('0 = 1');
}
if (SearchMode::ALL_TERMS === $searchDto->getSearchMode()) {
$queryBuilder->andWhere($queryTermConditions);
} else {
$queryBuilder->orWhere($queryTermConditions);
}
}
$this->eventDispatcher->dispatch(new AfterEntitySearchEvent($queryBuilder, $searchDto, $entityDto));
}
private function addOrderClause(QueryBuilder $queryBuilder, SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields): void
{
foreach ($searchDto->getSort() as $sortProperty => $sortOrder) {
$aliases = $queryBuilder->getAllAliases();
$sortFieldIsDoctrineAssociation = $this->isAssociation($entityDto, $sortProperty);
if ($sortFieldIsDoctrineAssociation) {
$sortFieldParts = explode('.', $sortProperty, 2);
// check if join has been added once before.
if (!\in_array($sortFieldParts[0], $aliases, true)) {
$queryBuilder->leftJoin('entity.'.$sortFieldParts[0], $sortFieldParts[0]);
}
if (1 === \count($sortFieldParts)) {
if ($entityDto->getClassMetadata()->isCollectionValuedAssociation($sortProperty)) {
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->doctrine->getManagerForClass($entityDto->getFqcn());
$countQueryBuilder = $entityManager->createQueryBuilder();
if (ClassMetadata::MANY_TO_MANY === $entityDto->getClassMetadata()->getAssociationMapping($sortProperty)['type']) {
// many-to-many relation
$countQueryBuilder
->select($queryBuilder->expr()->count('subQueryEntity'))
->from($entityDto->getFqcn(), 'subQueryEntity')
->join(sprintf('subQueryEntity.%s', $sortProperty), 'relatedEntity')
->where('subQueryEntity = entity');
} else {
// one-to-many relation
$countQueryBuilder
->select($queryBuilder->expr()->count('subQueryEntity'))
->from($entityDto->getClassMetadata()->getAssociationTargetClass($sortProperty), 'subQueryEntity')
->where(sprintf('subQueryEntity.%s = entity', $entityDto->getClassMetadata()->getAssociationMapping($sortProperty)['mappedBy']));
}
$queryBuilder->addSelect(sprintf('(%s) as HIDDEN sub_query_sort', $countQueryBuilder->getDQL()));
$queryBuilder->addOrderBy('sub_query_sort', $sortOrder);
$queryBuilder->addOrderBy('entity.'.$entityDto->getClassMetadata()->getSingleIdentifierFieldName(), $sortOrder);
} else {
$field = $fields->getByProperty($sortProperty);
$associationSortProperty = $field?->getCustomOption(AssociationField::OPTION_SORT_PROPERTY);
if (null === $associationSortProperty) {
$queryBuilder->addOrderBy('entity.'.$sortProperty, $sortOrder);
} else {
$queryBuilder->addOrderBy($sortProperty.'.'.$associationSortProperty, $sortOrder);
}
}
} else {
$queryBuilder->addOrderBy($sortProperty, $sortOrder);
}
} else {
$queryBuilder->addOrderBy('entity.'.$sortProperty, $sortOrder);
}
}
}
private function addFilterClause(QueryBuilder $queryBuilder, SearchDto $searchDto, EntityDto $entityDto, FilterCollection $configuredFilters, FieldCollection $fields): void
{
$filtersForm = $this->formFactory->createFiltersForm($configuredFilters, $this->adminContextProvider->getContext()->getRequest());
if (!$filtersForm->isSubmitted()) {
return;
}
$appliedFilters = $searchDto->getAppliedFilters();
$i = 0;
foreach ($filtersForm as $filterForm) {
$propertyName = $filterForm->getName();
$filter = $configuredFilters->get($propertyName);
// this filter is not defined or not applied
if (null === $filter || !isset($appliedFilters[$propertyName])) {
continue;
}
// if the form filter is not valid then we should not apply the filter
if (!$filterForm->isValid()) {
continue;
}
$submittedData = $filterForm->getData();
if (!\is_array($submittedData)) {
$submittedData = [
'comparison' => ComparisonType::EQ,
'value' => $submittedData,
];
}
/** @var string $rootAlias */
$rootAlias = current($queryBuilder->getRootAliases());
$filterDataDto = FilterDataDto::new($i, $filter, $rootAlias, $submittedData);
$filter->apply($queryBuilder, $filterDataDto, $fields->getByProperty($propertyName), $entityDto);
++$i;
}
}
/**
* @return array<array{
* entity_name: string,
* property_data_type: string,
* property_name: string,
* is_boolean: bool,
* is_small_integer: bool,
* is_integer: bool,
* is_numeric: bool,
* is_text: bool,
* is_guid: bool,
* is_ulid: bool,
* is_json: bool,
* }>
*/
private function getSearchablePropertiesConfig(QueryBuilder $queryBuilder, SearchDto $searchDto, EntityDto $entityDto): array
{
$searchablePropertiesConfig = [];
$configuredSearchableProperties = $searchDto->getSearchableProperties();
$searchableProperties = (null === $configuredSearchableProperties || 0 === \count($configuredSearchableProperties)) ? $entityDto->getClassMetadata()->getFieldNames() : $configuredSearchableProperties;
$entitiesAlreadyJoined = [];
foreach ($searchableProperties as $propertyName) {
if ($this->isAssociation($entityDto, $propertyName)) {
// support arbitrarily nested associations (e.g. foo.bar.baz.qux)
// and embeddables on associated entities (e.g. foo.bar.embeddable)
$associatedProperties = explode('.', $propertyName);
$numAssociatedProperties = \count($associatedProperties);
if (1 === $numAssociatedProperties) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field. When using associated properties in search, you must also define the exact field used in the search (e.g. \'%s.id\', \'%s.name\', etc.)', $propertyName, $propertyName, $propertyName));
}
$associatedEntityDto = $this->entityFactory->create($entityDto->getClassMetadata()->getAssociationTargetClass($associatedProperties[0]));
$associatedEntityAlias = '';
$embeddableStartIndex = null;
// Join through associations until we hit an embeddable or the end
for ($i = 0; $i < $numAssociatedProperties - 1; ++$i) {
$associatedEntityName = $associatedProperties[$i];
$associatedEntityAlias = $entitiesAlreadyJoined[$associatedEntityName] ?? Escaper::escapeDqlAlias($associatedEntityName).(0 === $i ? '' : $i);
$associatedPropertyName = $associatedProperties[$i + 1];
if (!\in_array($associatedEntityAlias, $entitiesAlreadyJoined, true)) {
$parentEntityName = 0 === $i ? 'entity' : $entitiesAlreadyJoined[$associatedProperties[$i - 1]];
$queryBuilder->leftJoin(Escaper::escapeDqlAlias($parentEntityName).'.'.$associatedEntityName, $associatedEntityAlias);
$entitiesAlreadyJoined[$associatedEntityName] = $associatedEntityAlias;
}
// Check if the next property is an embeddable
if ($i < $numAssociatedProperties - 2 && isset($associatedEntityDto->getClassMetadata()->embeddedClasses[$associatedPropertyName])) {
// We've hit an embeddable, stop joining and handle embeddable path
$embeddableStartIndex = $i + 1;
break;
}
if ($i < $numAssociatedProperties - 2) {
$targetEntity = $associatedEntityDto->getClassMetadata()->getAssociationTargetClass($associatedPropertyName);
$associatedEntityDto = $this->entityFactory->create($targetEntity);
}
}
$entityName = $associatedEntityAlias;
// If we encountered an embeddable in the path, handle it
if (null !== $embeddableStartIndex) {
$embeddablePath = \array_slice($associatedProperties, $embeddableStartIndex);
$numEmbeddableParts = \count($embeddablePath);
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->doctrine->getManagerForClass($associatedEntityDto->getFqcn());
$currentMetadata = $associatedEntityDto->getClassMetadata();
// Navigate through embeddable hierarchy
for ($j = 0; $j < $numEmbeddableParts - 1; ++$j) {
$embeddableName = $embeddablePath[$j];
if (!isset($currentMetadata->embeddedClasses[$embeddableName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid embeddable property.', $propertyName));
}
$embeddableClass = $currentMetadata->embeddedClasses[$embeddableName]['class'];
$currentMetadata = $entityManager->getClassMetadata($embeddableClass);
}
// Get the final field from the embeddable
$finalFieldName = $embeddablePath[$numEmbeddableParts - 1];
if (!isset($currentMetadata->fieldMappings[$finalFieldName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field.', $propertyName));
}
$propertyName = implode('.', $embeddablePath);
$fieldMapping = $currentMetadata->getFieldMapping($finalFieldName);
} else {
// No embeddable in path, handle as regular association field
$associatedPropertyName = $associatedProperties[$numAssociatedProperties - 1];
$propertyName = $associatedPropertyName;
if (!isset($associatedEntityDto->getClassMetadata()->fieldMappings[$propertyName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field. When using associated properties in search, you must also define the exact field used in the search (e.g. \'%s.id\', \'%s.name\', etc.)', $propertyName, $propertyName, $propertyName));
}
$fieldMapping = $associatedEntityDto->getClassMetadata()->getFieldMapping($propertyName);
}
// In Doctrine ORM 2.x, getFieldMapping() returns an array
/** @phpstan-ignore-next-line function.impossibleType */
if (\is_array($fieldMapping)) {
/** @phpstan-ignore-next-line cast.useless */
$fieldMapping = (object) $fieldMapping;
}
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
$propertyDataType = property_exists($fieldMapping, 'type') ? $fieldMapping->type : $fieldMapping['type'];
} elseif (str_contains($propertyName, '.')) {
// support arbitrarily nested embeddables on main entity (e.g. address.location.street)
$embeddablePath = explode('.', $propertyName);
$numEmbeddableParts = \count($embeddablePath);
$currentMetadata = $entityDto->getClassMetadata();
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->doctrine->getManagerForClass($entityDto->getFqcn());
// Navigate through embeddable hierarchy
for ($i = 0; $i < $numEmbeddableParts - 1; ++$i) {
$embeddableName = $embeddablePath[$i];
if (!isset($currentMetadata->embeddedClasses[$embeddableName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid embeddable property.', $propertyName));
}
$embeddableClass = $currentMetadata->embeddedClasses[$embeddableName]['class'];
$currentMetadata = $entityManager->getClassMetadata($embeddableClass);
}
// Get the final field from the embeddable
$finalFieldName = $embeddablePath[$numEmbeddableParts - 1];
if (!isset($currentMetadata->fieldMappings[$finalFieldName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field.', $propertyName));
}
$entityName = 'entity';
$propertyName = implode('.', $embeddablePath);
// In Doctrine ORM 3.x, FieldMapping implements \ArrayAccess; in 4.x it's an object with properties
$fieldMapping = $currentMetadata->getFieldMapping($finalFieldName);
// In Doctrine ORM 2.x, getFieldMapping() returns an array
/** @phpstan-ignore-next-line function.impossibleType */
if (\is_array($fieldMapping)) {
/** @phpstan-ignore-next-line cast.useless */
$fieldMapping = (object) $fieldMapping;
}
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
$propertyDataType = property_exists($fieldMapping, 'type') ? $fieldMapping->type : $fieldMapping['type'];
} else {
$entityName = 'entity';
if (!isset($entityDto->getClassMetadata()->fieldMappings[$propertyName])) {
throw new \InvalidArgumentException(sprintf('The "%s" property included in the setSearchFields() method is not a valid search field. When using associated properties in search, you must also define the exact field used in the search (e.g. \'%s.id\', \'%s.name\', etc.)', $propertyName, $propertyName, $propertyName));
}
// In Doctrine ORM 3.x, FieldMapping implements \ArrayAccess; in 4.x it's an object with properties
$fieldMapping = $entityDto->getClassMetadata()->getFieldMapping($propertyName);
// In Doctrine ORM 2.x, getFieldMapping() returns an array
/** @phpstan-ignore-next-line function.impossibleType */
if (\is_array($fieldMapping)) {
/** @phpstan-ignore-next-line cast.useless */
$fieldMapping = (object) $fieldMapping;
}
/** @phpstan-ignore-next-line function.alreadyNarrowedType */
$propertyDataType = property_exists($fieldMapping, 'type') ? $fieldMapping->type : $fieldMapping['type'];
}
$isBoolean = 'boolean' === $propertyDataType;
$isSmallIntegerProperty = 'smallint' === $propertyDataType;
$isIntegerProperty = 'integer' === $propertyDataType;
$isNumericProperty = \in_array($propertyDataType, ['number', 'bigint', 'decimal', 'float'], true);
// 'citext' is a PostgreSQL extension (https://github.com/EasyCorp/EasyAdminBundle/issues/2556)
$isTextProperty = \in_array($propertyDataType, ['ascii_string', 'string', 'text', 'citext', 'array', 'simple_array'], true);
$isGuidProperty = \in_array($propertyDataType, ['guid', 'uuid'], true);
$isUlidProperty = 'ulid' === $propertyDataType;
$isJsonProperty = 'json' === $propertyDataType;
if (!$isBoolean
&& !$isSmallIntegerProperty
&& !$isIntegerProperty
&& !$isNumericProperty
&& !$isTextProperty
&& !$isGuidProperty
&& !$isUlidProperty
&& !$isJsonProperty
) {
$entityFqcn = 'entity' !== $entityName && isset($associatedEntityDto)
? $associatedEntityDto->getFqcn()
: $entityDto->getFqcn()
;
/** @var \ReflectionNamedType|\ReflectionUnionType|null $idClassType */
$idClassType = null;
$reflectionClass = new \ReflectionClass($entityFqcn);
// this is needed to handle inherited properties
while (false !== $reflectionClass) {
if ($reflectionClass->hasProperty($propertyName)) {
$reflection = $reflectionClass->getProperty($propertyName);
$idClassType = $reflection->getType();
break;
}
$reflectionClass = $reflectionClass->getParentClass();
}
if (null !== $idClassType) {
/** @var \ReflectionNamedType|\ReflectionUnionType $idClassType */
$idClassName = $idClassType->getName();
if (class_exists($idClassName)) {
$isUlidProperty = (new \ReflectionClass($idClassName))->isSubclassOf(Ulid::class);
$isGuidProperty = (new \ReflectionClass($idClassName))->isSubclassOf(Uuid::class);
}
}
}
$searchablePropertiesConfig[] = [
'entity_name' => $entityName,
'property_data_type' => $propertyDataType,
'property_name' => $propertyName,
'is_boolean' => $isBoolean,
'is_small_integer' => $isSmallIntegerProperty,
'is_integer' => $isIntegerProperty,
'is_numeric' => $isNumericProperty,
'is_text' => $isTextProperty,
'is_guid' => $isGuidProperty,
'is_ulid' => $isUlidProperty,
'is_json' => $isJsonProperty,
];
}
return $searchablePropertiesConfig;
}
private function isAssociation(EntityDto $entityDto, string $propertyName): bool
{
if ($entityDto->getClassMetadata()->hasAssociation($propertyName)) {
return true;
}
if (!str_contains($propertyName, '.')) {
return false;
}
$propertyNameParts = explode('.', $propertyName, 2);
return !isset($entityDto->getClassMetadata()->embeddedClasses[$propertyNameParts[0]]);
}
}