class WorkerLifetimes

The worker lifetimes of one analysis: which classes the booted container shares across requests, which methods handle a request or run a job, and which parameters it fills with fresh or shared values.

Roots come from the booted routes, middleware, listeners and Bus handlers, and from the collected resolutions, singletons and jobs. Each class they build is walked the way the container resolves it. Classes are read through PHPStan reflection and factories are never called: resolving or loading an analyzed class at runtime would run its code.

Constants

private SHARED

private SCOPED

private FRESH

private DEFAULT

private UNKNOWN

private COPY_CLONE

The clone of the container's queued listener that CallQueuedListener runs a job on, which keeps what its constructor was given.

private COPY_WITHOUT_CONSTRUCTOR

The instance the dispatcher makes of a queued listener without its constructor to read the job's options.

private LISTENER_OPTION_METHODS

The option methods the dispatcher calls on that instance whenever it queues a listener (Dispatcher::queueHandler() and propagateListenerOptions()).

private EVENT_CONTEXTS

The framework events dispatched for one request, job or server operation, with the context their listeners run in.

Methods

__construct(ReflectionProvider $reflectionProvider, Container $container, array $abstracts, array $singletons, array $queued, array $helperCalls, array $observers)

Discover the worker lifetimes of the booted application and the collected roots.

bool
isShared(string $class)

Determine whether the container shares the class, or a subclass of it, across requests.

TrinaryLogic
sharesAbstract(string $abstract)

Determine whether resolving the abstract without parameters returns the instance the container shares for the worker.

string|null
getContext(string $class, string $method)

Get the operation a booted middleware, controller action, job, listener or observer method handles, or null.

bool
isContextShared(string $class, string $method)

Determine whether a worker-shared instance handles the booted handler method, rather than only scoped or fresh ones.

bool
runsOnCopy(string $class, string $method)

Determine whether only copies of a queued listener run the method: the clone CallQueuedListener makes of the container's instance for each job, or the instance the dispatcher makes without its constructor to read the job's options. Each has its own properties and arrays, but a clone shares the objects they hold, so only writes that replace them stay with the copy.

bool
isConfigParameter(string $class, string $method, string $parameter)

Determine whether the container injects the global configuration repository into the parameter of a booted controller action, a job's handler or a constructor it runs.

TrinaryLogic
sharesInjectedParameter(string $class, string $method, string $parameter)

Determine whether the container injects the instance it shares for the worker into the parameter of a booted controller action, a job's handler or a constructor it runs.

bool
isContainerBuilt(string $class, string $method)

Determine whether the container built every instance the method handles an operation for, so the properties its constructor promotes hold what the container injected.

bool
isGlobalConfig(string $abstract)

Determine whether the container name resolves the global configuration repository, which the framework registers as "config" with its contract and class as aliases.

bool
isFreshParameter(string $class, string $parameter)

Determine whether every shared instance built with the class's constructor gets the parameter's default or a fresh value from the container.

bool
isJob(string $class)

Determine whether the class is a job whose handler the container calls with injected parameters.

array
getClasses()

Get the classes whose declarations the lifetimes were read from.

array
getDefaultSources()

Get the classes whose property defaults the lifetimes were read from, which aren't declarations.

static string|null
getBindingConcrete(Closure $closure)

Get the class a binding's closure builds when it was registered with a class name.

static bool
isBuildableClass(ClassReflection $class)

Determine whether the container builds the class itself: an instantiable class without its own Bind or BindWhen attributes.

Details

at line 237
__construct(ReflectionProvider $reflectionProvider, Container $container, array $abstracts, array $singletons, array $queued, array $helperCalls, array $observers)

Discover the worker lifetimes of the booted application and the collected roots.

Parameters

ReflectionProvider $reflectionProvider
Container $container
array $abstracts

the abstracts resolved without parameters

array $singletons

the classes declaring #[Singleton]

array $queued

the concrete queued classes

array $helperCalls

the direct calls methods make on their own instance

array $observers

the #[ObservedBy] observer classes, each with the model events it can handle

at line 300
bool isShared(string $class)

Determine whether the container shares the class, or a subclass of it, across requests.

Parameters

string $class

Return Value

bool

at line 323
TrinaryLogic sharesAbstract(string $abstract)

Determine whether resolving the abstract without parameters returns the instance the container shares for the worker.

A bind() factory may return a shared object, so its resolution is unknown.

Parameters

string $abstract

Return Value

TrinaryLogic

at line 336
string|null getContext(string $class, string $method)

Get the operation a booted middleware, controller action, job, listener or observer method handles, or null.

Parameters

string $class
string $method

Return Value

string|null

at line 345
bool isContextShared(string $class, string $method)

Determine whether a worker-shared instance handles the booted handler method, rather than only scoped or fresh ones.

Parameters

string $class
string $method

Return Value

bool

at line 356
bool runsOnCopy(string $class, string $method)

Determine whether only copies of a queued listener run the method: the clone CallQueuedListener makes of the container's instance for each job, or the instance the dispatcher makes without its constructor to read the job's options. Each has its own properties and arrays, but a clone shares the objects they hold, so only writes that replace them stay with the copy.

Parameters

string $class
string $method

Return Value

bool

at line 365
bool isConfigParameter(string $class, string $method, string $parameter)

Determine whether the container injects the global configuration repository into the parameter of a booted controller action, a job's handler or a constructor it runs.

Parameters

string $class
string $method
string $parameter

Return Value

bool

at line 376
TrinaryLogic sharesInjectedParameter(string $class, string $method, string $parameter)

Determine whether the container injects the instance it shares for the worker into the parameter of a booted controller action, a job's handler or a constructor it runs.

Parameters

string $class
string $method
string $parameter

Return Value

TrinaryLogic

at line 395
bool isContainerBuilt(string $class, string $method)

Determine whether the container built every instance the method handles an operation for, so the properties its constructor promotes hold what the container injected.

A queued class is restored from its payload, except one the dispatcher resolves as a listener or observer. A method no booted handler reaches is judged by its own class. One that a queued listener's instance made without its constructor runs may initialize a readonly promoted property itself.

Parameters

string $class
string $method

Return Value

bool

at line 417
bool isGlobalConfig(string $abstract)

Determine whether the container name resolves the global configuration repository, which the framework registers as "config" with its contract and class as aliases.

Parameters

string $abstract

Return Value

bool

at line 426
bool isFreshParameter(string $class, string $parameter)

Determine whether every shared instance built with the class's constructor gets the parameter's default or a fresh value from the container.

Parameters

string $class
string $parameter

Return Value

bool

at line 434
bool isJob(string $class)

Determine whether the class is a job whose handler the container calls with injected parameters.

Parameters

string $class

Return Value

bool

at line 448
array getClasses()

Get the classes whose declarations the lifetimes were read from.

Return Value

array

at line 458
array getDefaultSources()

Get the classes whose property defaults the lifetimes were read from, which aren't declarations.

Return Value

array

at line 1243
static string|null getBindingConcrete(Closure $closure)

Get the class a binding's closure builds when it was registered with a class name.

Parameters

Closure $closure

Return Value

string|null

at line 1258
static bool isBuildableClass(ClassReflection $class)

Determine whether the container builds the class itself: an instantiable class without its own Bind or BindWhen attributes.

Parameters

ClassReflection $class

Return Value

bool