class WorkerStateHelper

Collects the boot-independent facts of the checks that judge code by the request, job or operation it runs in, and builds the shared model the rules apply the booted lifetimes with.

Traits

Constants

JOB_METHODS

The lowercase names of the methods that run a queued class as a job.

private STATE_TYPES

The values that belong to one request or operation, keyed by the label diagnostics use.

private RESOLVING_FUNCTIONS

The resolving helpers, each with its abstract's parameter name and whether parameters follow.

private RESOLVING_METHODS

The resolving container methods, each with its abstract's parameter name and whether parameters follow.

private LIFETIME_ATTRIBUTES

The attributes that restrict a method to boot time or tests.

private CONFIG_WRITES

The lowercase repository methods that change configuration.

Properties

protected Container|null $container from  HasContainer

Methods

void
setContainer(Container $container)

Set the container used for resolution.

getContainer()

Return the current container.

mixed
resolve(string $abstract)

Resolve the given type from the container.

__construct(ReflectionProvider $reflectionProvider, CoroutineRuleHelper $coroutineRuleHelper, RuntimeInputs $runtimeInputs, bool $checkWorkerSharedState, bool $checkStaticStateMutation, bool $checkUnboundedWorkerCaches, bool $noRuntimeConfigMutation, bool $checkRestrictedCalls, bool $checkCancellationHandling)

Create a new worker state helper instance.

bool
isEnabled()

Determine whether any check that judges code by the operation it runs in is enabled, so the shared model's facts are collected.

bool
hasStateChecks()

Determine whether any check of the state code keeps for the worker is enabled.

analyze(CollectedDataNode $node)

Get the worker-state model of the collected data, built once for all the rules that share it.

array|null
getFunctionFacts(Scope $scope, Node $node)

Get the facts of the function the scope's code at the node runs in, or null when it is a flushState() method or one marked as boot-time or test-only.

AttributeReflection|null
getLifetimeAttribute(FunctionReflection|ExtendedMethodReflection $function)

Get the attribute marking the function as running only while the application boots or in tests.

bool
isConfigRepositoryType(Type $type)

Determine whether the type is always a configuration repository, which the rule may prove to be the global one.

bool
isConfigFunction(FuncCall $call, Scope $scope)

Determine whether the call is the global config() helper.

bool
isConfigWrite(CallLike $call, Scope $scope)

Determine whether the call changes configuration: config() with an array, a Config facade write, or a repository write method.

array|null
getConfigReceiver(Expr $expr, Scope $scope)

Describe the expression a configuration write goes through when it may be the global repository: config() without arguments, a constant resolution from the application container (its names, which the rule resolves with the booted aliases), a parameter of the innermost function typed as a repository (its name, which the rule checks the container injects), or a repository property the constructor promotes (which the rule checks the same way). Null for any other expression.

array|null
getPromotedProperty(Expr $expr, Scope $scope)

Get the constructor's declaring class and the property name when the expression reads $this's readonly property that constructor promotes, outside closures. The property then holds what the container injected into the constructor, when the container built the instance.

array
getParameters(Scope $scope)

Get the parameters of the scope's innermost function.

array|null
getResolvedAbstracts(CallLike $call, Scope $scope)

Get the abstracts a container resolution without parameters requests, or null for any other call.

array|null
getContainerResolvedAbstracts(MethodCall $call, Scope $scope)

Get the abstracts a resolution without parameters requests from a receiver known to be the container, such as the container a #[BindWhen] condition receives, or null for any other call.

array|null
getApplicationResolvedAbstracts(CallLike $call, Scope $scope)

Get the abstracts a resolution from the application container requests, or null for any other call: the resolving helpers, the App facade, or the framework's resolving method called on the application, such as app() or an injected application, or on Container::getInstance().

bool
isApplicationContainerCall(MethodCall $call, Scope $scope)

Determine whether the call runs the framework container's own method on the application: any application instance, such as app() or an injected application, or Container::getInstance().

string|null
getState(Type $type)

Get the label of the request or operation value the type always holds, ignoring null.

bool
readsRequestState(Expr $expr, Scope $scope)

Determine whether the expression reads the current request or user, without entering closures.

bool
isBoundedKey(Type $type)

Determine whether a key of the type can only take a bounded set of values.

Details

in HasContainer at line 19
void setContainer(Container $container)

Set the container used for resolution.

Parameters

Container $container

Return Value

void

in HasContainer at line 27
Container getContainer()

Return the current container.

Return Value

Container

in HasContainer at line 35
mixed resolve(string $abstract)

Resolve the given type from the container.

Parameters

string $abstract

Return Value

mixed

at line 122
__construct(ReflectionProvider $reflectionProvider, CoroutineRuleHelper $coroutineRuleHelper, RuntimeInputs $runtimeInputs, bool $checkWorkerSharedState, bool $checkStaticStateMutation, bool $checkUnboundedWorkerCaches, bool $noRuntimeConfigMutation, bool $checkRestrictedCalls, bool $checkCancellationHandling)

