public function push(HandlerStack $stack)
    {
        $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
            $this->initEvent($request);

            return $request;
        }), 'eventDispatcher_initEvent');

        $stack->push(function (callable $handler) {
            return function (
                RequestInterface $request,
                array $options
            ) use ($handler) {
                $promise = $handler($request, $options);

                return $promise->then(
                    function (ResponseInterface $response) use ($request) {
                        $this->sendEvent($request, $response);

                        return $response;
                    },
                    function (\Exception $reason) use ($request) {
                        $this->sendErrorEvent($request, $reason);

                        throw $reason;
                    }
                );
            };
        }, 'eventDispatcher_dispatch');

        return $stack;
    }
public function push(HandlerStack $stack)
    {
        $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
            $this->initEvent($request);

            return $request;
        }), 'eventDispatcher_initEvent');

        $stack->push(function (callable $handler) {
            return function (
                RequestInterface $request,
                array $options
            ) use ($handler) {
                $promise = $handler($request, $options);

                return $promise->then(
                    function (ResponseInterface $response) use ($request) {
                        $this->sendEvent($request, $response);

                        return $response;
                    },
                    function (\Exception $reason) use ($request) {
                        $this->sendErrorEvent($request, $reason);

                        throw $reason;
                    }
                );
            };
        }, 'eventDispatcher_dispatch');

        return $stack;
    }
public function push ( HandlerStack $ stack ) { $ stack -> push ( Middleware :: mapRequest ( function ( RequestInterface $ request ) { $ this -> initEvent ( $ request ) ; return $ request ; } ) , 'eventDispatcher_initEvent' ) ; $ stack -> push ( function ( callable $ handler ) { return function ( RequestInterface $ request , array $ options ) use ( $ handler ) { $ promise = $ handler ( $ request , $ options ) ; return $ promise -> then ( function ( ResponseInterface $ response ) use ( $ request ) { $ this -> sendEvent ( $ request , $ response ) ; return $ response ; } , function ( \ Exception $ reason ) use ( $ request ) { $ this -> sendErrorEvent ( $ request , $ reason ) ; throw $ reason ; } ) ; } ; } , 'eventDispatcher_dispatch' ) ; return $ stack ; }
Push function to middleware handler

@param HandlerStack $stack

@return HandlerStack
Push function to middleware handler