class Rule in Rules 7.2
An actual rule.
Note: A rule also implements the RulesActionInterface (inherited).
Hierarchy
- class \RulesExtendable extends \FacesExtendable
- class \RulesPlugin
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesActionContainer implements RulesActionInterface
- class \Rule
- class \RulesActionContainer implements RulesActionInterface
- class \RulesContainerPlugin implements \IteratorAggregate
- class \RulesPlugin
Expanded class hierarchy of Rule
3 string references to 'Rule'
- hook_rules_plugin_info in ./
rules.api.php - Defines rules plugins.
- rules_drush_command in ./
rules.drush.inc - Implements hook_drush_command().
- rules_rules_plugin_info in ./
rules.module - Implements hook_rules_plugin_info().
File
- includes/
rules.plugins.inc, line 162 - Contains plugin info and implementations not needed for rule evaluation.
View source
class Rule extends RulesActionContainer {
protected $conditions = NULL;
/**
* @var string
*/
protected $itemName = 'rule';
/**
* @var string
*/
public $label = 'unlabeled';
public function __construct($variables = array(), $providesVars = array()) {
parent::__construct($variables, $providesVars);
// Initialize the conditions container.
if (!isset($this->conditions)) {
$this->conditions = rules_and();
// Don't use setParent() to avoid having it added to the children.
$this->conditions->parent = $this;
}
}
/**
* Gets an iterator over all contained conditions.
*
* Note that this iterator also implements the ArrayAccess interface.
*
* @return RulesRecursiveElementIterator
*/
public function conditions() {
return $this->conditions
->getIterator();
}
/**
* Returns the "And" condition container, which contains all conditions of
* this rule.
*
* @return RulesAnd
*/
public function conditionContainer() {
return $this->conditions;
}
public function __sleep() {
return parent::__sleep() + drupal_map_assoc(array(
'conditions',
'label',
));
}
/**
* Gets an iterator over all contained actions.
*
* Note that this iterator also implements the ArrayAccess interface.
*
* @return RulesRecursiveElementIterator
*/
public function actions() {
return parent::getIterator();
}
/**
* Adds a condition.
*
* Pass either an instance of the RulesConditionInterface or the arguments as
* needed by rules_condition().
*
* @return $this
*/
public function condition($name, $settings = array()) {
$this->conditions
->condition($name, $settings);
return $this;
}
public function sortChildren($deep = FALSE) {
$this->conditions
->sortChildren($deep);
parent::sortChildren($deep);
}
public function evaluate(RulesState $state) {
rules_log('Evaluating conditions of rule %label.', array(
'%label' => $this->label,
), RulesLog::INFO, $this);
if ($this->conditions
->evaluate($state)) {
rules_log('Rule %label fires.', array(
'%label' => $this->label,
), RulesLog::INFO, $this, TRUE);
parent::evaluate($state);
rules_log('Rule %label has fired.', array(
'%label' => $this->label,
), RulesLog::INFO, $this, FALSE);
}
}
/**
* Fires the rule, i.e. evaluates the rule without checking its conditions.
*
* @see RulesPlugin::evaluate()
*/
public function fire(RulesState $state) {
rules_log('Firing rule %label.', array(
'%label' => $this->label,
), RulesLog::INFO, $this);
parent::evaluate($state);
}
public function integrityCheck() {
parent::integrityCheck();
$this->conditions
->integrityCheck();
return $this;
}
public function access() {
return (!isset($this->conditions) || $this->conditions
->access()) && parent::access();
}
public function dependencies() {
return array_keys(array_flip($this->conditions
->dependencies()) + array_flip(parent::dependencies()));
}
public function destroy() {
$this->conditions
->destroy();
parent::destroy();
}
/**
* @return RulesRecursiveElementIterator
*/
public function getIterator() {
$array = array_merge(array(
$this->conditions,
), $this->children);
return new RulesRecursiveElementIterator($array);
}
protected function stateVariables($element = NULL) {
// Don't add in provided action variables for the conditions.
if (isset($element) && $element === $this->conditions) {
return $this
->availableVariables();
}
$vars = parent::stateVariables($element);
// Take variable info assertions of conditions into account.
if ($assertions = $this->conditions
->variableInfoAssertions()) {
$vars = RulesData::addMetadataAssertions($vars, $assertions);
}
return $vars;
}
protected function exportFlat() {
return $this
->isRoot();
}
protected function exportToArray() {
$export = parent::exportToArray();
if (!$this
->isRoot()) {
$export[strtoupper($this
->plugin())]['LABEL'] = $this->label;
}
return $export;
}
protected function exportChildren($key = NULL) {
$export = array();
if ($this->conditions->children) {
$export = $this->conditions
->exportChildren('IF');
}
return $export + parent::exportChildren('DO');
}
public function import(array $export) {
if (!$this
->isRoot() && isset($export[strtoupper($this
->plugin())]['LABEL'])) {
$this->label = $export[strtoupper($this
->plugin())]['LABEL'];
}
parent::import($export);
}
protected function importChildren($export, $key = NULL) {
if (!empty($export['IF'])) {
$this->conditions
->importChildren($export, 'IF');
}
parent::importChildren($export, 'DO');
}
public function __clone() {
parent::__clone();
$this->conditions = clone $this->conditions;
$this->conditions->parent = $this;
}
/**
* Overrides RulesPlugin::variableInfoAssertions().
*
* Rules may not provide any variable info assertions, as Rules are only
* conditionally executed.
*/
protected function variableInfoAssertions() {
return array();
}
/**
* Overridden to ensure the whole Rule is deleted at once.
*/
public function delete($keep_children = FALSE) {
parent::delete($keep_children);
}
/**
* Overridden to expose the variables of all actions for embedded rules.
*/
public function providesVariables() {
$provides = parent::providesVariables();
if (!$this
->isRoot()) {
foreach ($this
->actions() as $action) {
$provides += $action
->providesVariables();
}
}
return $provides;
}
public function resetInternalCache() {
parent::resetInternalCache();
$this->conditions
->resetInternalCache();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Rule:: |
protected | property | ||
Rule:: |
protected | property |
Overrides RulesExtendable:: |
|
Rule:: |
public | property | ||
Rule:: |
public | function |
Whether the currently logged in user has access to all configured elements. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function | Gets an iterator over all contained actions. | |
Rule:: |
public | function | Adds a condition. | |
Rule:: |
public | function | Returns the "And" condition container, which contains all conditions of this rule. | |
Rule:: |
public | function | Gets an iterator over all contained conditions. | |
Rule:: |
public | function |
Overridden to ensure the whole Rule is deleted at once. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Calculates an array of required modules. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Removes circular object references so PHP garbage collector can work. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Evaluate, whereas by default new vars are visible in the parent's scope. Overrides RulesActionContainer:: |
|
Rule:: |
protected | function |
Overrides RulesContainerPlugin:: |
|
Rule:: |
protected | function |
Determines whether the element should be exported in flat style. Overrides RulesContainerPlugin:: |
|
Rule:: |
protected | function |
Overrides RulesActionContainer:: |
|
Rule:: |
public | function | Fires the rule, i.e. evaluates the rule without checking its conditions. | |
Rule:: |
public | function |
Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Applies the given export. Overrides RulesActionContainer:: |
|
Rule:: |
protected | function |
Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Makes sure the plugin is configured right. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Overridden to expose the variables of all actions for embedded rules. Overrides RulesActionContainer:: |
|
Rule:: |
public | function |
Resets any internal static caches. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Sorts all child elements by their weight. Overrides RulesContainerPlugin:: |
|
Rule:: |
protected | function |
Returns available state variables for an element. Overrides RulesContainerPlugin:: |
|
Rule:: |
protected | function |
Overrides RulesPlugin::variableInfoAssertions(). Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
By default we do a deep clone. Overrides RulesContainerPlugin:: |
|
Rule:: |
public | function |
Overrides RulesActionContainer:: |
|
Rule:: |
public | function |
Overrides RulesContainerPlugin:: |
|
RulesActionContainer:: |
public | function | Adds an action to the container. | |
RulesActionContainer:: |
public | function | Returns an array of provided variable names. | |
RulesActionContainer:: |
public | function |
Returns info about variables 'provided' by the plugin. Overrides RulesPlugin:: |
|
RulesContainerPlugin:: |
protected | property | ||
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:: |
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:: |
|
RulesExtendable:: |
protected | property | ||
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 | |
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:: |
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:: |
protected | function | 1 | |
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 label of the element. | 4 |
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 | 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. |