Documentation

FlexObject
in package
implements FlexObjectInterface, FlexAuthorizeInterface uses ObjectTrait, LazyPropertyTrait, NestedPropertyTrait, OverloadedPropertyTrait, NestedArrayAccessTrait, FlexAuthorizeTrait, FlexRelatedDirectoryTrait

Class FlexObject

Table of Contents

Interfaces

FlexObjectInterface
Defines Flex Objects.
FlexAuthorizeInterface
Defines authorization checks for Flex Objects.

Properties

$_original  : array<string|int, mixed>|null
$storage_key  : string|null
$storage_timestamp  : int|null
$type  : string
$_blueprint  : array<string|int, Blueprint>
$_flexDirectory  : FlexDirectory
$_forms  : array<string|int, FlexFormInterface>
$_key  : string
$_meta  : array<string|int, mixed>|null

Methods

__clone()  : mixed
Clone object.
__construct()  : mixed
Construct a new Flex Object instance.
__debugInfo()  : array<string|int, mixed>
__get()  : mixed
Returns the value at specified offset.
__isset()  : bool
Checks whether or not an offset exists.
__serialize()  : array<string|int, mixed>
__set()  : void
Assigns a value to the specified offset.
__toString()  : string
Returns a string representation of this object.
__unserialize()  : void
__unset()  : void
Magic method to unset the attribute
blueprints()  : Blueprint
Alias of getBlueprint()
check()  : void
create()  : static
Create new object into the storage.
createCopy()  : FlexObject|FlexObjectInterface
createFromStorage()  : static
defNestedProperty()  : $this
defProperty()  : $this
delete()  : static
Delete object from the storage.
exists()  : bool
Returns true if the object exists in the storage.
getBlueprint()  : Blueprint
Returns the blueprint of the object.
getCache()  : CacheInterface
getCacheChecksum()  : string
Get cache checksum for the object / collection.
getCachedMethods()  : array<string|int, mixed>
getCacheKey()  : string
Get a cache key which is used for caching the object / collection.
getChanges()  : array<string|int, mixed>
Get any changes from the object.
getDefaultValue()  : mixed|null
Returns default value suitable to be used in a form for the given property.
getDefaultValues()  : array<string|int, mixed>
Returns default values suitable to be used in a form for the given property.
getDiff()  : array<string|int, mixed>
Get diff array from the object.
getFlexDirectory()  : FlexDirectory
Get Flex Directory for the object / collection.
getFlexFeatures()  : array<string|int, mixed>
Get full list of features the object / collection implements.
getFlexKey()  : string
Get a unique key for the object.
getFlexType()  : string
Get Flex Type of the object / collection.
getForm()  : FlexFormInterface
Returns a form instance for the object.
getFormValue()  : mixed
Returns raw value suitable to be used in a form for the given property.
getKey()  : string
getMetaData()  : array<string|int, mixed>
Get index data associated to the object.
getNestedProperty()  : mixed
getOriginalData()  : array<string|int, mixed>
Get original data before update
getProperty()  : mixed
getStorageKey()  : string
Get an unique storage key (within the directory) which is used for figuring out the filename or database id.
getTimestamp()  : int
Get last updated timestamp for the object / collection.
getType()  : string
hasFlexFeature()  : bool
Test whether the feature is implemented in the object / collection.
hasKey()  : bool
hasNestedProperty()  : bool
hasProperty()  : bool
isAuthorized()  : bool|null
Check if user is authorized for the action.
jsonSerialize()  : array<string|int, mixed>
offsetExists()  : bool
Whether or not an offset exists.
offsetGet()  : mixed
Returns the value at specified offset.
offsetSet()  : void
Assigns a value to the specified offset.
offsetUnset()  : void
Unsets an offset.
prepareStorage()  : array<string|int, mixed>
Prepare object for saving into the storage.
refresh()  : bool
Refresh object from the storage.
render()  : ContentBlockInterface|HtmlBlock
Renders the object.
save()  : static
Save object into the storage.
search()  : float
Search a string from the object, returns weight between 0 and 1.
searchNestedProperty()  : float
searchProperty()  : float
setFlexDirectory()  : void
setNestedProperty()  : $this
setProperty()  : $this
setStorageKey()  : $this
setTimestamp()  : $this
triggerEvent()  : $this
unsetNestedProperty()  : $this
unsetProperty()  : $this
update()  : static
Updates object in the memory.
value()  : mixed
createFormObject()  : FlexFormInterface
This methods allows you to override form objects in child classes.
doGetBlueprint()  : Blueprint
doGetProperty()  : mixed
doHasProperty()  : bool
doSerialize()  : array<string|int, mixed>
doSetProperty()  : void
doUnserialize()  : void
doUnsetProperty()  : void
filterElements()  : void
Filter data coming to constructor or $this->update() request.
getActiveUser()  : UserInterface|null
getAuthorizeAction()  : string
getAuthorizeRule()  : string
getAuthorizeScope()  : string
getCollectionByProperty()  : FlexCollectionInterface<string|int, FlexObjectInterface>
getElement()  : mixed|null
getElements()  : array<string|int, mixed>
getFlexContainer()  : Flex
getRelatedDirectory()  : FlexDirectory
getStorage()  : array<string|int, mixed>
getTemplate()  : Template|TemplateWrapper
getTemplateConfig()  : array<string|int, mixed>
getTemplatePaths()  : array<string|int, mixed>
getTypePrefix()  : string
isAuthorizedAction()  : bool|null
Check if user is authorized for the action.
isAuthorizedOverride()  : bool|null
Please override this method
isAuthorizedSuperAdmin()  : bool|null
markAsCopy()  : void
resetBlueprints()  : void
Method to reset blueprints if the type changes.
searchValue()  : float
setKey()  : $this
setMetaData()  : void
setStorage()  : void

