class SSViewer_Scope (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 ViewableData)

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 object $item

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

protected Iterator $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

Methods

public
__construct($item, SSViewer_Scope $inheritedScope = null)

No description

public
object
getItem()

Returns the current "active" item

public
locally()

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

public
resetLocalScope()

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

public
mixed
getObj(string $name, array $arguments = [], bool $cache = false, string $cacheName = null)

No description

public
$this
obj(string $name, array $arguments = [], bool $cache = false, string $cacheName = null)

No description

public
object
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
mixed
next()

Fast-forwards the current iterator to the next item

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

No description

protected
array
getItemStack()

No description

protected
setItemStack(array $stack)

No description

protected
int|null
getUpIndex()

No description

Details

__construct($item, SSViewer_Scope $inheritedScope = null)

No description

Parameters

$item
SSViewer_Scope $inheritedScope

object getItem()

Returns the current "active" item

Return Value

object

SSViewer_Scope locally()

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

Return Value

SSViewer_Scope

resetLocalScope()

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

mixed getObj(string $name, array $arguments = [], bool $cache = false, string $cacheName = null)

No description

Parameters

string $name
array $arguments
bool $cache
string $cacheName

Return Value

mixed

$this obj(string $name, array $arguments = [], bool $cache = false, string $cacheName = null)

No description

Parameters

string $name
array $arguments
bool $cache
string $cacheName

Return Value

$this

object self()

Gets the current object and resets the scope.

Return Value

object

SSViewer_Scope pushScope()

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

Return Value

SSViewer_Scope

SSViewer_Scope popScope()

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

Return Value

SSViewer_Scope

mixed next()

Fast-forwards the current iterator to the next item

Return Value

mixed

mixed __call(string $name, array $arguments)

No description

Parameters

string $name
array $arguments

Return Value

mixed

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