src/Middleware/ReleaseRecordedEventsMiddleware.php
public function execute($command, callable $next)
    {
        try {
            $result = $next($command);
        } catch (\Exception $exception) {
            $this->eventRecorder->eraseEvents();

            throw $exception;
        }

        $recordedEvents = $this->eventRecorder->releaseEvents();

        foreach ($recordedEvents as $event) {
            $this->eventDispatcher->dispatch($event);
        }

        return $result;
    }
public function execute($command, callable $next)
    {
        try {
            $result = $next($command);
        } catch (\Exception $exception) {
            $this->eventRecorder->eraseEvents();

            throw $exception;
        }

        $recordedEvents = $this->eventRecorder->releaseEvents();

        foreach ($recordedEvents as $event) {
            $this->eventDispatcher->dispatch($event);
        }

        return $result;
    }
public function execute ( $ command , callable $ next ) { try { $ result = $ next ( $ command ) ; } catch ( \ Exception $ exception ) { $ this -> eventRecorder -> eraseEvents ( ) ; throw $ exception ; } $ recordedEvents = $ this -> eventRecorder -> releaseEvents ( ) ; foreach ( $ recordedEvents as $ event ) { $ this -> eventDispatcher -> dispatch ( $ event ) ; } return $ result ; }
Dispatches all the recorded events in the EventBus and erases them

@param object $command
@param callable $next

@return mixed

@throws \Exception
Dispatches all the recorded events in the EventBus and erases them