public function RulesConditionalCase::canEvaluate in Conditional Rules 8
Same name and namespace in other branches
- 7 includes/rules_conditional.plugin.inc \RulesConditionalCase::canEvaluate()
Determines whether this branch can be evaluated.
Overrides RulesConditionalElement::canEvaluate
File
- includes/
rules_conditional.plugin.inc, line 349 - Rules plugin implementation.
Class
- RulesConditionalCase
- Switch case.
Code
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]);
}