ObjectField
extends ExtendedObject
in package
Класс представление поля типа обьект
Tags
Table of Contents
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.
- $_datarow : ExtendedObject|null
- $_field : Field
- Поле
- $_original : mixed
- Contains data received during initialization.
- $_prefix : string|null
- Prefix for properties, to ensure proper operation with storages.
- $_storage : Storage
- Хранилище
- $_validationResult : ValidationResult
- Validation results
- $casts : array<string|int, mixed>
Methods
- __construct() : void
- Конструктор
- __destruct() : mixed
- Destructor
- __get() : mixed
- Геттер
- __isset() : bool
- Checks whether a property is set in the object.
- __set() : void
- Сеттер
- __toString() : string
- Return string value of this 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.
- Field() : Field
- 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.
- Storage() : Storage
- 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.
- ToString() : 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
- Замена типов
- _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
$_data
Object data, properties.
protected
mixed
$_data
$_datarow
protected
ExtendedObject|null
$_datarow
= null
$_field
Поле
protected
Field
$_field
= null
$_original
Contains data received during initialization.
protected
mixed
$_original
$_prefix
Prefix for properties, to ensure proper operation with storages.
protected
string|null
$_prefix
= ""
$_storage
Хранилище
protected
Storage
$_storage
= null
$_validationResult
Validation results
protected
ValidationResult
$_validationResult
$casts
protected
static array<string|int, mixed>
$casts
= []
Methods
__construct()
Конструктор
public
__construct(string|mixed $data[, Storage $storage = null ][, Field $field = null ][, ExtendedObject|null $datarow = null ]) : void
Parameters
- $data : string|mixed
-
данные
- $storage : Storage = null
-
хранилище
- $field : Field = null
-
поле
- $datarow : ExtendedObject|null = null
__destruct()
Destructor
public
__destruct() : mixed
__get()
Геттер
public
__get(string $prop) : mixed
Parameters
- $prop : string
-
свойство
Return values
mixed —значение
__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()
Сеттер
public
__set(string $property, mixed $value) : void
Parameters
- $property : string
-
свойство
- $value : mixed
-
значение
__toString()
Return string value of this object
public
__toString() : string
Return values
string__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.
Clear()
Cleans object
public
Clear() : mixed
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.
Field()
public
Field() : Field
Return values
FieldGetData()
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
selfIsChanged()
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
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
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
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
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
selfSchema()
public
static Schema([bool $exportAsString = false ][, mixed $addElements = [] ]) : object|string
Parameters
- $exportAsString : bool = false
- $addElements : mixed = []
Return values
object|stringSetData()
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.
Storage()
public
Storage() : Storage
Return values
StorageToArray()
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.
ToString()
Возвращает в виде строки
public
ToString() : string
Return values
string —результат JSON
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
Return values
bool —True if the object's data is valid according to the schema, false otherwise.
_typeExchange()
Замена типов
protected
_typeExchange(string $mode, string $property[, mixed $value = false ]) : mixed
Parameters
- $mode : string
-
режим, get или set
- $property : string
-
свойство
- $value : mixed = false
-
значение
Return values
mixed —результат
_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.