Documentation

ExtendedObject implements ArrayAccess, IteratorAggregate, JsonSerializable, Countable Uses TEventDispatcher

Base class for objects. All object-like classes and instances will inherit from this class.

Table of Contents

Interfaces

ArrayAccess
IteratorAggregate
JsonSerializable
Countable

Constants

JsonSchema  = ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]
Data validation schema.

Properties

$_changed  : bool|null
Object change indicator.
$_changeKeyCase  : bool|null
Change case on object keys
$_data  : mixed
Object data, properties.
$_original  : mixed
Contains data received during initialization.
$_prefix  : string|null
Prefix for properties, to ensure proper operation with storages.
$_validationResult  : ValidationResult
Validation results

Methods

__construct()  : mixed
Constructor
__destruct()  : mixed
Destructor
__get()  : mixed
Retrieves the value of a dynamic or inaccessible property from the object.
__isset()  : bool
Checks whether a property is set in the object.
__set()  : void
Sets the value of a dynamic or inaccessible property within the object.
__unset()  : void
Unsets a property in the object.
Clear()  : mixed
Cleans object
Count()  : int
Counts the number of elements in the object.
DispatchEvent()  : object|null
Dispatches an event.
GetData()  : mixed
Retrieves the current data of the object.
getIterator()  : ExtendedObjectIterator
Returns an iterator for iterating over the data of the ExtendedObject.
GetValidationData()  : mixed
Retrieves the validation data used for schema validation.
HandleEvent()  : self
Adds an event handler.
IsChanged()  : bool
Checks if the object has been changed.
IsPropertyChanged()  : bool
Checks if a specific property of the object has been changed.
jsonSerialize()  : array<string|int, mixed>
Serializes the object to a value that can be serialized by json_encode.
JsonUnserialize()  : static
Constructs a new object instance from a JSON-encoded string.
offsetExists()  : bool
Checks if a value exists at the specified offset.
offsetGet()  : mixed|null
Retrieves the value at the specified offset.
offsetSet()  : void
Sets the value at the specified offset.
offsetUnset()  : void
Unsets the value at the specified offset.
Original()  : object
Returns the original data provided during object initialization.
Prefix()  : string
Retrieves the prefix used for object properties.
RemoveHandler()  : self
Removes an event handler.
Schema()  : object|string
SetData()  : void
Sets data for the object.
ToArray()  : array<string|int, mixed>
Converts the object's data to an associative array.
ToJSON()  : string
Converts the object's data to a JSON string.
UpdateOriginal()  : void
Updates the original data with the current data of the object.
Validate()  : bool
Validates the object's data against a JSON schema.
_typeExchange()  : mixed
Handles the exchange of property values based on the specified mode.
_typeToData()  : mixed
Converts data for retrieval via the GetData method.

Constants

JsonSchema

Data validation schema.

public mixed JsonSchema = ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]

Properties

$_changed

Object change indicator.

protected bool|null $_changed = false

$_changeKeyCase

Change case on object keys

protected bool|null $_changeKeyCase = true

$_original

Contains data received during initialization.

protected mixed $_original

$_prefix

Prefix for properties, to ensure proper operation with storages.

protected string|null $_prefix = ""

$_validationResult

Validation results

protected ValidationResult $_validationResult

Methods

__construct()

Constructor

public __construct([mixed $data = null ][, string $prefix = "" ][, bool $changeKeyCase = true ]) : mixed
Parameters
$data : mixed = null
  • initialization data
$prefix : string = ""
  • prefix
$changeKeyCase : bool = true
  • change key case

__get()

Retrieves the value of a dynamic or inaccessible property from the object.

public __get(string $property) : mixed

This magic method is invoked when attempting to access a property that is not accessible or does not exist within the object's scope using the arrow operator (->).

Parameters
$property : string

The name of the property to retrieve.

Return values
mixed

The value of the specified property.

__isset()

Checks whether a property is set in the object.

public __isset(string $property) : bool

This magic method is triggered when attempting to check whether a property is set in the object using isset().

Parameters
$property : string

The name of the property being checked.

Return values
bool

Returns true if the property is set, false otherwise.

__set()

Sets the value of a dynamic or inaccessible property within the object.

public __set(string $property, mixed $value) : void

