abstract class MultipleInstanceManager

Traits

Properties

protected Repository $config

The configuration repository instance.

protected array $instances

The array of resolved instances.

protected array $customCreators

The registered custom instance creators.

protected string $driverKey

The key name of the "driver" equivalent configuration option.

Methods

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Application $app)

Create a new manager instance.

string
getDefaultInstance()

Get the default instance name.

void
setDefaultInstance(string $name)

Set the default instance name.

array
getInstanceConfig(string $name)

Get the instance specific configuration.

mixed
instance(string|null $name = null)

Get an instance by name.

mixed
get(string $name)

Attempt to get an instance from the local cache.

mixed
resolve(string $name)

Resolve the given instance.

mixed
callCustomCreator(array $config)

Call a custom instance creator.

forgetInstance(array|string|null $name = null)

Unset the given instances.

void
purge(string|null $name = null)

Disconnect the given instance and remove from local cache.

extend(string $name, Closure $callback)

Register a custom instance creator Closure.

setApplication(Application $app)

Set the application instance used by the manager.

mixed
__call(string $method, array $parameters)

Dynamically call the default instance.

Details

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

at line 41
__construct(Application $app)

Create a new manager instance.

Parameters

Application $app

at line 50
abstract string getDefaultInstance()

Get the default instance name.

Return Value

string

at line 58
abstract void setDefaultInstance(string $name)

Set the default instance name.

Boot-only. Implementations typically mutate process-global config; per-request use races across coroutines. Use coroutine Context for request-scoped overrides.

Parameters

string $name

Return Value

void

at line 63
abstract array getInstanceConfig(string $name)

Get the instance specific configuration.

Parameters

string $name

Return Value

array

at line 68
mixed instance(string|null $name = null)

Get an instance by name.

Parameters

string|null $name

Return Value

mixed

at line 80
protected mixed get(string $name)

Attempt to get an instance from the local cache.

Parameters

string $name

Return Value

mixed

at line 91
protected mixed resolve(string $name)

Resolve the given instance.

Parameters

string $name

Return Value

mixed

Exceptions

InvalidArgumentException
RuntimeException

at line 123
protected mixed callCustomCreator(array $config)

Call a custom instance creator.

Parameters

array $config

Return Value

mixed

at line 137
MultipleInstanceManager forgetInstance(array|string|null $name = null)

Unset the given instances.

Boot or tests only. Mutates the singleton's instance cache; concurrent coroutines may already hold a reference to the forgotten instance and next resolution will rebuild.

Parameters

array|string|null $name

Return Value

MultipleInstanceManager

at line 157
void purge(string|null $name = null)

Disconnect the given instance and remove from local cache.

Boot or tests only. Mutates the singleton's instance cache; concurrent coroutines may already hold a reference to the instance and next resolution will rebuild.

Parameters

string|null $name

Return Value

void

at line 175
MultipleInstanceManager extend(string $name, Closure $callback)

Register a custom instance creator Closure.

Boot-only. The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent instance resolution.

Parameters

string $name
Closure $callback

Return Value

MultipleInstanceManager

at line 198
MultipleInstanceManager setApplication(Application $app)

Set the application instance used by the manager.

Tests only. Swaps the singleton's application reference; per-request use races across coroutines and breaks every concurrent resolution through this manager.

Parameters

Application $app

Return Value

MultipleInstanceManager

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

Dynamically call the default instance.

Parameters

string $method
array $parameters

Return Value

mixed