Skip to content

Instantly share code, notes, and snippets.

@lussoluca
Created January 8, 2015 16:14
Show Gist options
  • Save lussoluca/72dac451434c53dfb355 to your computer and use it in GitHub Desktop.
Save lussoluca/72dac451434c53dfb355 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\webprofiler\Plugin\RulesExpression;
use Drupal\rules\Engine\RulesState;
use Drupal\rules\Plugin\RulesExpression\Rule;
use Drupal\rules\Plugin\RulesExpressionPluginManager;
use Drupal\webprofiler\DataCollector\RulesDataCollector;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class TraceableRule
*/
class TraceableRule extends Rule {
private $collector;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RulesExpressionPluginManager $expression_manager, RulesDataCollector $collector) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $expression_manager);
$this->collector = $collector;
}
/**
* {@inheritdoc}
*/
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('webprofiler.rules')
);
}
/**
* {@inheritdoc}
*/
public function executeWithState(RulesState $state) {
// Evaluate the rule's conditions.
if (!$this->conditions->executeWithState($state)) {
$this->collector->registerRuleExecution($this, FALSE);
// Do not run the actions if the conditions are not met.
return;
}
$this->actions->executeWithState($state);
$this->collector->registerRuleExecution($this, TRUE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment