You are here

class RulesConditional in Conditional Rules 8

Same name and namespace in other branches
  1. 7 includes/rules_conditional.plugin.inc \RulesConditional

Default if-else conditional statement.

@method RulesConditional if() if($predicate, array $settings = array()) Adds an "if" statement. @method RulesConditional elseIf() elseIf($predicate, array $settings = array()) Adds an "else if" statement. This is an alias for self::if(). @method RulesConditional else() else() Adds an "else" statement. @method RulesConditional action() action($name, array $settings = array()) Adds an action to the currently active statement. Pass arguments as rules_action() would need.

Hierarchy

Expanded class hierarchy of RulesConditional

1 string reference to 'RulesConditional'
rules_conditional_rules_plugin_info in ./rules_conditional.rules.inc
Implements hook_rules_plugin_info().

File

includes/rules_conditional.plugin.inc, line 21
Rules plugin implementation.

View source
class RulesConditional extends RulesConditionalContainer {
  protected $itemName = 'conditional';

  /**
   * Intercepts calls to "if" and "else".
   * @var array
   */
  protected $interceptMethods = array(
    'if',
    'elseIf',
    'else',
  );
  public function __construct() {
    parent::__construct();
  }

  /**
   * Adds an "if" statement, for use with magic call.
   */
  protected function call_if($predicate, array $settings = array()) {
    $this->fluentElement = $element = rules_conditional_if($predicate, $settings);
    $element
      ->setParent($this);
    return $this;
  }

  /**
   * Adds an "if" as an "else if" statement, for use with magic call.
   */
  protected function call_elseIf($predicate, array $settings = array()) {
    return $this
      ->call_if($predicate, $settings);
  }

  /**
   * Adds an "else" statement, for use with magic call.
   */
  protected function call_else() {
    $this->fluentElement = $element = rules_conditional_else();
    $element
      ->setParent($this);
    return $this;
  }

  /**
   * Selects the branches to evaluate for this conditional.
   *
   * @param RulesState $state
   *   Rules state to use.
   * @return RulesConditionalElement[]
   *   An array of branches to evaluate.
   */
  protected function selectBranches(RulesState $state) {

    /** @var $branch RulesConditionalElement */
    foreach ($this->children as $branch) {

      // Select the first matched branch.
      if ($branch
        ->canEvaluate($state)) {
        return array(
          $branch,
        );
      }
    }

    // Return no branch if none matched.
    return array();
  }
  protected function exportFlat() {
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditional::$interceptMethods protected property Intercepts calls to "if" and "else". Overrides RulesConditionalContainer::$interceptMethods
RulesConditional::$itemName protected property
RulesConditional::call_else protected function Adds an "else" statement, for use with magic call.
RulesConditional::call_elseIf protected function Adds an "if" as an "else if" statement, for use with magic call.
RulesConditional::call_if protected function Adds an "if" statement, for use with magic call.
RulesConditional::exportFlat protected function
RulesConditional::selectBranches protected function Selects the branches to evaluate for this conditional. Overrides RulesConditionalContainer::selectBranches
RulesConditional::__construct public function
RulesConditionalContainer::$fluentElement protected property
RulesConditionalContainer::$providesVariables protected property
RulesConditionalContainer::action public function Adds an action to the active fluent statement.
RulesConditionalContainer::delete public function Deletes the container and its children.
RulesConditionalContainer::dependencies public function
RulesConditionalContainer::destroy public function
RulesConditionalContainer::evaluate public function Evaluates the conditional statement.
RulesConditionalContainer::exportSettings protected function
RulesConditionalContainer::label public function
RulesConditionalContainer::providesVariables public function Provides intersections of variables in all branches, at least one default.
RulesConditionalContainer::resetInternalCache public function
RulesConditionalContainer::stateVariables protected function Declares only parent state variables for individual branches.
RulesConditionalContainer::variableInfoAssertions protected function Asserts no variables (since a conditional is *conditionally* evaluated).
RulesConditionalContainer::__call public function Intercepts calls to magic methods, possibly using reserved keywords.