vendor/score/cms/src/EventSubscriber/StatHitSubscriber.php line 47

Open in your IDE?
  1. <?php
  2. namespace Score\CmsBundle\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. class StatHitSubscriber implements EventSubscriberInterface
  8. {
  9.     private $statManager;
  10.     public function __construct($statManager)
  11.     {
  12.         $this->statManager $statManager;
  13.     }
  14.      /**
  15.      * Get the value of statManager
  16.      */ 
  17.     public function getStatManager()
  18.     {
  19.         return $this->statManager;
  20.     }
  21.     /**
  22.      * Set the value of statManager
  23.      *
  24.      * @return  self
  25.      */ 
  26.     public function setStatManager($statManager)
  27.     {
  28.         $this->statManager $statManager;
  29.         return $this;
  30.     }
  31.     
  32.     public static function getSubscribedEvents()
  33.     {
  34.         return [
  35.             KernelEvents::CONTROLLER  => 'addHit',
  36.         ];
  37.     }
  38.     public function addHit($event)
  39.     {
  40.        //$uri = $
  41.        $controller $event->getController();
  42.        if(!is_array($controller))
  43.        {
  44.            return;
  45.        }
  46.        $hitTriggers = [
  47.            ['controller' => \Score\CmsBundle\Controller\Page\PublicController::class,'action' => 'subpageAction'],
  48.            ['controller' => \Score\CmsBundle\Controller\Page\PublicController::class,'action' => 'cookiesAction'], 
  49.            ['controller' => \Score\CmsBundle\Controller\Page\PublicController::class,'action' => 'searchAction'],  
  50.            ['controller' => \Score\CmsBundle\Controller\Article\PublicController::class,'action' => 'listAction'], 
  51.            ['controller' => \Score\CmsBundle\Controller\Article\PublicController::class,'action' => 'detailAction'],
  52.            ['controller' => \Score\CmsBundle\Controller\Event\PublicController::class,'action' => 'listAction'], 
  53.            ['controller' => \Score\CmsBundle\Controller\Event\PublicController::class,'action' => 'detailAction'],
  54.         ];
  55.         
  56.         foreach($hitTriggers as $hitTrigger)
  57.         {
  58.             if(is_a($controller[0],$hitTrigger['controller']) and $controller[1] == $hitTrigger['action'])
  59.             {
  60.                 $parameters $event->getRequest()->attributes->all();
  61.                
  62.                 $statData = ['source_type' => $parameters['_route'], 'source_title' => '','source_id' => ''];
  63.                 if($controller[1] == 'searchAction')
  64.                 {
  65.                     $statData['stat_type'] = 'search';
  66.                     $statData['source_id'] =  $event->getRequest()->query->get('search');
  67.                 }
  68.                 else
  69.                 {
  70.                     $statData['stat_type'] = 'request';
  71.                     if(array_key_exists('slug',$parameters))
  72.                     {
  73.                         $statData['source_id'] = $parameters['slug'];
  74.                     }
  75.                     if(array_key_exists('seoid',$parameters))
  76.                     {
  77.                         $statData['source_id'] = $parameters['seoid'];
  78.                     }
  79.                 }
  80.                 $dot strpos($statData['source_id'], '.');
  81.                 $slash strpos($statData['source_id'], '/');
  82.                 if ($dot === false and $slash === false) {
  83.                     $this->getStatManager()->addHit($statData);
  84.                 }
  85.             }
  86.         }
  87.     }
  88.    
  89. }