DataObject
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
Create an instance of the class using the provided data array.
Create an instance of the class using the provided data array.
Get the customized dependencies map.
Get the serialization handlers for specific dependency types.
Convert a value to the declared date target.
Determine if the given value is a standard date format.
Get the converted data array with dependencies resolved.
Get the dependencies map for the current class.
No description
Check if the union type allows null.
Recursively resolve the dependencies map for the given class.
Recursively replace dependencies data in the given data array.
Enable or disable auto-casting of data values.
Enable or disable auto-casting of data values.
Disable auto-casting of data values.
Convert the property name to the data key format.
Convert the data key to the property name format.
Get the reflection parameters for the constructor.
Convert the value to the correct type based on the parameter type.
Get property map (snake_case key => camelCase property).
Get reversed property map (camelCase key => snake_case property).
Update the object properties with the provided data array.
Check if the offset exists.
Get the value at the specified offset.
Set the value at the specified offset.
Unset the value at the specified offset.
Convert the object to an array representation.
JSON serialize the object.
Return a refreshed instance of the object with cleared cache.
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.
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.
at line 119
static protected array
getCustomizedDependencies()
Get the customized dependencies map.
at line 145
static protected array
getSerializers()
Get the serialization handlers for specific dependency types.
at line 157
static protected DateTimeInterface
asDateTime(mixed $value, string $target)
Convert a value to the declared date target.
at line 195
static protected bool
isStandardDateFormat(mixed $value)
Determine if the given value is a standard date format.
at line 203
static protected array
getConvertedData(array $data)
Get the converted data array with dependencies resolved.
at line 220
static protected array
getDependenciesData()
Get the dependencies map for the current class.
at line 229
static protected ReflectionNamedType|null
getDependencyFromUnionType(ReflectionUnionType $type)
No description
at line 251
static protected bool
hasNullableUnionType(ReflectionUnionType $type)
Check if the union type allows null.
at line 268
static protected array
resolveDependenciesMap(string $class, array $visited = [])
Recursively resolve the dependencies map for the given class.
at line 339
static protected array
replaceDependenciesData(array $dependencies, array $data)
Recursively replace dependencies data in the given data 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.
at line 383
static bool
isAutoCasting()
Enable or disable auto-casting of data values.
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.
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.
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.
at line 422
static protected array
getReflectionParameters()
Get the reflection parameters for the constructor.
at line 438
static protected mixed
convertValueToType(mixed $value, ReflectionParameter $parameter)
Convert the value to the correct type based on the parameter type.
at line 464
static protected mixed
getDefaultValueForType(ReflectionParameter $parameter)
Get default value for the parameter type.
at line 481
static protected array
getPropertyMap()
Get property map (snake_case key => camelCase property).
at line 508
static protected array
getReversedPropertyMap()
Get reversed property map (camelCase key => snake_case property).
at line 522
DataObject
update(array $data)
Update the object properties with the provided data array.
at line 537
bool
offsetExists(mixed $offset)
Check if the offset exists.
at line 545
mixed
offsetGet(mixed $offset)
Get the value at the specified offset.
at line 557
void
offsetSet(mixed $offset, mixed $value)
Set the value at the specified offset.
at line 565
void
offsetUnset(mixed $offset)
Unset the value at the specified offset.
at line 573
array
toArray()
Convert the object to an array representation.
at line 610
array
jsonSerialize()
JSON serialize the object.
at line 618
DataObject
refresh()
Return a refreshed instance of the object with cleared cache.
at line 628
static void
flushState()
Flush all static state.