com\setasign\Konquadrat\Object

SmartObjectSet Class SmartObjectSet

File: /Konquadrat/src/Object/SmartObjectSet.php

A smart object set will use smart/lazy eager loading to solve the n+1 problem instead of eager loading of the ObjectSet.

The smart object set will completely ignore already existing instances of objects and don't use any instance pool. Every object created by a smart object set is unique and not shared.

Class hierarchy

Implements

Summary

Constants

SOURCE_CHILDS

private const SmartObjectSet::SOURCE_CHILDS = 'childs'

SOURCE_FILTER

private const SmartObjectSet::SOURCE_FILTER = 'filter'

SOURCE_FORK

private const SmartObjectSet::SOURCE_FORK = 'fork'

SOURCE_PARENT

private const SmartObjectSet::SOURCE_PARENT = 'parent'

SOURCE_REFERENCE

private const SmartObjectSet::SOURCE_REFERENCE = 'reference'

SOURCE_REFERENCING

private const SmartObjectSet::SOURCE_REFERENCING = 'referencing'

Properties

$actualScope

protected int[] AbstractObjectSet::$actualScope = array()

The ids of the actual run throw

$childFinder

$filter

$isFork

private SmartObjectSet::$isFork = false

$magicResolver

$magicWithParamResolver

$objectConfig

$objectData

protected array<int, array> AbstractObjectSet::$objectData = array()

Array with all objectData from this objectSet

Key => id
Value => data

$objectFactory

$objectFinder

$objectSetFactory

$parentObjectSet

$permissionControl

$position

Cursor for the iterator

$referenceFinder

$referencing

protected AbstractObjectSet::$referencing = array()

Array with information about referencing objects

  • Key => reference target id
  • Value => Array:
    • Key => Type
    • Value => Array:
      • Key => Field
      • Value => Array(ids)

$referencingObjectsFinder

$source

$sourcePayload


Methods

__construct()

public SmartObjectSet::__construct (
ObjectSet\ObjectSetFactoryInterface $objectSetFactory,
ObjectSet\ReferenceFinder $referenceFinder,
ObjectSet\ChildFinder $childFinder,
ObjectSet\MagicResolver $magicResolver,
ObjectSet\MagicWithParamResolver $magicWithParamResolver,
ObjectSet\ReferencingObjectsFinder $referencingObjectsFinder,
ObjectSet\Filter $filter,
ObjectSet\Sorter $sorter,
ObjectSet\Reloader $reloader,
ObjectConfig $objectConfig,
ObjectFinder $objectFinder,
ObjectFactoryInterface $objectFactory,
?\com\setasign\Konquadrat\Permission\PermissionControl $permissionControl = null,
array $data = array ( ),
?SmartObjectSet $parentObjectSet = null,
?string $sourceType = null,
?array $sourcePayload = null
)

ObjectSet constructor.

Parameters
$objectSetFactory : ObjectSet\ObjectSetFactoryInterface
 
$referenceFinder : ObjectSet\ReferenceFinder
 
$childFinder : ObjectSet\ChildFinder
 
$magicResolver : ObjectSet\MagicResolver
 
$magicWithParamResolver : ObjectSet\MagicWithParamResolver
 
$referencingObjectsFinder : ObjectSet\ReferencingObjectsFinder
 
$filter : ObjectSet\Filter
 
$sorter : ObjectSet\Sorter
 
$reloader : ObjectSet\Reloader
 
$objectConfig : ObjectConfig
 
$objectFinder : ObjectFinder
 
$objectFactory : ObjectFactoryInterface
 
$permissionControl : ?\com\setasign\Konquadrat\Permission\PermissionControl
 
$data : array
 
$parentObjectSet : ?SmartObjectSet
 
$sourceType : ?string
 
$sourcePayload : ?array
 

__sleep()

public AbstractObjectSet::__sleep (
void
): void

count()

public AbstractObjectSet::count (
void
): int

(PHP 5 >= 5.1.0)
Count elements of an object

Return Values

The custom count as an integer.

The return value is cast to an integer.

current()

public AbstractObjectSet::current (
void
): ?mixed

(PHP 5 >= 5.0.0)
Return the current element

filter()

getActualScope()

public AbstractObjectSet::getActualScope (
void
): array

Returns the object ids of the objects in the actual scope.

getById()

public SmartObjectSet::getById (
int $id,
?class-string<expectedType> $expectedType = null
): AbstractObject|expectedType

Return the AbstractObject with the id $id.

Note: The Smart ObjectSet it won't redirect the call to ObjectFinder::getById().

Parameters
$id : int
 
$expectedType : ?class-string<expectedType>
 
