class RulesConditionalCase in Conditional Rules 7
Same name and namespace in other branches
- 8 includes/rules_conditional.plugin.inc \RulesConditionalCase
Switch case.
Hierarchy
- class \RulesExtendable extends \FacesExtendable
- class \RulesPlugin
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesActionContainer implements RulesActionInterface
- class \RulesConditionalElement implements RulesActionInterface
- class \RulesConditionalCase
- class \RulesConditionalElement implements RulesActionInterface
- class \RulesActionContainer implements RulesActionInterface
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesPlugin
Expanded class hierarchy of RulesConditionalCase
1 string reference to 'RulesConditionalCase'
- rules_conditional_rules_plugin_info in ./
rules_conditional.rules.inc - Implements hook_rules_plugin_info().
File
- includes/
rules_conditional.plugin.inc, line 240 - Rules plugin implementation.
View source
class RulesConditionalCase extends RulesConditionalElement {
protected $itemName = 'case';
/**
* @var RulesPlugin
*/
protected $condition;
/**
* Evaluated condition results.
* @var array
*/
protected $conditionResultCache = array();
public function __construct($settings = array(), $fallThrough = FALSE) {
parent::__construct();
if (isset($settings['value'])) {
$this->settings['value'] = $settings['value'];
}
elseif (isset($settings['value:select'])) {
$this->settings['value:select'] = $settings['value:select'];
}
$this->settings += array(
'fall_through' => $fallThrough,
);
}
public function __destruct() {
unset($this->condition);
unset($this->conditionResultCache);
}
public function forceSetUp() {
parent::forceSetUp();
$this
->setUpCondition();
}
public function pluginParameterInfo() {
$parameterInfo = array(
'value' => array(
'type' => '*',
'label' => t('Data value'),
'description' => t('The value to compare the data with.'),
'allow null' => TRUE,
),
'fall_through' => array(
'type' => 'boolean',
'label' => t('Fall through'),
'description' => t('Fall through to next case when complete. If this option is checked, the next case is automatically executed (regardless of the case value) when this case is finished. If not, the switch will terminate when the case is finished.'),
'optional' => TRUE,
'default value' => FALSE,
'restriction' => 'input',
),
);
// Derive parameter info from switch variable selector.
$dataSelector = isset($this->parent->settings['data:select']) ? $this->parent->settings['data:select'] : NULL;
if ($wrapper = $this
->applyDataSelector($dataSelector)) {
$parameterInfo['value']['type'] = $wrapper
->type();
}
return $parameterInfo;
}
public function stateVariables($element = NULL) {
$this
->forceSetUp();
if (!isset($element) || $element === $this->condition) {
return parent::stateVariables();
}
else {
// Add assertions from the condition.
$variables = parent::stateVariables($element);
if (isset($this->condition) && ($assertions = $this->condition
->call('variableInfoAssertions'))) {
$variables = RulesData::addMetadataAssertions($variables, $assertions);
}
return $variables;
}
}
protected function setUpCondition() {
if (!isset($this->condition) && isset($this->parent)) {
// Prepare settings for 'data_is' condition.
$settings = array(
'data:select' => $this->parent->settings['data:select'],
'op' => '==',
);
if (isset($this->settings['value:select'])) {
$settings['value:select'] = $this->settings['value:select'];
}
elseif (isset($this->settings['value'])) {
$settings['value'] = $this->settings['value'];
}
else {
// Abort if settings are incomplete.
return;
}
// Set up 'data_is'.
$this->condition = rules_condition('data_is', $settings);
$this->condition->parent = $this;
$this->condition
->processSettings();
}
}
/**
* Returns whether this case should fall through.
*/
public function fallThrough() {
return !empty($this->settings['fall_through']);
}
/**
* Determines whether this branch can be evaluated.
*/
public function canEvaluate(RulesState $state) {
$this
->forceSetUp();
// Check if this element has fallen through.
if ($previous = $this
->getPreviousSibling()) {
/** @var $previous self */
if ($previous instanceof self && $previous
->fallThrough() && $previous
->canEvaluate($state)) {
return TRUE;
}
}
// Evaluate condition for the given state once.
$this->conditionResultCache += array(
'state' => array(),
'result' => array(),
);
if (empty($this->conditionResultCache['state']) || !($cacheKey = array_search($state, $this->conditionResultCache['state'], TRUE))) {
$cacheKey = count($this->conditionResultCache['state']);
$this->conditionResultCache['state'][$cacheKey] = $state;
$this->conditionResultCache['result'][$cacheKey] = $this->condition
->evaluate($state);
}
return !empty($this->conditionResultCache['result'][$cacheKey]);
}
public function resetInternalCache() {
parent::resetInternalCache();
$this->condition = NULL;
$this->conditionResultCache = array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesActionContainer:: |
public | function | Adds an action to the container. | |
RulesActionContainer:: |
public | function | Returns an array of provided variable names. | |
RulesActionContainer:: |
public | function |
Evaluate, whereas by default new vars are visible in the parent's scope. Overrides RulesPlugin:: |
2 |
RulesActionContainer:: |
protected | function |
Overrides RulesContainerPlugin:: |
1 |
RulesActionContainer:: |
public | function |
Applies the given export. Overrides RulesContainerPlugin:: |
1 |
RulesActionContainer:: |
public | function |
Returns info about variables 'provided' by the plugin. Overrides RulesPlugin:: |
|
RulesConditionalCase:: |
protected | property | ||
RulesConditionalCase:: |
protected | property | Evaluated condition results. | |
RulesConditionalCase:: |
protected | property |
The name of the item this class represents in the info hook. Overrides RulesExtendable:: |
|
RulesConditionalCase:: |
public | function |
Determines whether this branch can be evaluated. Overrides RulesConditionalElement:: |
|
RulesConditionalCase:: |
public | function | Returns whether this case should fall through. | |
RulesConditionalCase:: |
public | function |
Forces the object to be setUp, this executes setUp() if not done yet. Overrides RulesExtendable:: |
|
RulesConditionalCase:: |
public | function |
Returns info about parameters needed by the plugin. Overrides RulesPlugin:: |
|
RulesConditionalCase:: |
public | function |
Resets any internal static caches. Overrides RulesContainerPlugin:: |
|
RulesConditionalCase:: |
protected | function | ||
RulesConditionalCase:: |
public | function |
Returns available state variables for an element. Overrides RulesContainerPlugin:: |
|
RulesConditionalCase:: |
public | function |
Overrides RulesActionContainer:: |
|
RulesConditionalCase:: |
public | function | ||
RulesConditionalElement:: |
protected | property |
The parent conditional. Overrides RulesPlugin:: |
|
RulesConditionalElement:: |
protected | function | Checks basic conditional element integrity. | |
RulesConditionalElement:: |
public | function |
Deletes the element and its children. Overrides RulesContainerPlugin:: |
1 |
RulesConditionalElement:: |
public | function |
Calculates an array of required modules. Overrides RulesContainerPlugin:: |
1 |
RulesConditionalElement:: |
protected | function |
Overrides RulesContainerPlugin:: |
3 |
RulesConditionalElement:: |
protected | function |
Overrides RulesPlugin:: |
|
RulesConditionalElement:: |
public | function | Gets sibling elements. | |
RulesConditionalElement:: |
public | function | Gets the next sibling element. | |
RulesConditionalElement:: |
public | function | Gets the previous sibling element. | |
RulesConditionalElement:: |
protected | function |
Overrides RulesContainerPlugin:: |
3 |
RulesConditionalElement:: |
public | function |
Makes sure the plugin is configured right. Overrides RulesContainerPlugin:: |
1 |
RulesConditionalElement:: |
public | function | Determines whether this branch is default, i.e. covers the remainder of conditions outside of all non-default branches inside the conditional. | 3 |
RulesConditionalElement:: |
public | function |
Returns the label of the element. Overrides RulesPlugin:: |
1 |
RulesConditionalElement:: |
public | function |
Returns info about all variables provided for later evaluated elements. Overrides RulesActionContainer:: |
1 |
RulesConditionalElement:: |
public | function |
@todo Remove once http://drupal.org/node/1671344 is resolved. Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
protected | property | ||
RulesContainerPlugin:: |
public | function |
Whether the currently logged in user has access to all configured elements. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function |
Returns info about variables available to be used as arguments for this element. Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
public | function | Returns the specified variables, in case the plugin is used as component. | |
RulesContainerPlugin:: |
public | function |
Removes circular object references so PHP garbage collector can work. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function |
Executes container with the given arguments. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
protected | function | Determines whether the element should be exported in flat style. | 1 |
RulesContainerPlugin:: |
public | function | Allows access to the children through the iterator. | 1 |
RulesContainerPlugin:: |
public | function |
Overrides optimize(). Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
public | function |
Returns info about parameters needed for executing the configured plugin. Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
protected | function |
Returns info about all variables that have to be setup in the state. Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
public | function | Sorts all child elements by their weight. | 1 |
RulesContainerPlugin:: |
protected | function |
Returns asserted additions to the available variable info. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function |
By default we do a deep clone. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function |
Overrides RulesPlugin:: |
2 |
RulesExtendable:: |
protected | property | ||
RulesExtendable:: |
public | function | ||
RulesExtendable:: |
public static | function | Returns whether the a RuleExtendable supports the given interface. | |
RulesExtendable:: |
public | function | Allows items to add something to the rules cache. | 1 |
RulesExtendable:: |
protected | function | 1 | |
RulesExtendable:: |
public | function | Magic method: Invoke the dynamically implemented methods. | |
RulesPlugin:: |
protected | property | Static cache for availableVariables(). | 1 |
RulesPlugin:: |
protected | property |
Overrides RulesExtendable:: |
|
RulesPlugin:: |
protected | property | Identifies an element inside a configuration. | |
RulesPlugin:: |
protected | property |
Overrides RulesExtendable:: |
|
RulesPlugin:: |
public | property | If this is a configuration saved to the db, the id of it. | |
RulesPlugin:: |
protected | property | Info about this element. Usage depends on the plugin. | 2 |
RulesPlugin:: |
public | property | ||
RulesPlugin:: |
public | property | An array of settings for this element. | |
RulesPlugin:: |
public | property | ||
RulesPlugin:: |
public | function | Applies the given data selector. | |
RulesPlugin:: |
protected | function | Checks whether parameters are correctly configured. | |
RulesPlugin:: |
protected | function | ||
RulesPlugin:: |
protected static | function | ||
RulesPlugin:: |
public | function | Returns the depth of this element in the configuration. | |
RulesPlugin:: |
public | function | Returns the element id, which identifies the element inside the config. | |
RulesPlugin:: |
public | function | Gets the element map helper object, which helps mapping elements to ids. | |
RulesPlugin:: |
public | function | Iterate over all elements nested below the current element. | |
RulesPlugin:: |
protected | function | Ensure the configuration has a name. If not, generate one. | |
RulesPlugin:: |
public | function | ||
RulesPlugin:: |
public | function | ||
RulesPlugin:: |
public | function | Execute the configuration. | |
RulesPlugin:: |
public | function | Exports a rule configuration. | |
RulesPlugin:: |
protected | function | ||
RulesPlugin:: |
public | function | Seamlessly invokes the method implemented via faces. | |
RulesPlugin:: |
public | function | ||
RulesPlugin:: |
public | function | ||
RulesPlugin:: |
protected | function | Returns the argument for the parameter $name described with $info. | |
RulesPlugin:: |
public | function | Returns info about the configured argument. | |
RulesPlugin:: |
protected | function | Gets the right arguments for executing the element. | |
RulesPlugin:: |
public | function | Gets the name of this plugin instance. | 1 |
RulesPlugin:: |
public | function | Checks if the configuration has a certain exportable status. | |
RulesPlugin:: |
public | function | Returns the config name. | |
RulesPlugin:: |
protected | function | ||
RulesPlugin:: |
protected | function | 1 | |
RulesPlugin:: |
public | function | Returns the info of the plugin. | 2 |
RulesPlugin:: |
public | function | ||
RulesPlugin:: |
public | function | Returns whether the element is the root of the configuration. | |
RulesPlugin:: |
public | function | Returns the element's parent. | |
RulesPlugin:: |
public | function | Returns the name of the element's plugin. | |
RulesPlugin:: |
public | function | Returns info about the element's plugin. | |
RulesPlugin:: |
public | function | Processes the settings e.g. to prepare input evaluators. | 1 |
RulesPlugin:: |
protected | function | Finalizes the configuration export. | |
RulesPlugin:: |
protected | function | Gets variables to return once the configuration has been executed. | 2 |
RulesPlugin:: |
public | function | Gets the root element of the configuration. | |
RulesPlugin:: |
public | function | Saves the configuration to the database. | 1 |
RulesPlugin:: |
public | function | Sets up the execution state for the given arguments. | |
RulesPlugin:: |
public | function | When converted to a string, just use the export format. |