vendor/shopware/core/Framework/Routing/Subscriber/ActiveRulesDataCollectorSubscriber.php line 70

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Routing\Subscriber;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent;
  7. use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\VarDumper\Cloner\Data;
  12. use Symfony\Contracts\Service\ResetInterface;
  13. /**
  14.  * @internal
  15.  */
  16. class ActiveRulesDataCollectorSubscriber extends AbstractDataCollector implements EventSubscriberInterfaceResetInterface
  17. {
  18.     private EntityRepositoryInterface $ruleRepository;
  19.     private array $ruleIds = [];
  20.     public function __construct(EntityRepositoryInterface $ruleRepository)
  21.     {
  22.         $this->ruleRepository $ruleRepository;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             SalesChannelContextResolvedEvent::class => 'onContextResolved',
  28.         ];
  29.     }
  30.     public function reset(): void
  31.     {
  32.         parent::reset();
  33.         $this->ruleIds = [];
  34.     }
  35.     /**
  36.      * @return array|Data
  37.      */
  38.     public function getData()
  39.     {
  40.         return $this->data;
  41.     }
  42.     public function getMatchingRuleCount(): int
  43.     {
  44.         if ($this->data instanceof Data) {
  45.             return $this->data->count();
  46.         }
  47.         return \count($this->data);
  48.     }
  49.     public function collect(Request $requestResponse $response, ?\Throwable $exception null): void
  50.     {
  51.         $this->data $this->getMatchingRules();
  52.     }
  53.     public static function getTemplate(): ?string
  54.     {
  55.         return '@Profiling/Collector/rules.html.twig';
  56.     }
  57.     public function onContextResolved(SalesChannelContextResolvedEvent $event): void
  58.     {
  59.         $this->ruleIds $event->getContext()->getRuleIds();
  60.     }
  61.     private function getMatchingRules(): array
  62.     {
  63.         if (empty($this->ruleIds)) {
  64.             return [];
  65.         }
  66.         $criteria = new Criteria($this->ruleIds);
  67.         return $this->ruleRepository->search($criteriaContext::createDefaultContext())->getElements();
  68.     }
  69. }