Properties

$_original

protected array<string|int, mixed>|null $_original

$storage_timestamp

protected int|null $storage_timestamp

$_meta

private array<string|int, mixed>|null $_meta

Methods

__clone()

Clone object.

public __clone() : mixed
Attributes
#[ReturnTypeWillChange]

__construct()

Construct a new Flex Object instance.

public __construct(array<string|int, mixed> $elements, mixed $key, FlexDirectory $directory[, bool $validate = false ]) : mixed
Parameters
$elements : array<string|int, mixed>

Array of object properties.

$key : mixed

Identifier key for the new object.

$directory : FlexDirectory

Flex Directory the object belongs into.

$validate : bool = false

True if the object should be validated against blueprint.

Tags
see
FlexObjectInterface::__construct()

__debugInfo()

public __debugInfo() : array<string|int, mixed>
Attributes
#[ReturnTypeWillChange]
Return values
array<string|int, mixed>

__get()

Returns the value at specified offset.

public __get(mixed $offset) : mixed
Parameters
$offset : mixed

The offset to retrieve.

Attributes
#[ReturnTypeWillChange]
Return values
mixed

Can return all value types.

__isset()

Checks whether or not an offset exists.

public __isset(mixed $offset) : bool
Parameters
$offset : mixed

An offset to check for.

Attributes
#[ReturnTypeWillChange]
Return values
bool

Returns TRUE on success or FALSE on failure.

__serialize()

public final __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__set()

Assigns a value to the specified offset.

public __set(mixed $offset, mixed $value) : void
Parameters
$offset : mixed

The offset to assign the value to.

$value : mixed

The value to set.

Attributes
#[ReturnTypeWillChange]

__toString()

Returns a string representation of this object.

public __toString() : string
Attributes
#[ReturnTypeWillChange]
Return values
string

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

__unset()

Magic method to unset the attribute

public __unset(mixed $offset) : void
Parameters
$offset : mixed

The name value to unset

Attributes
#[ReturnTypeWillChange]

create()

Create new object into the storage.

public create([string $key = null ]) : static
Parameters
$key : string = null

Optional new key. If key isn't given, random key will be associated to the object.

Tags
see
FlexObjectInterface::create()
Return values
static

createFromStorage()

public static createFromStorage(array<string|int, mixed> $elements, array<string|int, mixed> $storage, FlexDirectory $directory[, bool $validate = false ]) : static
Parameters
$elements : array<string|int, mixed>
$storage : array<string|int, mixed>
$directory : FlexDirectory
$validate : bool = false
Return values
static

defNestedProperty()

