SlotSpace
in package
Defines the slot space, its dimensions, the slots that exist within it, and the edges and flows that operate on it.
Tags
Table of Contents
Properties
- $cascades : array<non-empty-string, Flow>
- $codec : SlotCodec
- $flows : array<non-empty-string, Flow>
- $timeAxis : TimeAxis|null
- $dimensionNames : array<int, TDimensionName>
- $dimensions : array<non-empty-string, array<int, non-empty-string>>
- $dispatchCalendar : DispatchCalendarInterface|null
- $durationResolver : TimedDurationResolverInterface|null
- $edgeRulesByOriginSlot : array<non-empty-string, array<int, EdgeRule>>
- Per slot key => the list of rules needed to generate the valid edges from that slot to other slots.
- $nilSlot : Slot
- $outgoingEdgeByOriginSlot : array<non-empty-string, array<non-empty-string, MovementEdge>>
- $slotsByKey : array<non-empty-string, Slot>
- $slotsByPattern : array<non-empty-string, array<int, Slot>>
- $subjectKeyResolver : Closure
Methods
- __construct() : mixed
- Create one slot space from dimensions and optional time configuration.
- cascade() : self
- Register a named cascade definition.
- define() : self
- Define one untimed slot space from dimensions.
- defineTimed() : self
- Define one timed slot space from dimensions and a time axis.
- dimensionNames() : array<int, non-empty-string>
- dimensions() : array<non-empty-string, array<int, non-empty-string>>
- dimensionValues() : array<int, non-empty-string>
- Get the list of all possible valid values for a specific dimension.
- edgeRules() : self
- This is used to generate the valid edges between slots, after the valid slots have been determined by the slot rules.
- edgesBetween() : array<string|int, MovementEdge>
- Generate edges using pattern expansion Both wildcard and missing values are supported, with the same semantics.
- edgesByLabels() : array<int, MovementEdge>
- Return all currently valid edges generated from rules matching any of the given labels.
- expandSlotPattern() : array<int, array<non-empty-string, non-empty-string>|null>
- Expand a string or array of Slot pattern into a list of partials.
- flow() : self
- Register a named flow definition.
- getCascade() : Cascade
- getDispatchCalendar() : DispatchCalendarInterface|null
- Return the configured dispatch calendar, if any.
- getDurationResolver() : TimedDurationResolverInterface|null
- Return the configured duration resolver, if any.
- getEdgesFrom() : array<non-empty-string, MovementEdge>
- Apply edge rules in sequence to generate a list of edges Cache edge list by slot key at $this->outgoingEdgeByOriginSlot.
- getFlow() : Flow
- matchPartial() : array<int, Slot>
- Finds all slots matching the given partial pattern, where the pattern can contain specific values, and '*' can be used as a wildcard expression to match any value for a dimension.
- matchPattern() : array<int, Slot>
- Resolve a slot pattern directly to matching slots.
- nilSlot() : Slot
- setDispatchCalendar() : self
- Set the dispatch calendar that may delay when timed edges may depart.
- setDurationResolver() : self
- Set the resolver used to convert base edges into timed durations.
- slot() : Slot
- Finds the slot corresponding to the given key or values. The input can be either a serialized key string or an array of dimension values, which will be serialized using the defined serializer.
- slotRules() : self
- This function is to be used after the SlotSpace is constructed and applies provided inclusion/exclusion rules in sequential order, to shape the slot space into a shape meaningful for the application domain.
- subjectKey() : non-empty-string
- Resolve one internal subject key using the space's configured resolver.
- subjectKeyResolver() : self
- Configure how arbitrary subject values are converted to stable internal keys.
- trySlot() : Slot|null
- Finds the slot corresponding to the given key or values. The input can be either a serialized key string or an array of dimension values, which will be serialized using the defined serializer.
- validateKnownDimensionNames() : void
- cartesian() : array<int, array<non-empty-string, non-empty-string>>
- Generate the cartesian product of the given dimensions, where the input is an array of dimension name to list of values, and the output is a list of all combinations of dimension values, where each combination is represented as an array of dimension name to value.
- defaultSubjectKey() : string
- normalizeDispatchCalendar() : DispatchCalendarInterface|null
- normalizeDurationResolver() : TimedDurationResolverInterface|null
Properties
$cascades
public
array<non-empty-string, Flow>
$cascades
= []
$codec
public
SlotCodec
$codec
$flows
public
array<non-empty-string, Flow>
$flows
= []
$timeAxis read-only
public
TimeAxis|null
$timeAxis
$dimensionNames
private
array<int, TDimensionName>
$dimensionNames
= []
$dimensions
private
array<non-empty-string, array<int, non-empty-string>>
$dimensions
= []
Tags
$dispatchCalendar
private
DispatchCalendarInterface|null
$dispatchCalendar
= null
$durationResolver
private
TimedDurationResolverInterface|null
$durationResolver
= null
$edgeRulesByOriginSlot
Per slot key => the list of rules needed to generate the valid edges from that slot to other slots.
private
array<non-empty-string, array<int, EdgeRule>>
$edgeRulesByOriginSlot
= []
Tags
$nilSlot
private
Slot
$nilSlot
$outgoingEdgeByOriginSlot
private
array<non-empty-string, array<non-empty-string, MovementEdge>>
$outgoingEdgeByOriginSlot
= []
Tags
$slotsByKey
private
array<non-empty-string, Slot>
$slotsByKey
= []
Tags
$slotsByPattern
private
array<non-empty-string, array<int, Slot>>
$slotsByPattern
= []
$subjectKeyResolver
private
Closure
$subjectKeyResolver
Methods
__construct()
Create one slot space from dimensions and optional time configuration.
public
__construct(array<non-empty-string, array<int, non-empty-string>> $dimensions[, TimeAxis|null $timeAxis = null ][, TimedDurationResolverInterface|Closure|null $durationResolver = null ][, SlotCodec>|null $codecClass = null ]) : mixed
Parameters
- $dimensions : array<non-empty-string, array<int, non-empty-string>>
- $timeAxis : TimeAxis|null = null
- $durationResolver : TimedDurationResolverInterface|Closure|null = null
- $codecClass : SlotCodec>|null = null
Tags
cascade()
Register a named cascade definition.
public
cascade(non-empty-string $name, callable(Cascade): mixed|array<int, array{0?: array|string|null, 1?: array|string|null, from?: array|string|null, to?: array|string|null}> $builder) : self
use flow() instead
Parameters
- $name : non-empty-string
-
$builder
: callable(Cascade): mixed|array<int, array{0?: array
|string|null, 1?: array |string|null, from?: array |string|null, to?: array |string|null}>
Tags
Return values
selfdefine()
Define one untimed slot space from dimensions.
public
static define(array<non-empty-string, array<int, non-empty-string>> $dimensions[, SlotCodec>|null $codecClass = null ]) : self
Parameters
- $dimensions : array<non-empty-string, array<int, non-empty-string>>
- $codecClass : SlotCodec>|null = null
Tags
Return values
selfdefineTimed()
Define one timed slot space from dimensions and a time axis.
public
static defineTimed(array<non-empty-string, array<int, non-empty-string>> $dimensions, TimeAxis $timeAxis[, TimedDurationResolverInterface|Closure|null $durationResolver = null ][, SlotCodec>|null $codecClass = null ]) : self
Parameters
- $dimensions : array<non-empty-string, array<int, non-empty-string>>
- $timeAxis : TimeAxis
- $durationResolver : TimedDurationResolverInterface|Closure|null = null
- $codecClass : SlotCodec>|null = null
Tags
Return values
selfdimensionNames()
public
dimensionNames() : array<int, non-empty-string>
Tags
Return values
array<int, non-empty-string>dimensions()
public
dimensions() : array<non-empty-string, array<int, non-empty-string>>
Tags
Return values
array<non-empty-string, array<int, non-empty-string>>dimensionValues()
Get the list of all possible valid values for a specific dimension.
public
dimensionValues(non-empty-string $dimension) : array<int, non-empty-string>
Parameters
- $dimension : non-empty-string
Tags
Return values
array<int, non-empty-string>edgeRules()
This is used to generate the valid edges between slots, after the valid slots have been determined by the slot rules.
public
edgeRules(RuleSet<string|int, EdgeRule>|array<int, EdgeRule|RuleSet<string|int, EdgeRule>> $rules) : self
The starting point is always an empty set of edges, and the rules are applied sequentially to add edges between slots matching the from and to patterns.
Edge rules are stored at origin slot level, to be lazily evaluated into actual edges when needed.
Parameters
Return values
selfedgesBetween()
Generate edges using pattern expansion Both wildcard and missing values are supported, with the same semantics.
public
edgesBetween(non-empty-string|array<non-empty-string, string|null>|null $fromPattern, non-empty-string|array<non-empty-string, string|null>|null $toPattern) : array<string|int, MovementEdge>
Parameters
- $fromPattern : non-empty-string|array<non-empty-string, string|null>|null
-
Specified values match with equality, wildcard/missing match with anything
- $toPattern : non-empty-string|array<non-empty-string, string|null>|null
-
Specified values are kept, wildcard/missing are filled in from the $fromPattern match
Tags
Return values
array<string|int, MovementEdge>edgesByLabels()
Return all currently valid edges generated from rules matching any of the given labels.
public
edgesByLabels(array<int, non-empty-string> $labels) : array<int, MovementEdge>
Parameters
- $labels : array<int, non-empty-string>
Return values
array<int, MovementEdge>expandSlotPattern()
Expand a string or array of Slot pattern into a list of partials.
public
expandSlotPattern(string|array<non-empty-string, string|null>|null $pattern) : array<int, array<non-empty-string, non-empty-string>|null>
Parameters
- $pattern : string|array<non-empty-string, string|null>|null
Tags
Return values
array<int, array<non-empty-string, non-empty-string>|null>flow()
Register a named flow definition.
public
flow(non-empty-string $name, callable(Flow): mixed|array<int, array{0?: array|string|null, 1?: array|string|null, from?: array|string|null, to?: array|string|null}> $builder) : self
Parameters
- $name : non-empty-string
-
$builder
: callable(Flow): mixed|array<int, array{0?: array
|string|null, 1?: array |string|null, from?: array |string|null, to?: array |string|null}>
Tags
Return values
selfgetCascade()
public
getCascade(string $name) : Cascade
use getFlow() instead
Parameters
- $name : string
Tags
Return values
CascadegetDispatchCalendar()
Return the configured dispatch calendar, if any.
public
getDispatchCalendar() : DispatchCalendarInterface|null
Return values
DispatchCalendarInterface|nullgetDurationResolver()
Return the configured duration resolver, if any.
public
getDurationResolver() : TimedDurationResolverInterface|null
Return values
TimedDurationResolverInterface|nullgetEdgesFrom()
Apply edge rules in sequence to generate a list of edges Cache edge list by slot key at $this->outgoingEdgeByOriginSlot.
public
getEdgesFrom(Slot $from) : array<non-empty-string, MovementEdge>
Parameters
- $from : Slot
Tags
Return values
array<non-empty-string, MovementEdge>getFlow()
public
getFlow(string $name) : Flow
Parameters
- $name : string
Return values
FlowmatchPartial()
Finds all slots matching the given partial pattern, where the pattern can contain specific values, and '*' can be used as a wildcard expression to match any value for a dimension.
public
matchPartial(array<non-empty-string, string|null> $partial) : array<int, Slot>
The pattern can be either a serialized key string or an array of dimension values, where missing or null values are treated as '*' wildcards.
Parameters
- $partial : array<non-empty-string, string|null>
Tags
Return values
array<int, Slot>matchPattern()
Resolve a slot pattern directly to matching slots.
public
matchPattern(array<string|int, mixed>|string|null $pattern) : array<int, Slot>
Exact string keys are short-circuited through the slot registry. General string patterns are cached after expansion so repeated lookups can reuse the resolved slot list without re-running pattern deserialization and matching.
Parameters
- $pattern : array<string|int, mixed>|string|null
Tags
Return values
array<int, Slot>nilSlot()
public
nilSlot() : Slot
Return values
SlotsetDispatchCalendar()
Set the dispatch calendar that may delay when timed edges may depart.
public
setDispatchCalendar(DispatchCalendarInterface|callable|null $dispatchCalendar) : self
Parameters
- $dispatchCalendar : DispatchCalendarInterface|callable|null
Return values
selfsetDurationResolver()
Set the resolver used to convert base edges into timed durations.
public
setDurationResolver(mixed $durationResolver) : self
Parameters
- $durationResolver : mixed
Tags
Return values
selfslot()
Finds the slot corresponding to the given key or values. The input can be either a serialized key string or an array of dimension values, which will be serialized using the defined serializer.
public
slot(Slot|string|array<string|int, string>|null $keyOrValues) : Slot
All dimensions must be specified in the input, and wildcards are not allowed.
Parameters
- $keyOrValues : Slot|string|array<string|int, string>|null
Tags
Return values
SlotslotRules()
This function is to be used after the SlotSpace is constructed and applies provided inclusion/exclusion rules in sequential order, to shape the slot space into a shape meaningful for the application domain.
public
slotRules(RuleSet<string|int, SlotRule>|array<int, SlotRule|RuleSet<string|int, SlotRule>> $rules) : self
A "full slot space" is defined by the cartesian product of all dimensions and their values, and contains all possible combinations of dimension values. Inclusion rules add matching slots to the valid set, while exclusion rules remove remove them.
Since the rules are applied sequentially, later rules may override earlier ones. The starting slot space is determined by the first rule in the list: If it is an exclusion rule, then we start with a full slot space. If it is an inclusion rule, then we start with an empty slot space.
Parameters
- $rules : RuleSet<string|int, SlotRule>|array<int, SlotRule|RuleSet<string|int, SlotRule>>
-
list of patterns to include or exclude certain slots. If the list is empty, all combinations of dimensions are included. Exclusion patterns start with '-', inclusion patterns start with '+' or have no prefix. Patterns are applied in order, so later patterns override earlier ones. If the first pattern starts with '-', it is treated as an exclusion pattern and all slots are included by default. If the first pattern starts with '+', it is treated as an inclusion pattern and no slots are included by default.
Return values
selfsubjectKey()
Resolve one internal subject key using the space's configured resolver.
public
subjectKey(mixed $subject) : non-empty-string
Parameters
- $subject : mixed
Return values
non-empty-stringsubjectKeyResolver()
Configure how arbitrary subject values are converted to stable internal keys.
public
subjectKeyResolver(callable(mixed): string $resolver) : self
Parameters
- $resolver : callable(mixed): string
Return values
selftrySlot()
Finds the slot corresponding to the given key or values. The input can be either a serialized key string or an array of dimension values, which will be serialized using the defined serializer.
public
trySlot(Slot|string|array<string|int, string>|null $keyOrValues[, bool $throwOnInvalidDimensionValues = false ]) : Slot|null
All dimensions must be specified in the input, and wildcards are not allowed.
Parameters
- $keyOrValues : Slot|string|array<string|int, string>|null
- $throwOnInvalidDimensionValues : bool = false
Tags
Return values
Slot|null —Returns the SlotKey if found, or null if no matching slot exists
validateKnownDimensionNames()
public
validateKnownDimensionNames(array<string|int, mixed> $names) : void
Parameters
- $names : array<string|int, mixed>
-
list of dimension names that must all exist in the slot space
Tags
cartesian()
Generate the cartesian product of the given dimensions, where the input is an array of dimension name to list of values, and the output is a list of all combinations of dimension values, where each combination is represented as an array of dimension name to value.
private
cartesian(array<non-empty-string, array<int, non-empty-string>> $dimensions) : array<int, array<non-empty-string, non-empty-string>>
Dimensions with empty value lists are ignored.
Parameters
- $dimensions : array<non-empty-string, array<int, non-empty-string>>
Return values
array<int, array<non-empty-string, non-empty-string>>defaultSubjectKey()
private
defaultSubjectKey(mixed $subject) : string
Parameters
- $subject : mixed
Return values
stringnormalizeDispatchCalendar()
private
static normalizeDispatchCalendar(DispatchCalendarInterface|callable|null $dispatchCalendar) : DispatchCalendarInterface|null
Parameters
- $dispatchCalendar : DispatchCalendarInterface|callable|null
Return values
DispatchCalendarInterface|nullnormalizeDurationResolver()
private
static normalizeDurationResolver(mixed $durationResolver) : TimedDurationResolverInterface|null
Parameters
- $durationResolver : mixed