Last active
July 21, 2018 16:29
-
-
Save geomagilles/39ab348efd3ab74c55fccc5e741caa5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
public function handle() | |
{ | |
... | |
// wait for at most 3 providers quotation, 3 days maximum | |
$event = (new Wait(ProvidersQuotationGatheredEvent::class))->days(3)->execute(); | |
... | |
} | |
public function onEvent($event) | |
{ | |
if ($event instanceof ProviderQuotationEvent) { | |
// tell provider it's too late, if we already have enough quotations | |
if (count($this->quotations) >= self::ENOUGH_PROVIDERS) { | |
(new NotifyProviderItsTooLate($event->provider, $event->quotation))->execute(); | |
return; | |
} | |
// update or add provider quotation in quotations array | |
$this->quotation[$event->provider->id] = $event->quotation; | |
// if enough quotation, continue the main flow | |
if (count($this->quotations) >= self::ENOUGH_PROVIDERS) { | |
// send an event to itself | |
self::whereId($this->getId())->send(new ProvidersQuotationGatheredEvent()); | |
} | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment