class Repository (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Dispatcher $events

The event dispatcher instance.

protected array<string,mixed> $data

The contextual data.

protected array<string,mixed> $hidden

The hidden contextual data.

static protected callable|null $handleUnserializeExceptionsUsing

The callback that should handle unserialize exceptions.

Methods

$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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 handle calls to the class.

mixed
getSerializedPropertyValue(mixed $value, bool $withRelations = true)

Get the property value prepared for serialization.

mixed
getRestoredPropertyValue(mixed $value)

Get the restored property value after deserialization.

restoreCollection(ModelIdentifier $value)

Restore a queueable collection instance.

restoreModel(ModelIdentifier $value)

Restore the model from the model identifier instance.

getQueryForModelRestoration(Model $model, array|int $ids)

Get the query for model restoration.

array
__serialize()

Prepare the instance values for serialization.

void
__unserialize(array $values)

Restore the model after serialization.

mixed
getPropertyValue(ReflectionProperty $property)

Get the property value for the given property.

__construct(Dispatcher $events)

Create a new Context instance.

bool
has(string $key)

Determine if the given key exists.

bool
hasHidden(string $key)

Determine if the given key exists within the hidden context data.

array<string,mixed>
all()

Retrieve all the context data.

array<string,mixed>
allHidden()

Retrieve all the hidden context data.

mixed
get(string $key, mixed $default = null)

Retrieve the given key's value.

mixed
getHidden(string $key, mixed $default = null)

Retrieve the given key's hidden value.

mixed
pull(string $key, mixed $default = null)

Retrieve the given key's value and then forget it.

mixed
pullHidden(string $key, mixed $default = null)

Retrieve the given key's hidden value and then forget it.

array<string,mixed>
only(array<int,string> $keys)

Retrieve only the values of the given keys.

array<string,mixed>
onlyHidden(array<int,string> $keys)

Retrieve only the hidden values of the given keys.

$this
add(string|array<string,mixed> $key, mixed $value = null)

Add a context value.

$this
addHidden(string|array<string,mixed> $key, mixed $value = null)

Add a hidden context value.

$this
forget(string|array<int,string> $key)

Forget the given context key.

$this
forgetHidden(string|array<int,string> $key)

Forget the given hidden context key.

$this
addIf(string $key, mixed $value)

Add a context value if it does not exist yet.

$this
addHiddenIf(string $key, mixed $value)

Add a hidden context value if it does not exist yet.

$this
push(string $key, mixed ...$values)

Push the given values onto the key's stack.

$this
pushHidden(string $key, mixed ...$values)

Push the given hidden values onto the key's stack.

bool
isStackable(string $key)

Determine if a given key can be used as a stack.

bool
isHiddenStackable(string $key)

Determine if a given key can be used as a hidden stack.

bool
isEmpty()

Determine if the repository is empty.

$this
dehydrating(callable $callback)

Execute the given callback when context is about to be dehydrated.

$this
hydrated(callable $callback)

Execute the given callback when context has been hydrated.

handleUnserializeExceptionsUsing(callable|null $callback)

Handle unserialize exceptions using the given callback.

$this
flush()

Flush all context data.

?array
dehydrate()

Dehydrate the context data.

$this
hydrate(?array $context)

Hydrate the context instance.

Details

$this|TWhenReturnType when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

protected mixed getSerializedPropertyValue(mixed $value, bool $withRelations = true)

Get the property value prepared for serialization.

Parameters

mixed $value
bool $withRelations

Return Value

mixed

protected mixed getRestoredPropertyValue(mixed $value)

Get the restored property value after deserialization.

Parameters

mixed $value

Return Value

mixed

protected Collection restoreCollection(ModelIdentifier $value)

Restore a queueable collection instance.

Parameters

ModelIdentifier $value

Return Value

Collection

Model restoreModel(ModelIdentifier $value)

Restore the model from the model identifier instance.

Parameters

ModelIdentifier $value

Return Value

Model

protected Builder getQueryForModelRestoration(Model $model, array|int $ids)

Get the query for model restoration.

Parameters

Model $model
array|int $ids

Return Value

Builder

array __serialize()

Prepare the instance values for serialization.

Return Value

array

void __unserialize(array $values)

Restore the model after serialization.

Parameters

array $values

Return Value

void

protected mixed getPropertyValue(ReflectionProperty $property)

Get the property value for the given property.

Parameters

ReflectionProperty $property

Return Value

mixed

__construct(Dispatcher $events)

Create a new Context instance.

Parameters

Dispatcher $events

bool has(string $key)

Determine if the given key exists.

Parameters

string $key

Return Value

bool

bool hasHidden(string $key)

Determine if the given key exists within the hidden context data.

Parameters

string $key

Return Value

bool

array<string,mixed> all()

Retrieve all the context data.

Return Value

array<string,mixed>

array<string,mixed> allHidden()

Retrieve all the hidden context data.

Return Value

array<string,mixed>

mixed get(string $key, mixed $default = null)

Retrieve the given key's value.

Parameters

string $key
mixed $default

Return Value

mixed

mixed getHidden(string $key, mixed $default = null)

Retrieve the given key's hidden value.

Parameters

string $key
mixed $default

Return Value

mixed

mixed pull(string $key, mixed $default = null)

Retrieve the given key's value and then forget it.

Parameters

string $key
mixed $default

Return Value

mixed

mixed pullHidden(string $key, mixed $default = null)

Retrieve the given key's hidden value and then forget it.

Parameters

string $key
mixed $default

Return Value

mixed

array<string,mixed> only(array<int,string> $keys)

Retrieve only the values of the given keys.

Parameters

array<int,string> $keys

Return Value

array<string,mixed>

array<string,mixed> onlyHidden(array<int,string> $keys)

Retrieve only the hidden values of the given keys.

Parameters

array<int,string> $keys

Return Value

array<string,mixed>

$this add(string|array<string,mixed> $key, mixed $value = null)

Add a context value.

Parameters

string|array<string,mixed> $key
mixed $value

Return Value

$this

$this addHidden(string|array<string,mixed> $key, mixed $value = null)

Add a hidden context value.

Parameters

string|array<string,mixed> $key
mixed $value

Return Value

$this

$this forget(string|array<int,string> $key)

Forget the given context key.

Parameters

string|array<int,string> $key

Return Value

$this

$this forgetHidden(string|array<int,string> $key)

Forget the given hidden context key.

Parameters

string|array<int,string> $key

Return Value

$this

$this addIf(string $key, mixed $value)

Add a context value if it does not exist yet.

Parameters

string $key
mixed $value

Return Value

$this

$this addHiddenIf(string $key, mixed $value)

Add a hidden context value if it does not exist yet.

Parameters

string $key
mixed $value

Return Value

$this

$this push(string $key, mixed ...$values)

Push the given values onto the key's stack.

Parameters

string $key
mixed ...$values

Return Value

$this

Exceptions

RuntimeException

$this pushHidden(string $key, mixed ...$values)

Push the given hidden values onto the key's stack.

Parameters

string $key
mixed ...$values

Return Value

$this

Exceptions

RuntimeException

protected bool isStackable(string $key)

Determine if a given key can be used as a stack.

Parameters

string $key

Return Value

bool

protected bool isHiddenStackable(string $key)

Determine if a given key can be used as a hidden stack.

Parameters

string $key

Return Value

bool

bool isEmpty()

Determine if the repository is empty.

Return Value

bool

$this dehydrating(callable $callback)

Execute the given callback when context is about to be dehydrated.

Parameters

callable $callback

Return Value

$this

$this hydrated(callable $callback)

Execute the given callback when context has been hydrated.

Parameters

callable $callback

Return Value

$this

Repository handleUnserializeExceptionsUsing(callable|null $callback)

Handle unserialize exceptions using the given callback.

Parameters

callable|null $callback

Return Value

Repository

$this flush()

Flush all context data.

Return Value

$this

?array dehydrate()

internal  
 

Dehydrate the context data.

Return Value

?array

$this hydrate(?array $context)

internal  
 

Hydrate the context instance.

Parameters

?array $context

Return Value

$this

Exceptions

RuntimeException