vendor/pimcore/portal-engine/src/EventSubscriber/DownloadTrackerSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Event\Download\DownloadAssetEvent;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\StatisticsTracker\Elasticsearch\DownloadTracker;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class DownloadTrackerSubscriber implements EventSubscriberInterface
  16. {
  17.     protected $downloadTracker;
  18.     /**
  19.      * @param DownloadTracker $downloadTracker
  20.      */
  21.     public function __construct(DownloadTracker $downloadTracker)
  22.     {
  23.         $this->downloadTracker $downloadTracker;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             DownloadAssetEvent::class => 'onDownloadAsset',
  32.         ];
  33.     }
  34.     /**
  35.      * @param DownloadAssetEvent $event
  36.      *
  37.      * @throws \Exception
  38.      */
  39.     public function onDownloadAsset(DownloadAssetEvent $event)
  40.     {
  41.         $this->downloadTracker->trackEvent([
  42.             'downloadable' => $event->getDownloadable(),
  43.             'context' => $event->getDownloadContext()
  44.         ]);
  45.     }
  46. }