CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.3 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.3
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
      • Association
      • Attribute
      • Behavior
      • Exception
      • Locator
      • Query
      • Rule
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ResultSetFactory

Factory class for generating ResultSet instances.

It is responsible for correctly nesting result keys reported from the query and hydrating entities.

Namespace: Cake\ORM

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|null

    Cached 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
void

collectData() ¶ 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): object

getDtoMapper() ¶ public

getDtoMapper(): Cake\ORM\DtoMapper

Get or create the DtoMapper instance.

Returns
Cake\ORM\DtoMapper

getResultSetClass() ¶ 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|array

hydrateDto() ¶ 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
object

setResultSetClass() ¶ 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
$this

Property 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>

$dtoMapper ¶ protected

Cached DtoMapper instance

Type
Cake\ORM\DtoMapper|null

$resultSetClass ¶ protected

Type
class-string<Cake\Datasource\ResultSetInterface<array-key, mixed>>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs