2019-08-02 03:23:59 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Contracts\Listener;
|
|
|
|
use App\Events\PirepAccepted;
|
2019-11-06 00:44:31 +08:00
|
|
|
use App\Services\BidService;
|
2019-08-02 03:23:59 +08:00
|
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do stuff with bids - like if a PIREP is accepted, then remove the bid
|
|
|
|
*/
|
|
|
|
class BidEvents extends Listener
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $events
|
|
|
|
*/
|
|
|
|
public function subscribe(Dispatcher $events): void
|
|
|
|
{
|
|
|
|
$events->listen(
|
|
|
|
PirepAccepted::class,
|
|
|
|
'App\Listeners\BidEvents@onPirepAccept'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a PIREP is accepted, remove any bids
|
|
|
|
*
|
|
|
|
* @param PirepAccepted $event
|
|
|
|
*
|
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function onPirepAccept(PirepAccepted $event): void
|
|
|
|
{
|
2019-11-06 00:44:31 +08:00
|
|
|
$this->bidSvc->removeBidForPirep($event->pirep);
|
2019-08-02 03:23:59 +08:00
|
|
|
}
|
|
|
|
}
|