PHP Класс Webiny\Component\Entity\Attribute\AbstractAttribute

Наследование: implements JsonSerializabl\JsonSerializable, use trait Webiny\Component\StdLib\StdLibTrait, use trait Webiny\Component\StdLib\FactoryLoaderTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$attribute null | string Attribute name
$defaultValue null Default value
$onFromDbCallback null The value returned from the callback will be set as attribute value
$onGetCallback null The value returned from the callback will be returned as attribute value.
$onSetCallback null The value returned from the callback will be set as a new attribute value.
$onSetValue null Value to trigger $onSetCallback
$onToArrayCallback null The value returned from the callback will be returned as attribute value.
$onToDbCallback null The value returned from the callback will be returned as attribute value for database.
$once boolean If true - updating will be disabled
$parent Webiny\Component\Entity\AbstractEntity Entity this attribute belongs to
$required boolean Is this attribute required
$setAfterPopulate boolean If true - will wait until mass populate is finished and assign the value afterwards
$skipOnPopulate boolean If true - mass populate will skip this attribute
$storeToDb boolean If true - will store this attribute to database
$toArrayDefault null If true - this attribute will be included in the output of entity's toArray method
$validationMessages array Validation messages
$validatorInterface string
$validators array Attribute validators
$value null Actual value

Открытые методы

Метод Описание
__construct ( string $name = null, AbstractEntity $parent = null )
__toString ( ) : string Get attribute value as string
attr ( null | string $attribute = null ) : EntityAttributeBuilder | string Create new attribute or get name of current attribute
getAfterPopulate ( ) : boolean Should this attribute's value be assigned after populate() ?
getDbValue ( ) : string Get value that will be stored to database
getDefaultValue ( ) : mixed Get default value
getName ( ) : string Get attribute name
getOnce ( ) Get 'once' flag
This flag tells you whether this attribute should only be populated when it's a new AbstractEntity instance.
By default, attributes are populated each time.
getParent ( ) : AbstractEntity Get entity instance this attribute belongs to
getSkipOnPopulate ( ) : boolean Get skipOnPopulate flag
getStoreToDb ( ) : boolean Should this attribute value be stored to DB
getToArrayDefault ( ) : boolean Get toArrayDefault flag
getValidationMessages ( string | null $validator = null ) : mixed Get validation messages
getValidators ( ) : array Get validators
getValue ( array $params = [], boolean $processCallbacks = true ) Get attribute value
hasToArrayCallback ( )
hasValue ( )
isRequired ( ) Get required flag
jsonSerialize ( ) : mixed (PHP 5 >= 5.4.0)
Specify data which should be serialized to JSON
onFromDb ( $callback ) Set callback that will be used to process value when data is loaded from DB
onGet ( $callable = null )
onSet ( $value, $callable = null )
onToArray ( $callback ) Set callback that will be used to process getToArrayValue() call
onToDb ( $callback ) Set callback that will be used to process getDbValue() call
setAfterPopulate ( boolean $flag = true ) Should this attribute's value be assigned after populate() ? This is useful when onSet() callback is triggering business logic that depends on other attributes that are not yet set because populate() cycle has not yet finished and onSet() callback of current attribute is executed
setDefaultValue ( mixed $defaultValue = null ) Set default value
setName ( string $attribute ) Set attribute name
setOnce ( boolean $flag = true ) Set 'once' flag
If true, it tells AbstractEntity to only populate this attribute if it's a new entity
This is useful when you want to protect values from being populate on later updates.
setParent ( AbstractEntity $entity )
setRequired ( boolean $flag = true ) Set required flag
setSkipOnPopulate ( boolean $flag = true ) Skip attribute on mass populate
setToArrayDefault ( boolean $flag = true ) Set if this attribute will be by default included in the output of entity's toArray method
setValidationMessages ( array $messages ) Set validation messages
setValidators ( array | string $validators = [] ) Set attribute validators
setValue ( null $value = null, boolean $fromDb = false ) Set attribute value
toArray ( array $params = [] ) : string Get value that will be used to represent this attribute when converting AbstractEntity to array

Защищенные методы

Метод Описание
applyValidator ( string $validator, string $key, mixed $value, array $messages = [] ) Apply validator to given value
canAssign ( ) : boolean Check if value can be assigned to current attribute
expected ( string $expecting, string $got, boolean $return = false ) : ValidationException Throw or return attribute validation exception
processFromDbValue ( $value ) : mixed Triggered when calling 'setValue()' with $fromDb=true on attribute instance
processGetValue ( mixed $value, array $params = [], boolean $processCallbacks = true ) : mixed Triggered when calling 'getValue()' on attribute instance
processSetValue ( $value ) : mixed Triggered when calling 'setValue()' on attribute instance
processToArrayValue ( $value ) : mixed Triggered when calling 'toArray()' on the entity instance
processToDbValue ( $value ) : mixed Triggered when calling 'getDbValue()' on attribute instance
validate ( &$value ) Perform validation against given value