Create a new worker state helper instance.

Parameters

ReflectionProvider $reflectionProvider
CoroutineRuleHelper $coroutineRuleHelper
RuntimeInputs $runtimeInputs
bool $checkWorkerSharedState
bool $checkStaticStateMutation
bool $checkUnboundedWorkerCaches
bool $noRuntimeConfigMutation
bool $checkRestrictedCalls
bool $checkCancellationHandling

at line 145
bool isEnabled()

Determine whether any check that judges code by the operation it runs in is enabled, so the shared model's facts are collected.

Return Value

bool

at line 153
bool hasStateChecks()

Determine whether any check of the state code keeps for the worker is enabled.

Return Value

bool

at line 164
WorkerStateAnalysis analyze(CollectedDataNode $node)

Get the worker-state model of the collected data, built once for all the rules that share it.

Parameters

CollectedDataNode $node

Return Value

WorkerStateAnalysis

at line 188
array|null getFunctionFacts(Scope $scope, Node $node)

Get the facts of the function the scope's code at the node runs in, or null when it is a flushState() method or one marked as boot-time or test-only.

The context is the operation the code always runs in when the class alone decides it: a queued class's handle(), __invoke() or failed(), or a form request's method. The rule adds booted middleware and controller actions, the helpers those methods call on their own instance, and route closures by the node's position.

Parameters

Scope $scope
Node $node

Return Value

array|null

at line 219
AttributeReflection|null getLifetimeAttribute(FunctionReflection|ExtendedMethodReflection $function)

Get the attribute marking the function as running only while the application boots or in tests.

Parameters

FunctionReflection|ExtendedMethodReflection $function

Return Value

AttributeReflection|null

at line 231
bool isConfigRepositoryType(Type $type)

Determine whether the type is always a configuration repository, which the rule may prove to be the global one.

Parameters

Type $type

Return Value

bool

at line 239
bool isConfigFunction(FuncCall $call, Scope $scope)

Determine whether the call is the global config() helper.

Parameters

FuncCall $call
Scope $scope

Return Value

bool

at line 249
bool isConfigWrite(CallLike $call, Scope $scope)

Determine whether the call changes configuration: config() with an array, a Config facade write, or a repository write method.

Parameters

CallLike $call
Scope $scope

Return Value

bool

at line 281
array|null getConfigReceiver(Expr $expr, Scope $scope)

Describe the expression a configuration write goes through when it may be the global repository: config() without arguments, a constant resolution from the application container (its names, which the rule resolves with the booted aliases), a parameter of the innermost function typed as a repository (its name, which the rule checks the container injects), or a repository property the constructor promotes (which the rule checks the same way). Null for any other expression.

Parameters

Expr $expr
Scope $scope

Return Value

array|null

at line 313
array|null getPromotedProperty(Expr $expr, Scope $scope)

Get the constructor's declaring class and the property name when the expression reads $this's readonly property that constructor promotes, outside closures. The property then holds what the container injected into the constructor, when the container built the instance.

Parameters

Expr $expr
Scope $scope

Return Value

array|null

at line 344
array getParameters(Scope $scope)

Get the parameters of the scope's innermost function.

Parameters

Scope $scope

Return Value

array

at line 356
array|null getResolvedAbstracts(CallLike $call, Scope $scope)

Get the abstracts a container resolution without parameters requests, or null for any other call.

Parameters

CallLike $call
Scope $scope

Return Value

array|null

at line 383
array|null getContainerResolvedAbstracts(MethodCall $call, Scope $scope)

Get the abstracts a resolution without parameters requests from a receiver known to be the container, such as the container a #[BindWhen] condition receives, or null for any other call.

Parameters

MethodCall $call
Scope $scope

Return Value

array|null

at line 426
array|null getApplicationResolvedAbstracts(CallLike $call, Scope $scope)

Get the abstracts a resolution from the application container requests, or null for any other call: the resolving helpers, the App facade, or the framework's resolving method called on the application, such as app() or an injected application, or on Container::getInstance().

Another container, or one overriding the method, may hold other bindings than the booted ones.

Parameters

CallLike $call
Scope $scope

Return Value

array|null

at line 441
bool isApplicationContainerCall(MethodCall $call, Scope $scope)

Determine whether the call runs the framework container's own method on the application: any application instance, such as app() or an injected application, or Container::getInstance().

Another container, or one overriding the method, may hold other bindings than the booted ones.

Parameters

MethodCall $call
Scope $scope

Return Value

bool

at line 464
string|null getState(Type $type)

Get the label of the request or operation value the type always holds, ignoring null.

Parameters

Type $type

Return Value

string|null

at line 486
bool readsRequestState(Expr $expr, Scope $scope)

Determine whether the expression reads the current request or user, without entering closures.

Parameters

Expr $expr
Scope $scope

Return Value

bool

at line 528
bool isBoundedKey(Type $type)

Determine whether a key of the type can only take a bounded set of values.

Parameters

Type $type

Return Value

bool