PHP Class Webiny\Component\Entity\EntityCollection

Inheritance: implements IteratorAggregate, implements ArrayAccess, implements Countable, use trait Webiny\Component\Mongo\MongoTrait, use trait Webiny\Component\StdLib\StdLibTrait
Afficher le fichier Open project: Webiny/Framework

Méthodes publiques

Méthode Description
__construct ( string $entityClass, array $data = [], array $parameters = [] )
__toString ( ) : mixed | null | string Get string of masked entity values when array of instances is being converted to string
contains ( string | AbstractEntity $item ) : boolean Check if given item is already in the data set.
NOTE: this triggers loading of data from database if not yet loaded
count ( ) : mixed Count items in entity collection
delete ( ) : boolean Delete all items in the result set (WARNING: removes data from database)
first ( ) : AbstractEntity | null Gets first entity in collection
getData ( ) : array Get collection data
getIterator ( )
getLimit ( )
getOffset ( )
last ( ) : AbstractEntity | null Gets last entity in collection
offsetExists ( $offset )
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
randomize ( ) Shuffle values (useful when you want to fetch a random value)
removeItem ( $item ) Remove item from data set
toArray ( string $fields = '' ) : array Convert EntityCollection to array.
totalCount ( ) : mixed Count total number of items in collection

Méthodes protégées

Méthode Description
normalizeValue ( array | AbstractEntity $item, boolean $fromDb = false ) : AbstractEntity Normalize value to always be an instance of AbstractEntity

Method Details

__construct() public méthode

public __construct ( string $entityClass, array $data = [], array $parameters = [] )
$entityClass string Entity class
$data array Array of data to be converted to EntityCollection
$parameters array Parameters used to load given data

__toString() public méthode

Get string of masked entity values when array of instances is being converted to string
public __toString ( ) : mixed | null | string
Résultat mixed | null | string

contains() public méthode

TODO: unittest
public contains ( string | AbstractEntity $item ) : boolean
$item string | AbstractEntity ID or AbstractEntity instance
Résultat boolean

count() public méthode

Count items in entity collection
public count ( ) : mixed
Résultat mixed

delete() public méthode

Delete all items in the result set (WARNING: removes data from database)
public delete ( ) : boolean
Résultat boolean

first() public méthode

Gets first entity in collection
public first ( ) : AbstractEntity | null
Résultat AbstractEntity | null

getData() public méthode

Get collection data
public getData ( ) : array
Résultat array

getIterator() public méthode

public getIterator ( )

getLimit() public méthode

public getLimit ( )

getOffset() public méthode

public getOffset ( )

last() public méthode

Gets last entity in collection
public last ( ) : AbstractEntity | null
Résultat AbstractEntity | null

normalizeValue() protected méthode

Normalize value to always be an instance of AbstractEntity
protected normalizeValue ( array | AbstractEntity $item, boolean $fromDb = false ) : AbstractEntity
$item array | AbstractEntity
$fromDb boolean Is $item coming from DB
Résultat AbstractEntity

offsetExists() public méthode

public offsetExists ( $offset )

offsetGet() public méthode

public offsetGet ( $offset )

offsetSet() public méthode

public offsetSet ( $offset, $value )

offsetUnset() public méthode

public offsetUnset ( $offset )

randomize() public méthode

Shuffle values (useful when you want to fetch a random value)
public randomize ( )

removeItem() public méthode

Remove item from data set
public removeItem ( $item )
$item

toArray() public méthode

Each AbstractEntity wil be converted to array using $fields which can be defined as a comma-separated keys, or as a function which will be ran with each entity - this gives the possibility to return different data sets depending on the given function
public toArray ( string $fields = '' ) : array
$fields string List of fields to extract
Résultat array

totalCount() public méthode

TODO: unittest
public totalCount ( ) : mixed
Résultat mixed