class Optional implements ArrayAccess

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected mixed $value

The underlying object.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically pass a method to the underlying object.

__construct(mixed $value)

Create a new optional instance.

mixed
__get(string $key)

Dynamically access a property on the underlying object.

bool
__isset(mixed $name)

Dynamically check a property exists on the underlying object.

bool
offsetExists(mixed $key)

Determine if an item exists at an offset.

mixed
offsetGet(mixed $key)

Get an item at a given offset.

void
offsetSet(mixed $key, mixed $value)

Set the item at a given offset.

void
offsetUnset(mixed $key)

Unset the item at a given offset.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 104
mixed __call(string $method, array $parameters)

Dynamically pass a method to the underlying object.

Parameters

string $method
array $parameters

Return Value

mixed

at line 24
__construct(mixed $value)

Create a new optional instance.

Parameters

mixed $value

at line 32
mixed __get(string $key)

Dynamically access a property on the underlying object.

Parameters

string $key

Return Value

mixed

at line 44
bool __isset(mixed $name)

Dynamically check a property exists on the underlying object.

Parameters

mixed $name

Return Value

bool

at line 60
bool offsetExists(mixed $key)

Determine if an item exists at an offset.

Parameters

mixed $key

Return Value

bool

at line 68
mixed offsetGet(mixed $key)

Get an item at a given offset.

Parameters

mixed $key

Return Value

mixed

at line 76
void offsetSet(mixed $key, mixed $value)

Set the item at a given offset.

Parameters

mixed $key
mixed $value

Return Value

void

at line 86
void offsetUnset(mixed $key)

Unset the item at a given offset.

Parameters

mixed $key

Return Value

void

at line 96
static void flushState()

Flush all static state.

Return Value

void