This magic method is invoked when attempting to assign a value to a property that is not accessible or does not exist within the object's scope using the arrow operator (->).

Parameters
$property : string

The name of the property to set.

$value : mixed

The value to assign to the property.

__unset()

Unsets a property in the object.

public __unset(string $property) : void

This magic method is triggered when attempting to unset a property in the object using unset().

Parameters
$property : string

The name of the property to unset.

Count()

Counts the number of elements in the object.

public Count() : int

This method returns the number of elements in the object.

Return values
int

The number of elements in the object.

DispatchEvent()

Dispatches an event.

public DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
$event : string|Event

The event object or its name.

$args : mixed = null

Additional arguments to pass to the event handlers.

$async : bool = false

Whether to dispatch the event asynchronously.

Return values
object|null

The event object with updated arguments, or null if the event does not exist.

GetData()

Retrieves the current data of the object.

public GetData([bool $type = true ]) : mixed

This method returns the current data of the object. If the $type parameter is set to true, the data is converted according to the object's type conversion rules; otherwise, the raw data is returned without conversion.

Parameters
$type : bool = true

Optional. Determines whether to convert the data according to type conversion rules. Defaults to true.

Return values
mixed

The current data of the object.

getIterator()

Returns an iterator for iterating over the data of the ExtendedObject.

public getIterator() : ExtendedObjectIterator

This method returns an iterator that allows iterating over the data of the ExtendedObject. It enables the use of foreach loops and other iterable operations on ExtendedObject instances.

Return values
ExtendedObjectIterator

An iterator for the data of the ExtendedObject.

GetValidationData()

Retrieves the validation data used for schema validation.

public GetValidationData() : mixed

This method returns the data that is used for schema validation. It can be useful for debugging or accessing the data before validation.

Return values
mixed

The validation data used for schema validation.

HandleEvent()

Adds an event handler.

public HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
$ename : array<string|int, mixed>|string

The event name or an array of event names.

$listener : mixed

The event handler.

Return values
self

IsChanged()

Checks if the object has been changed.

public IsChanged() : bool

This method determines whether any changes have been made to the object's data since its initialization or the last update. It returns true if changes have been made, indicating that the object state is different from its original state; otherwise, it returns false.

Return values
bool

True if the object has been changed; otherwise, false.

IsPropertyChanged()

Checks if a specific property of the object has been changed.

public IsPropertyChanged(string $property[, bool $dummy = false ]) : bool

This method determines whether a particular property of the object has been modified since its initialization or the last update. It returns true if the specified property has been changed; otherwise, it returns false.

Parameters
$property : string

The name of the property to check for changes.

$dummy : bool = false

Optional. A dummy parameter to maintain method signature consistency.

Return values
bool

True if the specified property has been changed; otherwise, false.

jsonSerialize()

Serializes the object to a value that can be serialized by json_encode.

public jsonSerialize() : array<string|int, mixed>

This method is called during JSON serialization of the object. It allows the object to be serialized to a JSON-serializable representation using the json_encode function.

Return values
array<string|int, mixed>

The serializable representation of the object.

JsonUnserialize()

Constructs a new object instance from a JSON-encoded string.

public static JsonUnserialize(string $json) : static

This method creates a new instance of the class from a JSON-encoded string. It accepts a JSON string representing the object and returns a new instance of the class.

Parameters
$json : string

The JSON-encoded string representing the object.

Return values
static

The new instance of the class.

offsetExists()

Checks if a value exists at the specified offset.

public offsetExists(string|int $offset) : bool

This method checks if a value exists at the specified offset in the ExtendedObject. It allows checking the existence of values using array access syntax, e.g., isset($object['key']).

Parameters
$offset : string|int

The offset to check.

Tags
throws
InvalidArgumentException

If the offset is not a string or an integer.

Return values
bool

True if a value exists at the specified offset, false otherwise.

offsetGet()

Retrieves the value at the specified offset.

public offsetGet(string|int $offset) : mixed|null

This method retrieves the value at the specified offset in the ExtendedObject. It allows accessing values using array access syntax, e.g., $value = $object['key'].

Parameters
$offset : string|int

The offset of the value to retrieve.

Tags
throws
InvalidArgumentException

If the offset is not a string or an integer.

Return values
mixed|null

