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 $offset)

Determine if an item exists at an offset.

mixed
offsetGet(mixed $offset)

Get an item at a given offset.

void
offsetSet(mixed $offset, mixed $value)

Set the item at a given offset.

void
offsetUnset(mixed $offset)

Unset the item at a given offset.

static void
flushState()

Flush all static state.

Details

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

Register a custom macro.

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 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

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 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

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

Return Value

void

in Macroable at line 83
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 109
mixed __call(string $method, array $parameters)

Dynamically pass a method to the underlying object.

Parameters

string $method
array $parameters

Return Value

mixed

at line 29
__construct(mixed $value)

Create a new optional instance.

Parameters

mixed $value

at line 37
mixed __get(string $key)

Dynamically access a property on the underlying object.

Parameters

string $key

Return Value

mixed

at line 49
bool __isset(mixed $name)

Dynamically check a property exists on the underlying object.

Parameters

mixed $name

Return Value

bool

at line 65
bool offsetExists(mixed $offset)

Determine if an item exists at an offset.

Parameters

mixed $offset

Return Value

bool

at line 73
mixed offsetGet(mixed $offset)

Get an item at a given offset.

Parameters

mixed $offset

Return Value

mixed

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

Set the item at a given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 91
void offsetUnset(mixed $offset)

Unset the item at a given offset.

Parameters

mixed $offset

Return Value

void

at line 101
static void flushState()

Flush all static state.

Return Value

void