Приватные методы

Метод Описание
processCallback ( $callback, $value, array $params = [] ) : mixed Execute given callback
Take $value and check if a valid callback is given
If yes, return the processed value.

Описание методов

__construct() публичный Метод

public __construct ( string $name = null, AbstractEntity $parent = null )
$name string
$parent Webiny\Component\Entity\AbstractEntity

__toString() публичный Метод

Get attribute value as string
public __toString ( ) : string
Результат string

applyValidator() защищенный Метод

Apply validator to given value
protected applyValidator ( string $validator, string $key, mixed $value, array $messages = [] )
$validator string
$key string
$value mixed
$messages array

attr() публичный Метод

Create new attribute or get name of current attribute
public attr ( null | string $attribute = null ) : EntityAttributeBuilder | string
$attribute null | string
Результат Webiny\Component\Entity\EntityAttributeBuilder | string

canAssign() защищенный Метод

If Entity has an ID and attribute 'once' flag is set and attribute has a value assigned to it then a new value should not be assigned.
protected canAssign ( ) : boolean
Результат boolean

expected() защищенный Метод

Throw or return attribute validation exception
protected expected ( string $expecting, string $got, boolean $return = false ) : ValidationException
$expecting string
$got string
$return boolean
Результат Webiny\Component\Entity\Attribute\Validation\ValidationException

getAfterPopulate() публичный Метод

Should this attribute's value be assigned after populate() ?
public getAfterPopulate ( ) : boolean
Результат boolean

getDbValue() публичный Метод

If no value is set, default value will be used, and that value will also be assigned as a new attribute value.
public getDbValue ( ) : string
Результат string

getDefaultValue() публичный Метод

Get default value
public getDefaultValue ( ) : mixed
Результат mixed

getName() публичный Метод

Get attribute name
public getName ( ) : string
Результат string

getOnce() публичный Метод

Get 'once' flag
This flag tells you whether this attribute should only be populated when it's a new AbstractEntity instance.
By default, attributes are populated each time.
public getOnce ( )

getParent() публичный Метод

Get entity instance this attribute belongs to
public getParent ( ) : AbstractEntity
Результат Webiny\Component\Entity\AbstractEntity

getSkipOnPopulate() публичный Метод

Get skipOnPopulate flag
public getSkipOnPopulate ( ) : boolean
Результат boolean

getStoreToDb() публичный Метод

Should this attribute value be stored to DB
public getStoreToDb ( ) : boolean
Результат boolean

getToArrayDefault() публичный Метод

Get toArrayDefault flag
public getToArrayDefault ( ) : boolean
Результат boolean

getValidationMessages() публичный Метод

Get validation messages
public getValidationMessages ( string | null $validator = null ) : mixed
$validator string | null If given, returns validation message for given validator
Результат mixed

getValidators() публичный Метод

Get validators
public getValidators ( ) : array
Результат array

getValue() публичный Метод

Get attribute value
public getValue ( array $params = [], boolean $processCallbacks = true )
$params array
$processCallbacks boolean Process `onGet` callbacks

hasToArrayCallback() публичный Метод

public hasToArrayCallback ( )

hasValue() публичный Метод

public hasValue ( )

isRequired() публичный Метод

Get required flag
public isRequired ( )

jsonSerialize() публичный Метод

(PHP 5 >= 5.4.0)
Specify data which should be serialized to JSON
public jsonSerialize ( ) : mixed
Результат mixed data which can be serialized by json_encode, which is a value of any type other than a resource.

onFromDb() публичный Метод

Set callback that will be used to process value when data is loaded from DB
public onFromDb ( $callback )
$callback

onGet() публичный Метод

public onGet ( $callable = null )

onSet() публичный Метод

public onSet ( $value, $callable = null )

onToArray() публичный Метод

Set callback that will be used to process getToArrayValue() call
public onToArray ( $callback )
$callback

onToDb() публичный Метод

Set callback that will be used to process getDbValue() call
public onToDb ( $callback )
$callback

processFromDbValue() защищенный Метод

Triggered when calling 'setValue()' with $fromDb=true on attribute instance
protected processFromDbValue ( $value ) : mixed
$value
Результат mixed

processGetValue() защищенный Метод

Triggered when calling 'getValue()' on attribute instance
protected processGetValue ( mixed $value, array $params = [], boolean $processCallbacks = true ) : mixed
$value mixed
$params array
$processCallbacks boolean
Результат mixed