public defNestedProperty(string $property, mixed $default[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be updated.

$default : mixed

Default value.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

defProperty()

public defProperty(string $property, mixed $default) : $this
Parameters
$property : string

Object property to be defined.

$default : mixed

Default value.

Return values
$this

exists()

Returns true if the object exists in the storage.

public exists() : bool
Tags
see
FlexObjectInterface::exists()
Return values
bool

Returns true if the object exists, false otherwise.

getBlueprint()

Returns the blueprint of the object.

public getBlueprint([string $name = '' ]) : Blueprint
Parameters
$name : string = ''

Name of the Blueprint form. Used to create customized forms for different use cases.

Tags
see
FlexObjectInterface::getBlueprint()
Return values
Blueprint

Returns a Blueprint.

getCacheChecksum()

Get cache checksum for the object / collection.

public getCacheChecksum() : string
Tags
see
FlexObjectInterface::getCacheChecksum()
Return values
string

Returns cache checksum.

getCachedMethods()

public static getCachedMethods() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCacheKey()

Get a cache key which is used for caching the object / collection.

public getCacheKey() : string
Tags
see
FlexObjectInterface::getCacheKey()
Return values
string

Returns cache key.

getChanges()

Get any changes from the object.

public getChanges() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDefaultValue()

Returns default value suitable to be used in a form for the given property.

public getDefaultValue(string $name[, string $separator = null ]) : mixed|null
Parameters
$name : string

Property name.

$separator : string = null

Optional nested property separator.

Tags
see
FlexObjectInterface::getDefaultValue()
Return values
mixed|null

Returns default value of the field, null if there is no default value.

getDefaultValues()

Returns default values suitable to be used in a form for the given property.

public getDefaultValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDiff()

Get diff array from the object.

public getDiff() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFlexDirectory()

Get Flex Directory for the object / collection.

public getFlexDirectory() : FlexDirectory
Tags
see
FlexObjectInterface::getFlexDirectory()
Return values
FlexDirectory

Returns associated Flex Directory.

getFlexFeatures()

Get full list of features the object / collection implements.

public getFlexFeatures() : array<string|int, mixed>
Tags
see
FlexCommonInterface::hasFlexFeature()
Return values
array<string|int, mixed>

getFlexType()

Get Flex Type of the object / collection.

public getFlexType() : string
Tags
see
FlexObjectInterface::getFlexType()
Return values
string

Returns Flex Type of the collection.

getForm()

Returns a form instance for the object.

public getForm([string $name = '' ][, array<string|int, mixed> $options = null ]) : FlexFormInterface
Parameters
$name : string = ''

Name of the form. Can be used to create customized forms for different use cases.

$options : array<string|int, mixed> = null

Options can be used to further customize the form.

Tags
see
FlexObjectInterface::getForm()
Return values
FlexFormInterface

Returns a Form.

getFormValue()

Returns raw value suitable to be used in a form for the given property.

public getFormValue(string $name[, mixed $default = null ][, string $separator = null ]) : mixed
Parameters
$name : string

Property name.

$default : mixed = null

Default value.

$separator : string = null

Optional nested property separator.

Tags
see
FlexObjectInterface::getFormValue()
Return values
mixed

Returns value of the field.

getKey()

public getKey() : string
Tags
see
ObjectInterface::getFlexKey()
Return values
string

getMetaData()

Get index data associated to the object.

public getMetaData() : array<string|int, mixed>
Tags
see
FlexObjectInterface::getMetaData()
Return values
array<string|int, mixed>

Returns metadata of the object.

getNestedProperty()

public getNestedProperty(string $property[, mixed|null $default = null ][, string|null $separator = null ]) : mixed
Parameters
$property : string

Object property to be fetched.

$default : mixed|null = null

Default value if property has not been set.

$separator : string|null = null

Separator, defaults to '.'

Return values
mixed

Property value.

getOriginalData()

Get original data before update

public getOriginalData() : array<string|int, mixed>
Return values
array<string|int, mixed>

getProperty()

public getProperty(string $property[, mixed $default = null ]) : mixed
Parameters
$property : string

Object property to be fetched.

$default : mixed = null

Default value if property has not been set.

Return values
mixed

Property value.

getStorageKey()

Get an unique storage key (within the directory) which is used for figuring out the filename or database id.

public getStorageKey() : string
Tags
see
FlexObjectInterface::getStorageKey()
Return values
string

Returns storage key of the Object.

getTimestamp()

Get last updated timestamp for the object / collection.

public getTimestamp() : int
Tags
see
FlexObjectInterface::getTimestamp()
Return values
int

Returns Unix timestamp.

getType()

public getType([bool $prefix = false ]) : string

Use ->getFlexType() instead.

Parameters
$prefix : bool = false
Return values
string

hasFlexFeature()

Test whether the feature is implemented in the object / collection.

public hasFlexFeature(string $name) : bool
Parameters
$name : string
Tags
see
FlexCommonInterface::hasFlexFeature()
Return values
bool

hasNestedProperty()

public hasNestedProperty(string $property[, string|null $separator = null ]) : bool
Parameters
$property : string

Object property name.

$separator : string|null = null

Separator, defaults to '.'

Return values
bool

True if property has been defined (can be null).

hasProperty()

public hasProperty(string $property) : bool
Parameters
$property : string

Object property name.

Return values
bool

True if property has been defined (can be null).

isAuthorized()

Check if user is authorized for the action.

public isAuthorized(string $action[, string|null $scope = null ][, UserInterface|null $user = null ]) : bool|null

Note: There are two deny values: denied (false), not set (null). This allows chaining multiple rules together when the previous rules were not matched.

To override the default behavior, please use isAuthorizedOverride().

Parameters
$action : string
$scope : string|null = null
$user : UserInterface|null = null
Tags
final
Return values
bool|null

jsonSerialize()

public jsonSerialize() : array<string|int, mixed>
Attributes
#[ReturnTypeWillChange]
Return values
array<string|int, mixed>

offsetExists()

Whether or not an offset exists.

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed

An offset to check for.

Attributes
#[ReturnTypeWillChange]
Return values
bool

Returns TRUE on success or FALSE on failure.

offsetGet()

Returns the value at specified offset.

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed

The offset to retrieve.

Attributes
#[ReturnTypeWillChange]
Return values
mixed

Can return all value types.

offsetSet()

Assigns a value to the specified offset.

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed

The offset to assign the value to.

$value : mixed

The value to set.

Attributes
#[ReturnTypeWillChange]

offsetUnset()

Unsets an offset.

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

The offset to unset.

Attributes
#[ReturnTypeWillChange]

prepareStorage()

Prepare object for saving into the storage.

public prepareStorage() : array<string|int, mixed>
Tags
see
FlexObjectInterface::prepareStorage()
Return values
array<string|int, mixed>

Returns an array of object properties containing only scalars and arrays.

refresh()

Refresh object from the storage.

public refresh([bool $keepMissing = false ]) : bool
Parameters
$keepMissing : bool = false
Return values
bool

True if the object was refreshed

render()

Renders the object.

public render([string $layout = null ][, array<string|int, mixed> $context = [] ]) : ContentBlockInterface|HtmlBlock
Parameters
$layout : string = null

Layout to be used.

$context : array<string|int, mixed> = []

Extra context given to the renderer.

Tags
see
FlexObjectInterface::render()
Return values
ContentBlockInterface|HtmlBlock

Returns HtmlBlock containing the rendered output.

Search a string from the object, returns weight between 0 and 1.

public search(string $search[, mixed $properties = null ][, array<string|int, mixed> $options = null ]) : float
Parameters
$search : string

Search string.

$properties : mixed = null

Properties to search for, defaults to configured properties.

$options : array<string|int, mixed> = null

Search options, defaults to configured options.

Tags
see
FlexObjectInterface::search()
Return values
float

Returns a weight between 0 and 1.

searchNestedProperty()

public searchNestedProperty(string $property, string $search[, array<string|int, mixed>|null $options = null ]) : float
Parameters
$property : string
$search : string
$options : array<string|int, mixed>|null = null
Return values
float

searchProperty()

public searchProperty(string $property, string $search[, array<string|int, mixed>|null $options = null ]) : float
Parameters
$property : string
$search : string
$options : array<string|int, mixed>|null = null
Return values
float

setNestedProperty()

public setNestedProperty(string $property, mixed $value[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be updated.

$value : mixed

New value.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

setProperty()

public setProperty(string $property, mixed $value) : $this
Parameters
$property : string

Object property to be updated.

$value : mixed

New value.

Return values
$this

setStorageKey()

public setStorageKey([string|null $key = null ]) : $this
Parameters
$key : string|null = null
Return values
$this

setTimestamp()

public setTimestamp([int $timestamp = null ]) : $this
Parameters
$timestamp : int = null
Return values
$this

triggerEvent()

public triggerEvent(string $name[, object|null $event = null ]) : $this

Moved to \Grav\Common\Flex\Traits\FlexObjectTrait

Parameters
$name : string
$event : object|null = null
Return values
$this

unsetNestedProperty()

public unsetNestedProperty(string $property[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be updated.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

unsetProperty()

public unsetProperty(string $property) : $this
Parameters
$property : string

Object property to be unset.

Return values
$this

update()

Updates object in the memory.

public update(array<string|int, mixed> $data[, array<string|int, mixed> $files = [] ]) : static
Parameters
$data : array<string|int, mixed>

Data containing updated properties with their values. To unset a value, use null.

$files : array<string|int, mixed> = []

List of uploaded files to be saved within the object.

Tags
see
FlexObjectInterface::update()
Return values
static

value()

public value(string $name[, mixed|null $default = null ][, string|null $separator = null ]) : mixed

Use ->getFormValue() method instead.

Parameters
$name : string
$default : mixed|null = null
$separator : string|null = null

createFormObject()

This methods allows you to override form objects in child classes.

protected createFormObject(string $name[, array<string|int, mixed>|null $options = null ]) : FlexFormInterface
Parameters
$name : string

Form name

$options : array<string|int, mixed>|null = null

Form optiosn

Return values
FlexFormInterface

doGetProperty()

protected & doGetProperty(string $property[, mixed $default = null ][, bool $doCreate = false ]) : mixed
Parameters
$property : string

Object property to be fetched.

$default : mixed = null

Default value if property has not been set.

$doCreate : bool = false
Return values
mixed

Property value.

doHasProperty()

protected doHasProperty(string $property) : bool
Parameters
$property : string

Object property name.

Return values
bool

True if property has been defined (can be null).

doSerialize()

protected doSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

doSetProperty()

protected doSetProperty(string $property, mixed $value) : void
Parameters
$property : string

Object property to be updated.

$value : mixed

New value.

doUnserialize()

protected doUnserialize(array<string|int, mixed> $serialized[, FlexDirectory|null $directory = null ]) : void
Parameters
$serialized : array<string|int, mixed>
$directory : FlexDirectory|null = null

doUnsetProperty()

protected doUnsetProperty(string $property) : void
Parameters
$property : string

Object property to be unset.

filterElements()

Filter data coming to constructor or $this->update() request.

protected filterElements(array<string|int, mixed> &$elements) : void

NOTE: The incoming data can be an arbitrary array so do not assume anything from its content.

Parameters
$elements : array<string|int, mixed>

getAuthorizeAction()

protected getAuthorizeAction(string $action) : string
Parameters
$action : string
Return values
string

getAuthorizeRule()

protected getAuthorizeRule(string $scope, string $action) : string
Parameters
$scope : string
$action : string
Return values
string

getAuthorizeScope()

protected getAuthorizeScope() : string

Moved to \Grav\Common\Flex\Traits\GravTrait

Return values
string

getElement()

protected getElement(string $property[, mixed|null $default = null ]) : mixed|null
Parameters
$property : string
$default : mixed|null = null
Return values
mixed|null

getElements()

protected getElements() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFlexContainer()

protected getFlexContainer() : Flex

Moved to \Grav\Common\Flex\Traits\GravTrait

Return values
Flex

getStorage()

protected getStorage() : array<string|int, mixed>

Use ->getMetaData() instead.

Return values
array<string|int, mixed>

getTemplate()

protected getTemplate(string $layout) : Template|TemplateWrapper

Moved to \Grav\Common\Flex\Traits\GravTrait

Parameters
$layout : string
Tags
throws
LoaderError
throws
SyntaxError
Return values
Template|TemplateWrapper

getTemplateConfig()

protected getTemplateConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTemplatePaths()

protected getTemplatePaths(string $layout) : array<string|int, mixed>
Parameters
$layout : string
Return values
array<string|int, mixed>

getTypePrefix()

protected getTypePrefix() : string
Return values
string

isAuthorizedAction()

Check if user is authorized for the action.

protected isAuthorizedAction(UserInterface $user, string $action, string $scope, bool $isMe) : bool|null
Parameters
$user : UserInterface
$action : string
$scope : string
$isMe : bool
Return values
bool|null

isAuthorizedOverride()

Please override this method

protected isAuthorizedOverride(UserInterface $user, string $action, string $scope, bool $isMe) : bool|null
Parameters
$user : UserInterface
$action : string
$scope : string
$isMe : bool
Return values
bool|null

resetBlueprints()

Method to reset blueprints if the type changes.

protected resetBlueprints() : void
Tags
since
1.7.18

searchValue()

protected searchValue(string $name, mixed $value, string $search[, array<string|int, mixed>|null $options = null ]) : float
Parameters
$name : string
$value : mixed
$search : string
$options : array<string|int, mixed>|null = null
Return values
float

setKey()

protected setKey(string $key) : $this
Parameters
$key : string
Return values
$this

setMetaData()

protected setMetaData(array<string|int, mixed> $meta) : void
Parameters
$meta : array<string|int, mixed>

setStorage()

protected setStorage(array<string|int, mixed> $storage) : void

Use ->setMetaData() instead.

Parameters
$storage : array<string|int, mixed>

        
On this page

Search results