Class

TRex\Core\Objects

class Objects extends Object implements IObjects

IObjects is a oriented object array.

This handles a list like an object.

Methods

__construct(mixed $data = null)

Constructor.

mixed __get(string $propertyName)

See PHP doc.

from Object
mixed __set(string $propertyName, mixed $value)

See PHP doc.

from Object
mixed __call(string $methodName, array $args)

See PHP doc.

from Object
boolean isDynamic()

Indicates whether the current object has dynamic properties access.

from Object
setDynamic(boolean $isDynamic)

Sets dynamic properties access.

from Object
addMethod(string $name, Closure $method)

Adds a dynamic method to the object.

from Object
array toArray()

Converts an object to an array.

from Object
Json toJson(int $options = JSON_PRETTY_PRINT)

Converts an object to a Json object.

from Object
string __toString()

See PHP doc.

from Object
IObjectsIterator getIterator()

Returns the current iterator.

setIterator(IObjectsIterator $iterator)

Sets the current Iterator.

mixed|null getByIndex(int $index)

Gets the value of the associate index.

mixed|null first()

Gets the first value.

mixed|null last()

Gets the last value.

addFirst(mixed $value)

Adds values at the beginning of the list.

addLast(mixed $value)

Adds values at the end of the list.

removeFirst()

Removes first value of the list.

removeLast()

Removes last value of the list.

Details

at line 43
public __construct(mixed $data = null)

Constructor.

$data is initial data to set in the object. Keys are property names, and values are initial property values. $data could be a JSON string, an array or an array castable object.

Parameters

mixed $data

in Object at line 58
public mixed __get(string $propertyName)

See PHP doc.

Parameters

string $propertyName

Return Value

mixed

Exceptions

RuntimeException

in Object at line 78
public mixed __set(string $propertyName, mixed $value)

See PHP doc.

Parameters

string $propertyName
mixed $value

Return Value

mixed

Exceptions

RuntimeException

in Object at line 101
public mixed __call(string $methodName, array $args)

See PHP doc.

Call dynamically a method added with self::addMethod(). After having added a method, it is possible to call it like a declared method $object->newMethod($arg)

Parameters

string $methodName
array $args

Return Value

mixed

Exceptions

RuntimeException

in Object at line 116
public boolean isDynamic()

Indicates whether the current object has dynamic properties access.

Return Value

boolean

in Object at line 126
public setDynamic(boolean $isDynamic)

Sets dynamic properties access.

Parameters

boolean $isDynamic

in Object at line 137
public addMethod(string $name, Closure $method)

Adds a dynamic method to the object.

Parameters

string $name
Closure $method

in Object at line 147
public array toArray()

Converts an object to an array.

The exported array contains all property values of the class and its parents, which are not transient.

Return Value

array

in Object at line 157
public Json toJson(int $options = JSON_PRETTY_PRINT)

Converts an object to a Json object.

The exported data contains all property values ofn the class and its parents, who are not transient.

Parameters

int $options

Return Value

Json

in Object at line 170
public string __toString()

See PHP doc.

Return Value

string

at line 53
public IObjectsIterator getIterator()

Returns the current iterator.

Return Value

IObjectsIterator

at line 63
public setIterator(IObjectsIterator $iterator)

Sets the current Iterator.

Parameters

IObjectsIterator $iterator

at line 74
public mixed|null getByIndex(int $index)

Gets the value of the associate index.

$index can be specified even the keys are associative. If the index is 0, the method will return the first value, ... If the index is -1, the method will return the last value, ...

Parameters

int $index

Return Value

mixed|null

at line 89
public mixed|null first()

Gets the first value.

Return Value

mixed|null

at line 103
public mixed|null last()

Gets the last value.

Return Value

mixed|null

at line 117
public addFirst(mixed $value)

Adds values at the beginning of the list.

Parameters

mixed $value

at line 131
public addLast(mixed $value)

Adds values at the end of the list.

Parameters

mixed $value

at line 141
public removeFirst()

Removes first value of the list.

at line 151
public removeLast()

Removes last value of the list.