abstract class RulesConditionalContainer in Conditional Rules 7
Same name and namespace in other branches
- 8 includes/rules_conditional.core.inc \RulesConditionalContainer
Base conditional statement plugin implementation.
Hierarchy
- class \RulesExtendable extends \FacesExtendable
- class \RulesPlugin
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesConditionalContainer implements RulesActionInterface
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesPlugin
Expanded class hierarchy of RulesConditionalContainer
1 string reference to 'RulesConditionalContainer'
- rules_conditional.plugin.inc in includes/
rules_conditional.plugin.inc - Rules plugin implementation.
File
- includes/
rules_conditional.core.inc, line 10 - Conditional Rules framework implementation.
View source
abstract class RulesConditionalContainer extends RulesContainerPlugin implements RulesActionInterface {
/**
* Magic methods to intercept.
* @var array
*/
protected $interceptMethods = array();
/**
* @var RulesActionContainer
*/
protected $fluentElement;
protected $providesVariables;
public function label() {
$info = $this
->pluginInfo();
$label = isset($info['label']) ? $info['label'] : t('unlabeled');
return $label;
}
/**
* Intercepts calls to magic methods, possibly using reserved keywords.
*/
public function __call($name, $arguments = array()) {
if (in_array($name, $this->interceptMethods) && method_exists($this, $mapMethod = 'call_' . $name)) {
return call_user_func_array(array(
$this,
$mapMethod,
), $arguments);
}
else {
return parent::__call($name, $arguments);
}
}
public function destroy() {
$this->fluentElement = NULL;
parent::destroy();
}
/**
* Adds an action to the active fluent statement.
*
* Pass either an instance of the RulesActionInterface or the arguments as
* needed by rules_action().
*
* @param $name
* @param array $settings
* @return $this
* Returns $this for fluent interface.
*/
public function action($name, array $settings = array()) {
if (isset($this->fluentElement)) {
$this->fluentElement
->action($name, $settings);
}
return $this;
}
/**
* Evaluates the conditional statement.
*/
public function evaluate(RulesState $state) {
// Evaluate selected branches.
$branches = $this
->selectBranches($state);
foreach ($branches as $branch) {
$branch
->evaluate($state);
}
}
/**
* Asserts no variables (since a conditional is *conditionally* evaluated).
*/
protected function variableInfoAssertions() {
return array();
}
/**
* Declares only parent state variables for individual branches.
*
* By definition, divergent branches should not have each other's variables.
*/
protected function stateVariables($element = NULL) {
return $this
->availableVariables();
}
/**
* Provides intersections of variables in all branches, at least one default.
*/
public function providesVariables() {
if (!isset($this->providesVariables)) {
$this->providesVariables = parent::providesVariables();
if (!$this
->isRoot()) {
// Collect variables.
$hasDefault = FALSE;
$childVariables = array();
/** @var $child RulesConditionalElement */
$isEmpty = FALSE;
foreach ($this->children as $child) {
$hasDefault = $hasDefault || $child
->isDefault();
if ($childProvides = $child
->providesVariables()) {
$childVariables[] = $childProvides;
}
else {
// Mark as empty if any branch does not provide variables. This is
// to avoid having to perform intersections over empty sets.
$isEmpty = TRUE;
break;
}
}
if ($hasDefault && !$isEmpty) {
// Collect intersection of variable names.
$names = NULL;
foreach ($childVariables as $variables) {
$newNames = array_keys($variables);
$names = isset($names) ? array_intersect($names, $newNames) : $newNames;
}
// Add variables.
if (isset($names)) {
foreach ($names as $name) {
// Determine if variable types are consistent.
$type = NULL;
foreach ($childVariables as $variables) {
if (isset($type) && $type != $variables[$name]['type']) {
continue 2;
}
else {
$type = $variables[$name]['type'];
}
}
// Add compatible variable.
if (isset($type)) {
$lastVariables = end($childVariables);
$this->providesVariables[$name] = $lastVariables[$name];
}
}
}
}
}
}
return $this->providesVariables;
}
/**
* Selects the branches to evaluate for this conditional.
*
* @param RulesState $state
* Rules state to use.
* @return RulesConditionalElement[]
* An array of branches to evaluate.
*/
protected abstract function selectBranches(RulesState $state);
/**
* Deletes the container and its children.
*/
public function delete($keep_children = FALSE) {
parent::delete($keep_children);
}
public function dependencies() {
$modules = array(
'rules_conditional' => 1,
);
$modules += array_flip(parent::dependencies());
return array_keys($modules);
}
protected function exportSettings() {
$export = parent::exportSettings();
// Remove provided variables as plugin is only a container.
if (isset($export['PROVIDE'])) {
unset($export['PROVIDE']);
}
return $export;
}
public function resetInternalCache() {
parent::resetInternalCache();
$this->providesVariables = NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesConditionalContainer:: |
protected | property | ||
RulesConditionalContainer:: |
protected | property | Magic methods to intercept. | 3 |
RulesConditionalContainer:: |
protected | property | ||
RulesConditionalContainer:: |
public | function | Adds an action to the active fluent statement. | |
RulesConditionalContainer:: |
public | function |
Deletes the container and its children. Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Calculates an array of required modules. Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Removes circular object references so PHP garbage collector can work. Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Evaluates the conditional statement. Overrides RulesPlugin:: |
|
RulesConditionalContainer:: |
protected | function |
Overrides RulesPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Returns the label of the element. Overrides RulesPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Provides intersections of variables in all branches, at least one default. Overrides RulesPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Resets any internal static caches. Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
abstract protected | function | Selects the branches to evaluate for this conditional. | 3 |
RulesConditionalContainer:: |
protected | function |
Declares only parent state variables for individual branches. Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
protected | function |
Asserts no variables (since a conditional is *conditionally* evaluated). Overrides RulesContainerPlugin:: |
|
RulesConditionalContainer:: |
public | function |
Intercepts calls to magic methods, possibly using reserved keywords. Overrides RulesExtendable:: |
|
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 |
Executes container with the given arguments. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
protected | function | 4 | |
RulesContainerPlugin:: |
protected | function | Determines whether the element should be exported in flat style. | 1 |
RulesContainerPlugin:: |
protected | function |
Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function | Allows access to the children through the iterator. | 1 |
RulesContainerPlugin:: |
public | function |
Applies the given export. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
protected | function | 4 | |
RulesContainerPlugin:: |
public | function |
Overrides RulesPlugin:: |
2 |
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:: |
public | function |
By default we do a deep clone. Overrides RulesPlugin:: |
1 |
RulesContainerPlugin:: |
public | function |
Overrides RulesExtendable:: |
1 |
RulesContainerPlugin:: |
public | function |
Overrides RulesPlugin:: |
2 |
RulesExtendable:: |
protected | property | ||
RulesExtendable:: |
protected | property | The name of the item this class represents in the info hook. | 9 |
RulesExtendable:: |
public | function | ||
RulesExtendable:: |
public | function | Forces the object to be setUp, this executes setUp() if not done yet. | 1 |
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 | |
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:: |
protected | property | The parent element, if any. | |
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 | Returns info about parameters needed by the plugin. | 2 |
RulesPlugin:: |
public | function | Returns info about variables 'provided' by the plugin. | 2 |
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 a new parent element. | |
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. |