Exceptions

Throws UnknownObjectException If the type doesn't match.

getChilds()

public SmartObjectSet::getChilds (
null|string|string[] $types = null
): SmartObjectSet

Return an ObjectSet with all known childs of the objects in the actual scope.

It is necessary to previously call withChilds otherwise the returned ObjectSet will be empty.

The returned ObjectSet is connected with this ObjectSet.

Parameters
$types : null|string|string[]
 

getFullObjectSet()

Creates a full object set with all objects with the same path

getParentIds()

public AbstractObjectSet::getParentIds (
void
): array

getParents()

Return an ObjectSet with all known parents of the objects in the actual scope.

getReferenceIds()

public AbstractObjectSet::getReferenceIds (
array|string|null $fieldNames = null,
bool $validateFieldNames = true
): array
Parameters
$fieldNames : array|string|null
 
$validateFieldNames : bool
 

getReferences()

public SmartObjectSet::getReferences (
?array $fieldNames = null
): SmartObjectSet

Return an ObjectSet with all known references of the objects in the actual scope.


The $fieldNames array need to look like this:
$fieldNames = [
    'EventRelation' => ['Event', 'parent'],
    'Event', // load all references of containing event objects
];
Parameters
$fieldNames : ?array
 

getReferencingObjects()

public SmartObjectSet::getReferencingObjects (
string $type,
string $field
): SmartObjectSet

Get all objects of $type that are referencing on any object of the actual scope over the reference field $field.

Parameters
$type : string
 
$field : string
 

getTypes()

public AbstractObjectSet::getTypes (
void
): array

Returns the object types of all objects in the actual scope. Every type is only once in the result.

hasChilds()

public SmartObjectSet::hasChilds (
null|string|string[] $types = null
): bool
Parameters
$types : null|string|string[]
 

hasObject()

public AbstractObjectSet::hasObject (
int $id
): bool

Checks whether the object is inside the objectSet.

Note: Doesn't check whether the object is inside the actual scope!

Parameters
$id : int
 

hasReferencingObjects()

public AbstractObjectSet::hasReferencingObjects (
string $type,
string $field
): bool
Parameters
$type : string
 
$field : string
 

key()

public AbstractObjectSet::key (
void
): ?int

(PHP 5 >= 5.0.0)
Return the key of the current element

Return Values

scalar on success, or null on failure.

limit()

public AbstractObjectSet::limit (
int $limit,
?int $offset = null
): self
Parameters
$limit : int
 
$offset : ?int
 

next()

public AbstractObjectSet::next (
void
): void

(PHP 5 >= 5.0.0)
Move forward to next element

Return Values

Any returned value is ignored.

order()

public AbstractObjectSet::order (
string|array|callable $orders
): self
Parameters
$orders : string|array|callable
 
See

reload()

public AbstractObjectSet::reload (
void
): static

Reload all objects in the actual scope.

Exceptions

Throws UnknownObjectException If (at least) one object can't be found!

rewind()

public AbstractObjectSet::rewind (
void
): void

(PHP 5 >= 5.0.0)
Rewind the Iterator to the first element

Return Values

Any returned value is ignored.

toArray()

WARNING: This method is marked as deprecated!

Use toDataArray() or toObjectArray() instead

public AbstractObjectSet::toArray (
bool $asObject = false
): array

Returns the actual scope as array.

If $asObject is false the result will be an array filled with associative arrays. If $asObject is true the result will be an array filled with AbstractObjects.

Parameters
$asObject : bool
 

toDataArray()

public AbstractObjectSet::toDataArray (
void
): array

toObjectArray()

public AbstractObjectSet::toObjectArray (
void
): array

Returns the actual scope as an array ob AbstractObjects.

valid()

public AbstractObjectSet::valid (
void
): bool

(PHP 5 >= 5.0.0)
Checks if current position is valid

Return Values

The return value will be cast to boolean and then evaluated. Returns true on success or false on failure.

withAllChilds()

public SmartObjectSet::withAllChilds (
string|string[]|null $types = null
): self
Parameters
$types : string|string[]|null
 

withChilds()

public SmartObjectSet::withChilds (
string|string[]|null $types = null,
null $selectors = null
): ObjectSet\ResolveHelper
Parameters
$types : string|string[]|null
 
$selectors : null
 

withParents()

withReferences()

public SmartObjectSet::withReferences (
?array $fieldNames = null
): ObjectSet\ResolveHelper
Parameters
$fieldNames : ?array
 

withReferencingObjects()

public SmartObjectSet::withReferencingObjects (
string $type,
string $field
): ObjectSet\ResolveHelper
Parameters
$type : string
 
$field : string