public function execute(Request $req = null, Response $res = null)
    {
        $auto = false;
        if (!isset($req)) {
            $auto = true;
            $req  = (new Request())->fromGlobals();
            $res  = (new Response($req));
        } else if (!isset($res)) {
            throw new App\Exception('You must pass a Response object when passing a Request object');
        }

        $this->param('req', $req)
             ->param('res', $res);
        try {
            $this->preExecute($req, $res);
            foreach ($this->_executables as $executable) {
                if ($executable instanceof Executable && !$executable instanceof App) {
                    $executable->preExecute($req, $res);
                }
            }
            $result = null;
            foreach ($this->_executables as $executable) {
                $result = call_user_func($executable instanceof Executable
                    ? [$executable, 'execute']
                    : $executable, $req, $res);
                if (isset($result)) {
                    break;
                }
            }
            if (!$result && !$this->_isSubapp) {
                if (isset($this->_failureHandler)) {
                    $result = call_user_func($this->_failureHandler, $req, $res);
                } else {
                    throw new App\Exception('Nothing successfully handled the request');
                }
            }
            foreach ($this->_executables as $executable) {
                if ($executable instanceof Executable && !$executable instanceof App) {
                    $executable->postExecute($req, $res);
                }
            }
            $this->postExecute($req, $res);
        } catch (\Exception $e) {
            if (isset($this->_errorHandler)) {
                $result = call_user_func($this->_errorHandler, $req, $res, $e);
            } else {
                throw $e;
            }
        }
        $this->param('req', null)
             ->param('res', null);
        
        if ($auto) {
            $res->toGlobals();
        } else {
            return $result;
        }
    }
public function execute(Request $req = null, Response $res = null)
    {
        $auto = false;
        if (!isset($req)) {
            $auto = true;
            $req  = (new Request())->fromGlobals();
            $res  = (new Response($req));
        } else if (!isset($res)) {
            throw new App\Exception('You must pass a Response object when passing a Request object');
        }

        $this->param('req', $req)
             ->param('res', $res);
        try {
            $this->preExecute($req, $res);
            foreach ($this->_executables as $executable) {
                if ($executable instanceof Executable && !$executable instanceof App) {
                    $executable->preExecute($req, $res);
                }
            }
            $result = null;
            foreach ($this->_executables as $executable) {
                $result = call_user_func($executable instanceof Executable
                    ? [$executable, 'execute']
                    : $executable, $req, $res);
                if (isset($result)) {
                    break;
                }
            }
            if (!$result && !$this->_isSubapp) {
                if (isset($this->_failureHandler)) {
                    $result = call_user_func($this->_failureHandler, $req, $res);
                } else {
                    throw new App\Exception('Nothing successfully handled the request');
                }
            }
            foreach ($this->_executables as $executable) {
                if ($executable instanceof Executable && !$executable instanceof App) {
                    $executable->postExecute($req, $res);
                }
            }
            $this->postExecute($req, $res);
        } catch (\Exception $e) {
            if (isset($this->_errorHandler)) {
                $result = call_user_func($this->_errorHandler, $req, $res, $e);
            } else {
                throw $e;
            }
        }
        $this->param('req', null)
             ->param('res', null);
        
        if ($auto) {
            $res->toGlobals();
        } else {
            return $result;
        }
    }
public function execute ( Request $ req = null , Response $ res = null ) { $ auto = false ; if ( ! isset ( $ req ) ) { $ auto = true ; $ req = ( new Request ( ) ) -> fromGlobals ( ) ; $ res = ( new Response ( $ req ) ) ; } else if ( ! isset ( $ res ) ) { throw new App \ Exception ( 'You must pass a Response object when passing a Request object' ) ; } $ this -> param ( 'req' , $ req ) -> param ( 'res' , $ res ) ; try { $ this -> preExecute ( $ req , $ res ) ; foreach ( $ this -> _executables as $ executable ) { if ( $ executable instanceof Executable && ! $ executable instanceof App ) { $ executable -> preExecute ( $ req , $ res ) ; } } $ result = null ; foreach ( $ this -> _executables as $ executable ) { $ result = call_user_func ( $ executable instanceof Executable ? [ $ executable , 'execute' ] : $ executable , $ req , $ res ) ; if ( isset ( $ result ) ) { break ; } } if ( ! $ result && ! $ this -> _isSubapp ) { if ( isset ( $ this -> _failureHandler ) ) { $ result = call_user_func ( $ this -> _failureHandler , $ req , $ res ) ; } else { throw new App \ Exception ( 'Nothing successfully handled the request' ) ; } } foreach ( $ this -> _executables as $ executable ) { if ( $ executable instanceof Executable && ! $ executable instanceof App ) { $ executable -> postExecute ( $ req , $ res ) ; } } $ this -> postExecute ( $ req , $ res ) ; } catch ( \ Exception $ e ) { if ( isset ( $ this -> _errorHandler ) ) { $ result = call_user_func ( $ this -> _errorHandler , $ req , $ res , $ e ) ; } else { throw $ e ; } } $ this -> param ( 'req' , null ) -> param ( 'res' , null ) ; if ( $ auto ) { $ res -> toGlobals ( ) ; } else { return $ result ; } }
Execute the application, running middleware in order.
@param  Coast\Request $req Request object.
@param  Coast\Response $res Response object.
Execute the application running middleware in order .