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

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.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             DownloadAssetEvent::class => 'onDownloadAsset',
  29.         ];
  30.     }
  31.     /**
  32.      * @param DownloadAssetEvent $event
  33.      *
  34.      * @throws \Exception
  35.      */
  36.     public function onDownloadAsset(DownloadAssetEvent $event)
  37.     {
  38.         $this->downloadTracker->trackEvent([
  39.             'downloadable' => $event->getDownloadable(),
  40.             'context' => $event->getDownloadContext()
  41.         ]);
  42.     }
  43. }