StackedStates
in package
A class that providing stacking states.
Table of Contents
Properties
- $_defaults : mixed
- Default values for a new state.
- $_states : array<string|int, mixed>
- Stack of states.
Methods
- __construct() : mixed
- Construct a new StackState with the given default values.
- current() : mixed
- Return the current state.
- getValue() : mixed
- Get a value from the current state.
- is() : bool
- Check if the current state is of the given type. If there is no current state, this function returns false.
- isEmpty() : bool
- Check if the stack is empty.
- pop() : mixed
- Pop the current state.
- push() : void
- Push a new state, merging given values with the default ones.
- setValue() : void
- Set a value of the current state.
- type() : string
- Retrieve the type of the current sate.
Properties
$_defaults
Default values for a new state.
protected
mixed
$_defaults
= []
$_states
Stack of states.
protected
array<string|int, mixed>
$_states
= []
Methods
__construct()
Construct a new StackState with the given default values.
public
__construct([mixed $defaults = [] ]) : mixed
Parameters
- $defaults : mixed = []
-
Default values for the states.
current()
Return the current state.
public
current() : mixed
Return values
mixed —Current values of the state.
getValue()
Get a value from the current state.
public
getValue(mixed $name) : mixed
Parameters
- $name : mixed
-
Name of the attribute to retrieve.
Return values
mixed —Value retrieved from the current state.
is()
Check if the current state is of the given type. If there is no current state, this function returns false.
public
is(string $type) : bool
Parameters
- $type : string
-
Type to check
Return values
bool —true if the current state is of the given type, false if the types do not match or if there is no current state.
isEmpty()
Check if the stack is empty.
public
isEmpty() : bool
Return values
bool —true if the stack is empty (i.e. contains no states).
pop()
Pop the current state.
public
pop() : mixed
Return values
mixed —An array [type, state] containing the removed state.
push()
Push a new state, merging given values with the default ones.
public
push(string $type[, mixed $state = [] ]) : void
Parameters
- $type : string
-
Type of the new state.
- $state : mixed = []
-
New state.
setValue()
Set a value of the current state.
public
setValue(mixed $name, mixed $value) : void
Parameters
- $name : mixed
-
Name of the attribute to set.
- $value : mixed
-
New value for the attribute.
type()
Retrieve the type of the current sate.
public
type() : string
Return values
string —Type of the current state.