Skip to content

Loader

  • Full name: \Zemit\Mvc\Model\EagerLoading\Loader
  • This class is marked as final and can't be subclassed
  • This class is a Final class

Constants

Constant Visibility Type Value
E_INVALID_SUBJECT private 'Expected value of subject to be either a ModelInterface object, a Simple object or an array of ModelInterface objects.'
E_INVALID_CLASSNAME private 'Expected value of className to be either an existing class name.'

Properties

subject

public ?array $subject

className

public string $className

eagerLoads

public array $eagerLoads

singleModel

public bool $singleModel

options

public array $options

Methods

__construct

Constructs a new instance of the class.

public __construct(mixed $from, array $arguments): mixed

Parameters:

Parameter Type Description
$from mixed The data source from which to load the data. Can be an instance of ModelInterface,
Simple, array, null, or boolean.
$arguments array Optional arguments for eager loading. Each argument should be an array
specifying the relationships to eager load.

Throws:

If the supplied data source is invalid.


setOptions

Sets the options for the current object instance.

public setOptions(array $options = []): $this

Parameters:

Parameter Type Description
$options array An array of options for the current object.

Return Value:

The current object instance after setting the options.


setSubject

Sets the subject of the object.

public setSubject(array|null $subject): $this

Parameters:

Parameter Type Description
$subject **array null**

Return Value:

The current object instance with the subject set.


getSubject

Gets the subject

public getSubject(): \Phalcon\Mvc\ModelInterface[]|null

Return Value:

The subject, or null if it has not been set.


getFirstSubject

Retrieves the first element from the subject array and returns it.

public getFirstSubject(): \Phalcon\Mvc\ModelInterface|null

Return Value:

The first element from the subject array, or null if the array is empty.


from

Creates an instance of the current object from various input types and returns it.

public static from(mixed $subject, mixed $arguments): array|\Phalcon\Mvc\ModelInterface|null
  • This method is static.

Parameters:

Parameter Type Description
$subject mixed The input object or array to create the instance from.
$arguments mixed Additional arguments that can be passed to the creation process.

Return Value:

The current object instance created from the input.


fromModel

Create and get from a Model

public static fromModel(\Phalcon\Mvc\ModelInterface $subject, mixed $arguments): ?\Phalcon\Mvc\ModelInterface
  • This method is static.

Parameters:

Parameter Type Description
$subject \Phalcon\Mvc\ModelInterface
$arguments mixed

fromArray

Create and get from an array

public static fromArray(\Phalcon\Mvc\ModelInterface[] $subject, mixed $arguments): array
  • This method is static.

Parameters:

Parameter Type Description
$subject \Phalcon\Mvc\ModelInterface[]
$arguments mixed

fromModelWithoutSoftDelete

Create and get from a Model without soft deleted records

public static fromModelWithoutSoftDelete(\Phalcon\Mvc\ModelInterface $subject, mixed $arguments): ?\Phalcon\Mvc\ModelInterface
  • This method is static.

Parameters:

Parameter Type Description
$subject \Phalcon\Mvc\ModelInterface
$arguments mixed

fromArrayWithoutSoftDelete

Create and get from an array without soft deleted records

public static fromArrayWithoutSoftDelete(\Phalcon\Mvc\ModelInterface[] $subject, mixed $arguments): array
  • This method is static.

Parameters:

Parameter Type Description
$subject \Phalcon\Mvc\ModelInterface[]
$arguments mixed

fromResultset

Create and get from a Resultset

public static fromResultset(\Phalcon\Mvc\Model\ResultsetInterface $subject, mixed $arguments): array
  • This method is static.

Parameters:

Parameter Type Description
$subject \Phalcon\Mvc\Model\ResultsetInterface
$arguments mixed

parseArguments

Parses the arguments that will be resolved to Relation instances

private static parseArguments(array $arguments): array
  • This method is static.

Parameters:

Parameter Type Description
$arguments array

Throws:


addEagerLoad

Adds an eager load for a given relation alias and optional constraints and returns an instance of the current object.

public addEagerLoad(string $relationAlias, callable|null $constraints = null): $this

Parameters:

Parameter Type Description
$relationAlias string The alias of the relation to be eagerly loaded.
$constraints **callable null**

Return Value:

The current object instance after adding the eager load.


buildTree

Resolves the relations

private buildTree(): \Zemit\Mvc\Model\EagerLoading\EagerLoad[]

Throws:


execute

Execute the eager loading of related models.

public execute(): self

This method iterates through the result of the buildTree method and loads the related models using the load method of each eager load instance.

Return Value:

The instance of the class executing the method.


load

Loads the data from a data source and returns an instance of the current object.

public load(): $this

Return Value:

The current object instance after loading the data.