PHP Class Webiny\Component\Entity\AbstractEntity

Inheritance: implements ArrayAccess, use trait Webiny\Component\StdLib\StdLibTrait, use trait EntityTrait, use trait Webiny\Component\StdLib\FactoryLoaderTrait
Mostra file Open project: Webiny/Framework Class Usage Examples

Protected Properties

Property Type Description
$attributeBuilder EntityAttributeBuilder
$attributes Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject Entity attributes
$entityCollection Entity collection name
$entityMask string View mask (used for grids and many2one input fields)

Public Methods

Method Description
__call ( $name, $arguments )
__construct ( ) Entity constructor
__get ( $name ) : AbstractAttribute This method allows us to use simplified accessor methods.
__set ( $name, $value ) This method allows setting attribute values through simple assignment Ex: $person->name = 'Webiny';
__toString ( ) : mixed Return string representation of entity
attr ( $attribute ) : EntityAttributeBuilder
count ( array $conditions = [] ) : integer Count records using given criteria
delete ( ) : boolean Delete entity
exists ( ) : boolean Is this entity already saved?
find ( array $conditions = [], array $order = [], integer $limit, integer $page ) : EntityCollection Find entities
findById ( $id ) : null | AbstractEntity Find entity by ID
findOne ( array $conditions = [] ) : null | AbstractEntity Find entity by array of conditions
getAttribute ( string $attribute ) : AbstractAttribute Get entity attribute
getAttributes ( ) : ArrayObject Get all entity attributes
getEntityCollection ( ) : string Get collection name
getMaskedValue ( )
latest ( integer $limit = 1 ) : mixed | null Finds one or more latest entities
offsetExists ( $offset )
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
populate ( array $data ) Populate entity with given data
random ( array $conditions = [] ) : null | AbstractEntity Find a random entity
save ( ) Save entity attributes to database
toArray ( string $fields = '' ) : array Convert AbstractEntity to array with specified fields.

Protected Methods

Method Description
isDbData ( $data ) : boolean Used for checking if the entity populate data is coming from database

Private Methods

Method Description
normalizeData ( $data )
parseOrderParameters ( $order ) : array Parse order parameters and construct parameters suitable for MongoDB
populateAttribute ( $attributeName, AbstractAttribute $entityAttribute, $validation, $data, $fromDb )

Method Details

__call() public method

public __call ( $name, $arguments )

__construct() public method

Entity constructor
public __construct ( )

__get() public method

Ex: $person->company->name
public __get ( $name ) : AbstractAttribute
$name
return Webiny\Component\Entity\Attribute\AbstractAttribute

__set() public method

This method allows setting attribute values through simple assignment Ex: $person->name = 'Webiny';
public __set ( $name, $value )
$name
$value

__toString() public method

Return string representation of entity
public __toString ( ) : mixed
return mixed

attr() public method

public attr ( $attribute ) : EntityAttributeBuilder
$attribute
return EntityAttributeBuilder

count() public static method

Count records using given criteria
public static count ( array $conditions = [] ) : integer
$conditions array
return integer

delete() public method

Delete entity
public delete ( ) : boolean
return boolean

exists() public method

Is this entity already saved?
public exists ( ) : boolean
return boolean

find() public static method

Find entities
public static find ( array $conditions = [], array $order = [], integer $limit, integer $page ) : EntityCollection
$conditions array
$order array Example: ['-name', '+title']
$limit integer
$page integer
return EntityCollection

findById() public static method

Find entity by ID
public static findById ( $id ) : null | AbstractEntity
$id
return null | AbstractEntity

findOne() public static method

Find entity by array of conditions
public static findOne ( array $conditions = [] ) : null | AbstractEntity
$conditions array
return null | AbstractEntity

getAttribute() public method

Get entity attribute
public getAttribute ( string $attribute ) : AbstractAttribute
$attribute string
return Webiny\Component\Entity\Attribute\AbstractAttribute

getAttributes() public method

Get all entity attributes
public getAttributes ( ) : ArrayObject
return Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject

getEntityCollection() public static method

Get collection name
public static getEntityCollection ( ) : string
return string

getMaskedValue() public method

public getMaskedValue ( )

isDbData() protected method

Used for checking if the entity populate data is coming from database
protected isDbData ( $data ) : boolean
$data
return boolean

latest() public static method

Finds one or more latest entities
public static latest ( integer $limit = 1 ) : mixed | null
$limit integer
return mixed | null

offsetExists() public method

public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

populate() public method

Populate entity with given data
public populate ( array $data )
$data array

random() public static method

Find a random entity
public static random ( array $conditions = [] ) : null | AbstractEntity
$conditions array
return null | AbstractEntity

save() public method

Save entity attributes to database
public save ( )

toArray() public method

If no fields are specified, array will contain all simple and Many2One attributes
public toArray ( string $fields = '' ) : array
$fields string List of fields to extract
return array

Property Details

$attributeBuilder protected_oe property

protected EntityAttributeBuilder,Webiny\Component\Entity $attributeBuilder
return EntityAttributeBuilder

$attributes protected_oe property

Entity attributes
protected ArrayObject,Webiny\Component\StdLib\StdObject\ArrayObject $attributes
return Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject

$entityCollection protected_oe static_oe property

Entity collection name
protected static $entityCollection

$entityMask protected_oe static_oe property

View mask (used for grids and many2one input fields)
protected static string $entityMask
return string