class ScopeManager (View source)

This tracks the current scope for an SSViewer instance. It has three goals:

  • Handle entering & leaving sub-scopes in loops and withs
  • Track Up and Top
  • (As a side effect) Inject data that needs to be available globally (used to live in ModelData)

It is also responsible for mixing in data on top of what the item provides. This can be "global" data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like (like $FirstLast etc).

In order to handle up, rather than tracking it using a tree, which would involve constructing new objects for each step, we use indexes into the itemStack (which already has to exist).

Each item has three indexes associated with it

  • Pop. Which item should become the scope once the current scope is popped out of
  • Up. Which item is up from this item
  • Current. Which item is the first time this object has appeared in the stack

We also keep the index of the current starting point for lookups. A lookup is a sequence of obj calls - when in a loop or with tag the end result becomes the new scope, but for injections, we throw away the lookup and revert back to the original scope once we've got the value we're after

Constants

ITEM

ITEM_ITERATOR

ITEM_ITERATOR_TOTAL

POP_INDEX

UP_INDEX

CURRENT_INDEX

ITEM_OVERLAY

Properties

protected ViewLayerData|null $item

The current "global" item (the one any lookup starts from)

protected Iterator|null $itemIterator

If we're looping over the current "global" item, here's the iterator that tracks with item we're up to

protected int $itemIteratorTotal

Total number of items in the iterator

protected array $overlay

Overlay variables. Take precedence over anything from the current scope

protected bool $preserveOverlay

Flag for whether overlay should be preserved when pushing a new scope

protected array $underlay

Underlay variables. Concede precedence to overlay variables or anything from the current scope

Methods

public
__construct(ViewLayerData|null $item, array $overlay = [], array $underlay = [], ScopeManager|null $inheritedScope = null)

No description

public
ViewLayerData|null
getCurrentItem()

Returns the current "current" item in scope

public
locally()

Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope

public
scopeToIntermediateValue(string $name, array $arguments)

Set scope to an intermediate value, which will be used for getting output later on.

public
ViewLayerData|null
self()

Gets the current object and resets the scope.

public
pushScope()

Jump to the last item in the stack, called when a new item is added before a loop/with

public
popScope()

Jump back to "previous" item in the stack, called after a loop/with block

public
bool
next()

Fast-forwards the current iterator to the next item.

public
string
getOutputValue(string $name, array $arguments)

Get the value that will be directly rendered in the template.

public
mixed
getValueAsArgument(string $name, array $arguments)

Get the value to pass as an argument to a method.

public
bool
hasValue(string $name, array $arguments)

Check if the current item in scope has a value for the named field.

protected
resetLocalScope()

Reset the local scope - restores saved state to the "global" item stack. Typically called after a lookup chain has been completed

protected
array
getItemStack()

No description

protected
setItemStack(array $stack)

No description

protected
int|null
getUpIndex()

No description

protected
array
processTemplateOverride(string $property, array $overrides)

Evaluate a template override. Returns an array where the presence of a 'value' key indiciates whether an override was successfully found, as null is a valid override value

protected
cacheGlobalProperties()

Build cache of global properties

protected
cacheIteratorProperties()

Build cache of global iterator properties

protected
ViewLayerData|null
getObj(string $name, array $arguments)

No description

protected
bool
hasOverlay(string $property)

No description

protected
mixed
getOverlay(string $property, array $args, bool $getRaw = false)

No description

protected
mixed
getUnderlay(string $property, array $args, bool $getRaw = false)

No description

protected
getInjectedValue(TemplateIteratorProvider $source, string $property, array $params, bool $getRaw = false)

No description

Details

__construct(ViewLayerData|null $item, array $overlay = [], array $underlay = [], ScopeManager|null $inheritedScope = null)

No description

Parameters

ViewLayerData|null $item
array $overlay
array $underlay
ScopeManager|null $inheritedScope

ViewLayerData|null getCurrentItem()

Returns the current "current" item in scope

Return Value

ViewLayerData|null

ScopeManager locally()

Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope

Return Value

ScopeManager

ScopeManager scopeToIntermediateValue(string $name, array $arguments)

Set scope to an intermediate value, which will be used for getting output later on.

Parameters

string $name
array $arguments

Return Value

ScopeManager

ViewLayerData|null self()

Gets the current object and resets the scope.

Return Value

ViewLayerData|null

ScopeManager pushScope()

Jump to the last item in the stack, called when a new item is added before a loop/with

Store the current overlay (as it doesn't directly apply to the new scope that's being pushed). We want to store the overlay against the next item "up" in the stack (hence upIndex), rather than the current item, because ScopeManager::obj() has already been called and pushed the new item to the stack by this point

Return Value

ScopeManager

ScopeManager popScope()

Jump back to "previous" item in the stack, called after a loop/with block

Now that we're going to jump up an item in the item stack, we need to restore the overlay that was previously stored against the next item "up" in the stack from the current one

Return Value

ScopeManager

bool next()

Fast-forwards the current iterator to the next item.

Return Value

bool

True if there's an item, false if not.

string getOutputValue(string $name, array $arguments)

Get the value that will be directly rendered in the template.

Parameters

string $name
array $arguments

Return Value

string

mixed getValueAsArgument(string $name, array $arguments)

Get the value to pass as an argument to a method.

Parameters

string $name
array $arguments

Return Value

mixed

bool hasValue(string $name, array $arguments)

Check if the current item in scope has a value for the named field.

Parameters

string $name
array $arguments

Return Value

bool

protected resetLocalScope()

Reset the local scope - restores saved state to the "global" item stack. Typically called after a lookup chain has been completed

protected array getItemStack()

No description

Return Value

array

protected setItemStack(array $stack)

No description

Parameters

array $stack

protected int|null getUpIndex()

No description

Return Value

int|null

protected array processTemplateOverride(string $property, array $overrides)

Evaluate a template override. Returns an array where the presence of a 'value' key indiciates whether an override was successfully found, as null is a valid override value

Parameters

string $property

Name of override requested

array $overrides

List of overrides available

Return Value

array

An array with a 'value' key if a value has been found, or empty if not

protected cacheGlobalProperties()

Build cache of global properties

protected cacheIteratorProperties()

Build cache of global iterator properties

protected ViewLayerData|null getObj(string $name, array $arguments)

No description

Parameters

string $name
array $arguments

Return Value

ViewLayerData|null

protected bool hasOverlay(string $property)

No description

Parameters

string $property

Return Value

bool

protected mixed getOverlay(string $property, array $args, bool $getRaw = false)

No description

Parameters

string $property
array $args
bool $getRaw

Return Value

mixed

protected mixed getUnderlay(string $property, array $args, bool $getRaw = false)

No description

Parameters

string $property
array $args
bool $getRaw

Return Value

mixed

protected getInjectedValue(TemplateIteratorProvider $source, string $property, array $params, bool $getRaw = false)

No description

Parameters

TemplateIteratorProvider $source
string $property
array $params
bool $getRaw