abstract class DataObject implements ArrayAccess, JsonSerializable

Constants

protected DEFAULT_DATE_FORMAT

The default date format for DateTime properties.

Properties

static array $reflectionParametersCache

Reflection parameters cache (class name => [ReflectionParameter]).

static array $propertyMapCache

Property map cache (class name => [snake_case key => camelCase property]).

static array $reversedPropertyMapCache

Reversed property map cache (class name => [camelCase key => snake_case property]).

static protected bool $autoCasting

Flag to indicate if auto-casting is enabled.

static protected array $dependenciesMapCache

Cache for dependencies map (class name => dependencies array).

static protected string $dateFormat

The date format for DateTime properties.

protected array $arrayCache

Cache for the array representation of the object.

Methods

static DataObject
make(array $data, bool $autoResolve = false)

Create an instance of the class using the provided data array.

static DataObject
from(array $data, bool $autoResolve = false)

Create an instance of the class using the provided data array.

static array
getCustomizedDependencies()

Get the customized dependencies map.

static array
getSerializers()

Get the serialization handlers for specific dependency types.

asDateTime(mixed $value, string $target)

Convert a value to the declared date target.

static bool
isStandardDateFormat(mixed $value)

Determine if the given value is a standard date format.

static array
getConvertedData(array $data)

Get the converted data array with dependencies resolved.

static array
getDependenciesData()

Get the dependencies map for the current class.

static ReflectionNamedType|null
getDependencyFromUnionType(ReflectionUnionType $type)

No description

static bool
hasNullableUnionType(ReflectionUnionType $type)

Check if the union type allows null.

static array
resolveDependenciesMap(string $class, array $visited = [])

Recursively resolve the dependencies map for the given class.

static array
replaceDependenciesData(array $dependencies, array $data)

Recursively replace dependencies data in the given data array.

static void
enableAutoCasting()

Enable or disable auto-casting of data values.

static bool
isAutoCasting()

Enable or disable auto-casting of data values.

static void
disableAutoCasting()

Disable auto-casting of data values.

static string
convertPropertyToDataKey(string $input)

Convert the property name to the data key format.

static string
convertDataKeyToProperty(string $input)

Convert the data key to the property name format.

static array
getReflectionParameters()

Get the reflection parameters for the constructor.

static mixed
convertValueToType(mixed $value, ReflectionParameter $parameter)

Convert the value to the correct type based on the parameter type.

static mixed
getDefaultValueForType(ReflectionParameter $parameter)

Get default value for the parameter type.

static array
getPropertyMap()

Get property map (snake_case key => camelCase property).

static array
getReversedPropertyMap()

Get reversed property map (camelCase key => snake_case property).

update(array $data)

Update the object properties with the provided data array.

bool
offsetExists(mixed $offset)

Check if the offset exists.

mixed
offsetGet(mixed $offset)

Get the value at the specified offset.

void
offsetSet(mixed $offset, mixed $value)

Set the value at the specified offset.

void
offsetUnset(mixed $offset)

Unset the value at the specified offset.

array
toArray()

Convert the object to an array representation.

array
jsonSerialize()

JSON serialize the object.

refresh()

Return a refreshed instance of the object with cleared cache.

static void
flushState()

Flush all static state.

Details

at line 72
static DataObject make(array $data, bool $autoResolve = false)

Create an instance of the class using the provided data array.

Parameters

array $data
bool $autoResolve

Return Value

DataObject

at line 109
static DataObject from(array $data, bool $autoResolve = false)

Create an instance of the class using the provided data array.

This is an alias of the make method.

Parameters

array $data
bool $autoResolve

Return Value

DataObject

at line 119
static protected array getCustomizedDependencies()

Get the customized dependencies map.

Return Value

array

at line 145
static protected array getSerializers()

Get the serialization handlers for specific dependency types.

Return Value

array

at line 157
static protected DateTimeInterface asDateTime(mixed $value, string $target)

Convert a value to the declared date target.

Parameters

mixed $value
string $target

Return Value

DateTimeInterface

at line 195
static protected bool isStandardDateFormat(mixed $value)

Determine if the given value is a standard date format.

Parameters

mixed $value

Return Value

bool

at line 203
static protected array getConvertedData(array $data)

Get the converted data array with dependencies resolved.

Parameters

array $data

Return Value

array

at line 220
static protected array getDependenciesData()

Get the dependencies map for the current class.

Return Value

array

at line 229
static protected ReflectionNamedType|null getDependencyFromUnionType(ReflectionUnionType $type)

No description

Parameters

ReflectionUnionType $type

Return Value

ReflectionNamedType|null

at line 251
static protected bool hasNullableUnionType(ReflectionUnionType $type)

Check if the union type allows null.

Parameters

ReflectionUnionType $type

Return Value

bool

at line 268
static protected array resolveDependenciesMap(string $class, array $visited = [])

Recursively resolve the dependencies map for the given class.

Parameters

string $class
array $visited

Return Value

array

at line 339
static protected array replaceDependenciesData(array $dependencies, array $data)

Recursively replace dependencies data in the given data array.

Parameters

array $dependencies
array $data

Return Value

array

at line 375
static void enableAutoCasting()

Enable or disable auto-casting of data values.

Boot-only. The auto-casting flag persists in a static property for the worker lifetime and affects every subsequent data object hydration.

Return Value

void

at line 383
static bool isAutoCasting()

Enable or disable auto-casting of data values.

Return Value

bool

at line 394
static void disableAutoCasting()

Disable auto-casting of data values.

Boot-only. The auto-casting flag persists in a static property for the worker lifetime and affects every subsequent data object hydration.

Return Value

void

at line 403
static string convertPropertyToDataKey(string $input)

Convert the property name to the data key format.

It converts camelCase to snake_case by default.

Parameters

string $input

Return Value

string

at line 412
static string convertDataKeyToProperty(string $input)

Convert the data key to the property name format.

It converts snake_case to camelCase by default.

Parameters

string $input

Return Value

string

at line 422
static protected array getReflectionParameters()

Get the reflection parameters for the constructor.

Return Value

array

at line 438
static protected mixed convertValueToType(mixed $value, ReflectionParameter $parameter)

Convert the value to the correct type based on the parameter type.

Parameters

mixed $value
ReflectionParameter $parameter

Return Value

mixed

at line 464
static protected mixed getDefaultValueForType(ReflectionParameter $parameter)

Get default value for the parameter type.

Parameters

ReflectionParameter $parameter

Return Value

mixed

at line 481
static protected array getPropertyMap()

Get property map (snake_case key => camelCase property).

Return Value

array

at line 508
static protected array getReversedPropertyMap()

Get reversed property map (camelCase key => snake_case property).

Return Value

array

at line 522
DataObject update(array $data)

Update the object properties with the provided data array.

Parameters

array $data

Return Value

DataObject

at line 537
bool offsetExists(mixed $offset)

Check if the offset exists.

Parameters

mixed $offset

Return Value

bool

at line 545
mixed offsetGet(mixed $offset)

Get the value at the specified offset.

Parameters

mixed $offset

Return Value

mixed

at line 557
void offsetSet(mixed $offset, mixed $value)

Set the value at the specified offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 565
void offsetUnset(mixed $offset)

Unset the value at the specified offset.

Parameters

mixed $offset

Return Value

void

at line 573
array toArray()

Convert the object to an array representation.

Return Value

array

at line 610
array jsonSerialize()

JSON serialize the object.

Return Value

array

at line 618
DataObject refresh()

Return a refreshed instance of the object with cleared cache.

Return Value

DataObject

at line 628
static void flushState()

Flush all static state.

Return Value

void