Class ResultSetFactory
Factory class for generating ResultSet instances.
It is responsible for correctly nesting result keys reported from the query and hydrating entities.
Property Summary
-
$dtoHydrators protected static
array<class-string, callable(array): object>Cached DTO hydrator callables by class name. Avoids method_exists() check on every row.
-
$dtoMapper protected
Cake\ORM\DtoMapper|nullCached DtoMapper instance
-
$resultSetClass protected
class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>>
Method Summary
-
clearDtoHydratorCache() public static
Clear the DTO hydrator cache.
-
collectData() protected
Get repository and its associations data for nesting results key and entity hydration.
-
createResultSet() public
Create a result set instance.
-
getDtoHydrator() public
Get a cached hydrator callable for a DTO class.
-
getDtoMapper() public
Get or create the DtoMapper instance.
-
getResultSetClass() public
Get the ResultSet class to use.
-
groupResult() protected
Correctly nests results keys including those coming from associations.
-
hydrateDto() public
Hydrate a row into a DTO.
-
setResultSetClass() public
Set the ResultSet class to use.
Method Detail
clearDtoHydratorCache() ¶ public static
clearDtoHydratorCache(): void
Clear the DTO hydrator cache.
Useful for testing or when classes are reloaded.
Returns
voidcollectData() ¶ protected
collectData(Cake\ORM\Query\SelectQuery<Cake\Datasource\EntityInterface|array> $query): array{primaryAlias: string, registryAlias: string, entityClass: class-string<Cake\Datasource\EntityInterface>, hydrate: bool, autoFields: (bool|null, matchingColumns: array, dtoClass: (class-string|null, matchingAssoc: array, containAssoc: array, fields: array}
Get repository and its associations data for nesting results key and entity hydration.
Parameters
-
Cake\ORM\Query\SelectQuery<Cake\Datasource\EntityInterface|array>$query The query from where to derive the data.
Returns
array{primaryAlias: string, registryAlias: string, entityClass: class-string<Cake\Datasource\EntityInterface>, hydrate: bool, autoFields: (bool|null, matchingColumns: array, dtoClass: (class-string|null, matchingAssoc: array, containAssoc: array, fields: array}createResultSet() ¶ public
createResultSet(iterable $results, Cake\ORM\Query\SelectQuery<Cake\Datasource\EntityInterface|array>|null $query = null): Cake\Datasource\ResultSetInterface<array-key, mixed>
Create a result set instance.
Parameters
-
iterable$results Results.
-
Cake\ORM\Query\SelectQuery<Cake\Datasource\EntityInterface|array>|null$query optional Query from where results came.
Returns
Cake\Datasource\ResultSetInterface<array-key, mixed>getDtoHydrator() ¶ public
getDtoHydrator(class-string $dtoClass): callable(array): object
Get a cached hydrator callable for a DTO class.
The hydrator is determined once per class and cached to avoid method_exists() checks on every row.
Parameters
-
class-string$dtoClass DTO class name
Returns
callable(array): objectgetDtoMapper() ¶ public
getDtoMapper(): Cake\ORM\DtoMapper
Get or create the DtoMapper instance.
Returns
Cake\ORM\DtoMappergetResultSetClass() ¶ public
getResultSetClass(): class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>>
Get the ResultSet class to use.
Returns
class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>>groupResult() ¶ protected
groupResult(array $row, array $data): Cake\Datasource\EntityInterface|array
Correctly nests results keys including those coming from associations.
Hydrate row array into entity if hydration is enabled.
Parameters
-
array$row Array containing columns and values.
-
array$data Array containing table and query metadata
Returns
Cake\Datasource\EntityInterface|arrayhydrateDto() ¶ public
hydrateDto(array $row, class-string $dtoClass): object
Hydrate a row into a DTO.
Supports two patterns:
- Static
createFromArray($data, $nested)factory method (cakephp-dto style) - Constructor with named parameters (DtoMapper reflection)
Parameters
-
array$row Nested array data
-
class-string$dtoClass DTO class name
Returns
objectsetResultSetClass() ¶ public
setResultSetClass(class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>> $resultSetClass): $this
Set the ResultSet class to use.
Parameters
-
class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>>$resultSetClass Class name.
Returns
$thisProperty Detail
$dtoHydrators ¶ protected static
Cached DTO hydrator callables by class name. Avoids method_exists() check on every row.
Type
array<class-string, callable(array): object>