src/Core/Controller/AbstractController.php
public function execute()
    {
        try {
            // @ prepare hook
            $this->prepareExecute();

            // @ before event
            $this->triggerEvent('onControllerBeforeExecute', [
                'controller' => $this
            ]);

            // Prepare the last middleware, the last middleware is the real logic of this controller self.
            $chain = $this->getMiddlewareChain()->setEndMiddleware(function () {
                return $this->container->call([$this, 'doExecute'], [], $this);
            });

            // Do execute, run middlewares.
            $result = $chain->execute(new ControllerData(get_object_vars($this)));

            // @ post hook
            $result = $this->postExecute($result);

            // @ post event
            $this->triggerEvent('onControllerAfterExecute', [
                'controller' => $this,
                'result' => &$result,
            ]);
        } catch (ValidateFailException $e) {
            return $this->processFailure($e);
        } catch (\Exception $e) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            $result = $this->processFailure($e);

            if (!$this->app->get('system.debug')) {
                return $result;
            }

            throw $e;
        } catch (\Throwable $t) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            $this->processFailure(new \ErrorException(
                $t->getMessage(),
                $t->getCode(),
                E_ERROR,
                $t->getFile(),
                $t->getLine(),
                $t
            ));

            throw $t;
        }

        if ($result === false) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            return $this->processFailure(new \Exception('Unknown Error'));
        }

        // Now we return result to package that it will handle response.
        return $this->processSuccess($result);
    }
public function execute()
    {
        try {
            // @ prepare hook
            $this->prepareExecute();

            // @ before event
            $this->triggerEvent('onControllerBeforeExecute', [
                'controller' => $this
            ]);

            // Prepare the last middleware, the last middleware is the real logic of this controller self.
            $chain = $this->getMiddlewareChain()->setEndMiddleware(function () {
                return $this->container->call([$this, 'doExecute'], [], $this);
            });

            // Do execute, run middlewares.
            $result = $chain->execute(new ControllerData(get_object_vars($this)));

            // @ post hook
            $result = $this->postExecute($result);

            // @ post event
            $this->triggerEvent('onControllerAfterExecute', [
                'controller' => $this,
                'result' => &$result,
            ]);
        } catch (ValidateFailException $e) {
            return $this->processFailure($e);
        } catch (\Exception $e) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            $result = $this->processFailure($e);

            if (!$this->app->get('system.debug')) {
                return $result;
            }

            throw $e;
        } catch (\Throwable $t) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            $this->processFailure(new \ErrorException(
                $t->getMessage(),
                $t->getCode(),
                E_ERROR,
                $t->getFile(),
                $t->getLine(),
                $t
            ));

            throw $t;
        }

        if ($result === false) {
            // You can do some error handling in processFailure(), for example: rollback the transaction.
            return $this->processFailure(new \Exception('Unknown Error'));
        }

        // Now we return result to package that it will handle response.
        return $this->processSuccess($result);
    }
public function execute ( ) { try { // @ prepare hook $ this -> prepareExecute ( ) ; // @ before event $ this -> triggerEvent ( 'onControllerBeforeExecute' , [ 'controller' => $ this ] ) ; // Prepare the last middleware, the last middleware is the real logic of this controller self. $ chain = $ this -> getMiddlewareChain ( ) -> setEndMiddleware ( function ( ) { return $ this -> container -> call ( [ $ this , 'doExecute' ] , [ ] , $ this ) ; } ) ; // Do execute, run middlewares. $ result = $ chain -> execute ( new ControllerData ( get_object_vars ( $ this ) ) ) ; // @ post hook $ result = $ this -> postExecute ( $ result ) ; // @ post event $ this -> triggerEvent ( 'onControllerAfterExecute' , [ 'controller' => $ this , 'result' => & $ result , ] ) ; } catch ( ValidateFailException $ e ) { return $ this -> processFailure ( $ e ) ; } catch ( \ Exception $ e ) { // You can do some error handling in processFailure(), for example: rollback the transaction. $ result = $ this -> processFailure ( $ e ) ; if ( ! $ this -> app -> get ( 'system.debug' ) ) { return $ result ; } throw $ e ; } catch ( \ Throwable $ t ) { // You can do some error handling in processFailure(), for example: rollback the transaction. $ this -> processFailure ( new \ ErrorException ( $ t -> getMessage ( ) , $ t -> getCode ( ) , E_ERROR , $ t -> getFile ( ) , $ t -> getLine ( ) , $ t ) ) ; throw $ t ; } if ( $ result === false ) { // You can do some error handling in processFailure(), for example: rollback the transaction. return $ this -> processFailure ( new \ Exception ( 'Unknown Error' ) ) ; } // Now we return result to package that it will handle response. return $ this -> processSuccess ( $ result ) ; }
Execute the controller.

@return mixed Return executed result.

@throws \Exception
@throws \Throwable
Execute the controller .