processSetValue() защищенный Метод

Triggered when calling 'setValue()' on attribute instance
protected processSetValue ( $value ) : mixed
$value
Результат mixed

processToArrayValue() защищенный Метод

Triggered when calling 'toArray()' on the entity instance
protected processToArrayValue ( $value ) : mixed
$value
Результат mixed

processToDbValue() защищенный Метод

Triggered when calling 'getDbValue()' on attribute instance
protected processToDbValue ( $value ) : mixed
$value
Результат mixed

setAfterPopulate() публичный Метод

Should this attribute's value be assigned after populate() ? This is useful when onSet() callback is triggering business logic that depends on other attributes that are not yet set because populate() cycle has not yet finished and onSet() callback of current attribute is executed
public setAfterPopulate ( boolean $flag = true )
$flag boolean

setDefaultValue() публичный Метод

Set default value
public setDefaultValue ( mixed $defaultValue = null )
$defaultValue mixed

setName() публичный Метод

Set attribute name
public setName ( string $attribute )
$attribute string

setOnce() публичный Метод

Set 'once' flag
If true, it tells AbstractEntity to only populate this attribute if it's a new entity
This is useful when you want to protect values from being populate on later updates.
public setOnce ( boolean $flag = true )
$flag boolean

setParent() публичный Метод

public setParent ( AbstractEntity $entity )
$entity Webiny\Component\Entity\AbstractEntity

setRequired() публичный Метод

Set required flag
public setRequired ( boolean $flag = true )
$flag boolean

setSkipOnPopulate() публичный Метод

Skip attribute on mass populate
public setSkipOnPopulate ( boolean $flag = true )
$flag boolean

setToArrayDefault() публичный Метод

Set if this attribute will be by default included in the output of entity's toArray method
public setToArrayDefault ( boolean $flag = true )
$flag boolean

setValidationMessages() публичный Метод

Set validation messages
public setValidationMessages ( array $messages )
$messages array

setValidators() публичный Метод

Set attribute validators
public setValidators ( array | string $validators = [] )
$validators array | string

setValue() публичный Метод

Set attribute value
public setValue ( null $value = null, boolean $fromDb = false )
$value null Attribute value
$fromDb boolean Is value coming from DB?

toArray() публичный Метод

Get value that will be used to represent this attribute when converting AbstractEntity to array
public toArray ( array $params = [] ) : string
$params array
Результат string

validate() защищенный Метод

Perform validation against given value
protected validate ( &$value )
$value

Описание свойств

$attribute защищенное свойство

Attribute name
protected null|string $attribute
Результат null | string

$defaultValue защищенное свойство

Default value
protected null $defaultValue
Результат null

$onFromDbCallback защищенное свойство

The value returned from the callback will be set as attribute value
protected null $onFromDbCallback
Результат null

$onGetCallback защищенное свойство

The value returned from the callback will be returned as attribute value.
protected null $onGetCallback
Результат null

$onSetCallback защищенное свойство

The value returned from the callback will be set as a new attribute value.
protected null $onSetCallback
Результат null

$onSetValue защищенное свойство

Value to trigger $onSetCallback
protected null $onSetValue
Результат null

$onToArrayCallback защищенное свойство

The value returned from the callback will be returned as attribute value.
protected null $onToArrayCallback
Результат null

$onToDbCallback защищенное свойство

The value returned from the callback will be returned as attribute value for database.
protected null $onToDbCallback
Результат null

$once защищенное свойство

If true - updating will be disabled
protected bool $once
Результат boolean

$parent защищенное свойство

Entity this attribute belongs to
protected AbstractEntity,Webiny\Component\Entity $parent
Результат Webiny\Component\Entity\AbstractEntity

$required защищенное свойство

Is this attribute required
protected bool $required
Результат boolean

$setAfterPopulate защищенное свойство

If true - will wait until mass populate is finished and assign the value afterwards
protected bool $setAfterPopulate
Результат boolean

$skipOnPopulate защищенное свойство

If true - mass populate will skip this attribute
protected bool $skipOnPopulate
Результат boolean

$storeToDb защищенное свойство

If true - will store this attribute to database
protected bool $storeToDb
Результат boolean

$toArrayDefault защищенное свойство

If true - this attribute will be included in the output of entity's toArray method
protected null $toArrayDefault
Результат null

$validationMessages защищенное свойство

Validation messages
protected array $validationMessages
Результат array

$validatorInterface защищенное свойство

protected string $validatorInterface
Результат string

$validators защищенное свойство

Attribute validators
protected array $validators
Результат array

$value защищенное свойство

Actual value
protected null $value
Результат null