The value at the specified offset, or null if the offset does not exist.

offsetSet()

Sets the value at the specified offset.

public offsetSet(string|int $offset, mixed $value) : void

This method sets the value at the specified offset in the ExtendedObject. It allows setting values using array access syntax, e.g., $object['key'] = $value.

Parameters
$offset : string|int

The offset at which to set the value.

$value : mixed

The value to set at the specified offset.

Tags
throws
InvalidArgumentException

If the offset is not a string or an integer.

offsetUnset()

Unsets the value at the specified offset.

public offsetUnset(string|int $offset) : void

This method unsets the value at the specified offset in the ExtendedObject. It allows unsetting values using array access syntax, e.g., unset($object['key']).

Parameters
$offset : string|int

The offset of the value to unset.

Tags
throws
InvalidArgumentException

If the offset is not a string or an integer.

Original()

Returns the original data provided during object initialization.

public Original() : object

This method returns the original data provided during object initialization as an object. The original data represents the state of the object before any changes.

Return values
object

An object containing the original data provided during initialization.

Prefix()

Retrieves the prefix used for object properties.

public Prefix() : string

This method returns the prefix used for object properties. The prefix is typically set during object initialization and is useful for distinguishing properties when working with storage systems.

Return values
string

The prefix used for object properties.

RemoveHandler()

Removes an event handler.

public RemoveHandler(string $ename, mixed $listener) : self
Parameters
$ename : string

The event name.

$listener : mixed

The event handler to remove.

Return values
self

Schema()

public static Schema([bool $exportAsString = false ][, mixed $addElements = [] ]) : object|string
Parameters
$exportAsString : bool = false
$addElements : mixed = []
Return values
object|string

SetData()

Sets data for the object.

public SetData(mixed $data) : void

This method allows setting data for the object. It can accept various types of data, such as arrays, objects, or ExtendedObject instances.

Parameters
$data : mixed

The data to set for the object.

ToArray()

Converts the object's data to an associative array.

public ToArray([bool $noPrefix = false ][, Closure|null $callback = null ]) : array<string|int, mixed>

This method converts the object's data to an associative array. Optionally, you can specify whether to exclude the prefix from property names and provide a callback function to filter the properties included in the array.

Parameters
$noPrefix : bool = false

Whether to exclude the prefix from property names.

$callback : Closure|null = null

A callback function to filter properties included in the array.

Return values
array<string|int, mixed>

An associative array representing the object's data.

ToJSON()

Converts the object's data to a JSON string.

public ToJSON() : string

This method serializes the object's data into a JSON string representation.

Return values
string

The JSON string representing the object's data.

UpdateOriginal()

Updates the original data with the current data of the object.

public UpdateOriginal() : void

This method updates the original data of the object with its current data. It is typically used after modifying the object's data to synchronize the original and current states.

Validate()

Validates the object's data against a JSON schema.

public Validate([bool $throwExceptions = false ]) : bool

This method validates the object's data against a predefined JSON schema. If the validation fails, it returns false. Optionally, you can set $throwExceptions to true to throw a ValidationException upon failure.

Parameters
$throwExceptions : bool = false

Whether to throw a ValidationException upon failure.

Tags
throws
ValidationException

If $throwExceptions is true and the validation fails.

Return values
bool

True if the object's data is valid according to the schema, false otherwise.

_typeExchange()

Handles the exchange of property values based on the specified mode.

protected _typeExchange(string $mode, string $property[, mixed $value = null ]) : mixed

This method is responsible for managing the exchange of property values based on the specified mode ('get' or 'set'). It is used internally to retrieve or assign values to object properties dynamically.

Parameters
$mode : string

The mode of operation ('get' or 'set').

$property : string

The name of the property to interact with.

$value : mixed = null

The value to assign to the property (only applicable in 'set' mode).

Return values
mixed

The value of the property (in 'get' mode) or null (in 'set' mode).

_typeToData()

Converts data for retrieval via the GetData method.

protected _typeToData(mixed $data) : mixed

This method is responsible for converting data to be retrieved via the GetData method. It is intended to be overridden in subclasses to customize the conversion behavior if needed.

Parameters
$data : mixed

The data to be converted.

Return values
mixed

The converted data.


        
On this page

Search results