コード例 #1
0
 public function it_applies_rule(RuleInterface $rule, Article $subject, RouteProviderInterface $routeProvider, RouteInterface $route, LoggerInterface $logger, ArticleServiceInterface $articleService)
 {
     $rule->getConfiguration()->willReturn(['route' => 'some/route', 'templateName' => 'template.twig.html', 'published' => 'true']);
     $rule->getExpression()->willReturn('article.getSomething("something") matches /something/');
     $routeProvider->getOneById('some/route')->willReturn($route);
     $subject->setRoute($route)->shouldBeCalled();
     $subject->setTemplateName('template.twig.html')->shouldBeCalled();
     $articleService->publish($subject)->shouldBeCalled();
     $logger->info(Argument::any('string'))->shouldBeCalled();
     $this->apply($rule, $subject)->shouldReturn(null);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function apply(RuleInterface $rule, RuleSubjectInterface $subject)
 {
     $configuration = $this->validateRuleConfiguration($rule->getConfiguration());
     if (!$this->isAllowedType($subject) || empty($configuration)) {
         return;
     }
     /* @var ArticleInterface $subject */
     if (isset($configuration['route'])) {
         $route = $this->routeProvider->getOneById($configuration['route']);
         if (null === $route) {
             $this->logger->warning('Route not found! Make sure the rule defines an existing route!');
             return;
         }
         $subject->setRoute($route);
     }
     $subject->setTemplateName($configuration['templateName']);
     if ((bool) $configuration['published']) {
         $this->articleService->publish($subject);
     }
     $this->logger->info(sprintf('Configuration: "%s" for "%s" rule has been applied!', json_encode($configuration), $rule->getExpression()));
 }