2019-08-02 03:23:59 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Contracts\Listener;
|
|
|
|
use App\Events\PirepAccepted;
|
2019-11-20 23:16:01 +08:00
|
|
|
use App\Events\PirepRejected;
|
2019-11-06 00:44:31 +08:00
|
|
|
use App\Services\BidService;
|
2019-08-02 03:23:59 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do stuff with bids - like if a PIREP is accepted, then remove the bid
|
|
|
|
*/
|
2019-11-20 23:16:01 +08:00
|
|
|
class BidEventHandler extends Listener
|
2019-08-02 03:23:59 +08:00
|
|
|
{
|
2019-11-20 23:16:01 +08:00
|
|
|
public static $callbacks = [
|
|
|
|
PirepAccepted::class => 'onPirepAccept',
|
|
|
|
PirepRejected::class => 'onPirepReject',
|
|
|
|
];
|
|
|
|
|
2019-11-06 00:44:31 +08:00
|
|
|
private $bidSvc;
|
2019-08-02 03:23:59 +08:00
|
|
|
|
2019-11-06 00:44:31 +08:00
|
|
|
public function __construct(BidService $bidSvc)
|
|
|
|
{
|
|
|
|
$this->bidSvc = $bidSvc;
|
2019-08-02 03:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-20 23:16:01 +08:00
|
|
|
* When a PIREP is accepted, remove any bids
|
|
|
|
*
|
|
|
|
* @param PirepAccepted $event
|
|
|
|
*
|
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Exception
|
2019-08-02 03:23:59 +08:00
|
|
|
*/
|
2019-11-20 23:16:01 +08:00
|
|
|
public function onPirepAccept(PirepAccepted $event): void
|
2019-08-02 03:23:59 +08:00
|
|
|
{
|
2019-11-20 23:16:01 +08:00
|
|
|
$this->bidSvc->removeBidForPirep($event->pirep);
|
2019-08-02 03:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a PIREP is accepted, remove any bids
|
|
|
|
*
|
2019-11-20 23:16:01 +08:00
|
|
|
* @param PirepRejected $event
|
2019-08-02 03:23:59 +08:00
|
|
|
*
|
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2019-11-20 23:16:01 +08:00
|
|
|
public function onPirepReject(PirepRejected $event): void
|
2019-08-02 03:23:59 +08:00
|
|
|
{
|
2019-11-06 00:44:31 +08:00
|
|
|
$this->bidSvc->removeBidForPirep($event->pirep);
|
2019-08-02 03:23:59 +08:00
|
|
|
}
|
|
|
|
}
|