ExpressionContainerBase.php in Rules 8.3
File
src/Engine/ExpressionContainerBase.php
View source
<?php
namespace Drupal\rules\Engine;
use Drupal\rules\Context\ContextConfig;
use Drupal\rules\Context\ExecutionMetadataStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class ExpressionContainerBase extends ExpressionBase implements ExpressionContainerInterface {
protected $expressionManager;
protected $rulesDebugLogger;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.rules_expression'), $container
->get('logger.channel.rules_debug'));
}
public static function sortByWeightProperty(ExpressionInterface $a, ExpressionInterface $b) {
$a_weight = $a
->getWeight();
$b_weight = $b
->getWeight();
if ($a_weight == $b_weight) {
return 0;
}
return $a_weight < $b_weight ? -1 : 1;
}
public function addExpression($plugin_id, ContextConfig $config = NULL) {
return $this
->addExpressionObject($this->expressionManager
->createInstance($plugin_id, $config ? $config
->toArray() : []));
}
protected abstract function allowsMetadataAssertions();
public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state, $apply_assertions = TRUE) {
$violation_list = new IntegrityViolationList();
$this
->prepareExecutionMetadataStateBeforeTraversal($metadata_state);
$apply_assertions = $apply_assertions && $this
->allowsMetadataAssertions();
foreach ($this as $child_expression) {
$child_violations = $child_expression
->checkIntegrity($metadata_state, $apply_assertions);
$violation_list
->addAll($child_violations);
}
$this
->prepareExecutionMetadataStateAfterTraversal($metadata_state);
return $violation_list;
}
public function prepareExecutionMetadataState(ExecutionMetadataStateInterface $metadata_state, ExpressionInterface $until = NULL, $apply_assertions = TRUE) {
if ($until && $this
->getUuid() === $until
->getUuid()) {
return TRUE;
}
$this
->prepareExecutionMetadataStateBeforeTraversal($metadata_state);
$apply_assertions = $apply_assertions && $this
->allowsMetadataAssertions();
foreach ($this as $child_expression) {
$found = $child_expression
->prepareExecutionMetadataState($metadata_state, $until, $apply_assertions);
if ($found) {
return TRUE;
}
}
$this
->prepareExecutionMetadataStateAfterTraversal($metadata_state);
}
protected function prepareExecutionMetadataStateBeforeTraversal(ExecutionMetadataStateInterface $metadata_state) {
}
protected function prepareExecutionMetadataStateAfterTraversal(ExecutionMetadataStateInterface $metadata_state) {
}
}