<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\EventSubscriber\Money;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Events\Core\CronJobAddEvent;
use App\Model\Core\CronJob;
use App\Settings\SettingsManager;
use App\Utils\Money\ExchangeRate;
use App\Events\Money\CurrencyRateUpdateEvent;
class CurrencySubscriber implements EventSubscriberInterface
{
private $settingsManager;
private $exchangeRate;
public function __construct(
SettingsManager $settingsManager,
ExchangeRate $exchangeRate
) {
$this->settingsManager = $settingsManager;
$this->exchangeRate = $exchangeRate;
}
public static function getSubscribedEvents(): array
{
return [
CronJobAddEvent::NAME => 'onCronJobAddEvent',
CurrencyRateUpdateEvent::NAME => 'onCurrencyRateUpdateEvent',
];
}
public function onCurrencyRateUpdateEvent(CurrencyRateUpdateEvent $event): void
{
$this->exchangeRate->getAll();
}
public function onCronJobAddEvent(CronJobAddEvent $event): void
{
$cronJob = new CronJob();
$cronJob->setName('Update exchange rate')
->setEvent('money.currency.rate')
->setClass('App\Events\Money\CurrencyRateUpdateEvent')
->setInterval(1440)
;
$event->addCronJob($cronJob);
}
}