class StateMachine_State in State Machine 7.3
Same name and namespace in other branches
- 6 inc/base.inc \StateMachine_State
- 7 inc/base.inc \StateMachine_State
- 7.2 inc/base.inc \StateMachine_State
Base class for states.
Hierarchy
- class \StateMachine_State
Expanded class hierarchy of StateMachine_State
File
- inc/
base.inc, line 253 - Defines the base classes of the state machine.
View source
class StateMachine_State {
public $key;
protected $machine;
protected $options;
/**
* Instantiate state.
*
* @param string $name
* The machine readable name of the state.
* @param StateMachine $machine
* The related machine.
* @param array $options
* The options array.
*/
public function __construct($name, $machine, $options = array()) {
$this->name = $name;
$this->machine = $machine;
$this->options = $options;
$this->title = isset($this->options['title']) ? $this->options['title'] : $name;
}
/**
* Return the $options array.
*
* @return array
* The options array.
*/
public function get_options() {
return $this->options;
}
/**
* Return a specific key value from the $options array.
*
* @param string $key
* The options key.
*
* @return mixed
* The value of the option or FALSE if the option wasn't found.
*/
public function get_option($key) {
return array_key_exists($key, $this->options) ? $this->options[$key] : FALSE;
}
/**
* Called when entering into this state.
*/
public function on_enter() {
$args = func_get_args();
if (!empty($this->options['on_enter'])) {
call_user_func_array($this->options['on_enter'], $args);
}
}
/**
* Called when exiting out of this state.
*/
public function on_exit() {
$args = func_get_args();
if (!empty($this->options['on_exit'])) {
call_user_func_array($this->options['on_exit'], $args);
}
}
/**
* Check if this state is published.
*/
public function is_published() {
if (!empty($this->options['on_enter'])) {
return in_array('on_enter_published', $this->options['on_enter']);
}
return FALSE;
}
/**
* Check if this state is unpublished.
*/
public function is_unpublished() {
if (!empty($this->options['on_enter'])) {
return in_array('on_enter_unpublished', $this->options['on_enter']);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StateMachine_State:: |
public | property | ||
StateMachine_State:: |
protected | property | ||
StateMachine_State:: |
protected | property | ||
StateMachine_State:: |
public | function | Return a specific key value from the $options array. | |
StateMachine_State:: |
public | function | Return the $options array. | |
StateMachine_State:: |
public | function | Check if this state is published. | |
StateMachine_State:: |
public | function | Check if this state is unpublished. | |
StateMachine_State:: |
public | function | Called when entering into this state. | |
StateMachine_State:: |
public | function | Called when exiting out of this state. | |
StateMachine_State:: |
public | function | Instantiate state. |