src/EventSubscriber/Money/CurrencySubscriber.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\EventSubscriber\Money;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use App\Events\Core\CronJobAddEvent;
  12. use App\Model\Core\CronJob;
  13. use App\Settings\SettingsManager;
  14. use App\Utils\Money\ExchangeRate;
  15. use App\Events\Money\CurrencyRateUpdateEvent;
  16. class CurrencySubscriber implements EventSubscriberInterface
  17. {
  18.     private $settingsManager;
  19.     private $exchangeRate;
  20.     public function __construct(
  21.         SettingsManager $settingsManager,
  22.         ExchangeRate $exchangeRate
  23.     ) {
  24.         $this->settingsManager $settingsManager;
  25.         $this->exchangeRate $exchangeRate;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             CronJobAddEvent::NAME => 'onCronJobAddEvent',
  31.             CurrencyRateUpdateEvent::NAME => 'onCurrencyRateUpdateEvent',
  32.         ];
  33.     }
  34.     public function onCurrencyRateUpdateEvent(CurrencyRateUpdateEvent $event): void
  35.     {
  36.         $this->exchangeRate->getAll();
  37.     }
  38.     public function onCronJobAddEvent(CronJobAddEvent $event): void
  39.     {
  40.         $cronJob = new CronJob();
  41.         $cronJob->setName('Update exchange rate')
  42.             ->setEvent('money.currency.rate')
  43.             ->setClass('App\Events\Money\CurrencyRateUpdateEvent')
  44.             ->setInterval(1440)
  45.         ;
  46.         $event->addCronJob($cronJob);
  47.     }
  48. }