Skip to content

Instantly share code, notes, and snippets.

@geomagilles
Last active July 21, 2018 16:29
Show Gist options
  • Save geomagilles/39ab348efd3ab74c55fccc5e741caa5f to your computer and use it in GitHub Desktop.
Save geomagilles/39ab348efd3ab74c55fccc5e741caa5f to your computer and use it in GitHub Desktop.
<?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