src/BjyAuthorize/View/UnauthorizedStrategy.php
public function onDispatchError(MvcEvent $event)
    {
        // Do nothing if the result is a response object
        $result   = $event->getResult();
        $response = $event->getResponse();

        if ($result instanceof Response || ($response && ! $response instanceof HttpResponse)) {
            return;
        }

        // Common view variables
        $viewVariables = array(
           'error'      => $event->getParam('error'),
           'identity'   => $event->getParam('identity'),
        );

        switch ($event->getError()) {
            case Controller::ERROR:
                $viewVariables['controller'] = $event->getParam('controller');
                $viewVariables['action']     = $event->getParam('action');
                break;
            case Route::ERROR:
                $viewVariables['route'] = $event->getParam('route');
                break;
            case Application::ERROR_EXCEPTION:
                if (!($event->getParam('exception') instanceof UnAuthorizedException)) {
                    return;
                }

                $viewVariables['reason'] = $event->getParam('exception')->getMessage();
                $viewVariables['error']  = 'error-unauthorized';
                break;
            default:
                /*
                 * do nothing if there is no error in the event or the error
                 * does not match one of our predefined errors (we don't want
                 * our 403 template to handle other types of errors)
                 */

                return;
        }

        $model    = new ViewModel($viewVariables);
        $response = $response ?: new HttpResponse();

        $model->setTemplate($this->getTemplate());
        $event->getViewModel()->addChild($model);
        $response->setStatusCode(403);
        $event->setResponse($response);
    }
public function onDispatchError(MvcEvent $event)
    {
        // Do nothing if the result is a response object
        $result   = $event->getResult();
        $response = $event->getResponse();

        if ($result instanceof Response || ($response && ! $response instanceof HttpResponse)) {
            return;
        }

        // Common view variables
        $viewVariables = array(
           'error'      => $event->getParam('error'),
           'identity'   => $event->getParam('identity'),
        );

        switch ($event->getError()) {
            case Controller::ERROR:
                $viewVariables['controller'] = $event->getParam('controller');
                $viewVariables['action']     = $event->getParam('action');
                break;
            case Route::ERROR:
                $viewVariables['route'] = $event->getParam('route');
                break;
            case Application::ERROR_EXCEPTION:
                if (!($event->getParam('exception') instanceof UnAuthorizedException)) {
                    return;
                }

                $viewVariables['reason'] = $event->getParam('exception')->getMessage();
                $viewVariables['error']  = 'error-unauthorized';
                break;
            default:
                /*
                 * do nothing if there is no error in the event or the error
                 * does not match one of our predefined errors (we don't want
                 * our 403 template to handle other types of errors)
                 */

                return;
        }

        $model    = new ViewModel($viewVariables);
        $response = $response ?: new HttpResponse();

        $model->setTemplate($this->getTemplate());
        $event->getViewModel()->addChild($model);
        $response->setStatusCode(403);
        $event->setResponse($response);
    }
public function onDispatchError ( MvcEvent $ event ) { // Do nothing if the result is a response object $ result = $ event -> getResult ( ) ; $ response = $ event -> getResponse ( ) ; if ( $ result instanceof Response || ( $ response && ! $ response instanceof HttpResponse ) ) { return ; } // Common view variables $ viewVariables = array ( 'error' => $ event -> getParam ( 'error' ) , 'identity' => $ event -> getParam ( 'identity' ) , ) ; switch ( $ event -> getError ( ) ) { case Controller :: ERROR : $ viewVariables [ 'controller' ] = $ event -> getParam ( 'controller' ) ; $ viewVariables [ 'action' ] = $ event -> getParam ( 'action' ) ; break ; case Route :: ERROR : $ viewVariables [ 'route' ] = $ event -> getParam ( 'route' ) ; break ; case Application :: ERROR_EXCEPTION : if ( ! ( $ event -> getParam ( 'exception' ) instanceof UnAuthorizedException ) ) { return ; } $ viewVariables [ 'reason' ] = $ event -> getParam ( 'exception' ) -> getMessage ( ) ; $ viewVariables [ 'error' ] = 'error-unauthorized' ; break ; default : /*
                 * do nothing if there is no error in the event or the error
                 * does not match one of our predefined errors (we don't want
                 * our 403 template to handle other types of errors)
                 */ return ; } $ model = new ViewModel ( $ viewVariables ) ; $ response = $ response ? : new HttpResponse ( ) ; $ model -> setTemplate ( $ this -> getTemplate ( ) ) ; $ event -> getViewModel ( ) -> addChild ( $ model ) ; $ response -> setStatusCode ( 403 ) ; $ event -> setResponse ( $ response ) ; }
Callback used when a dispatch error occurs. Modifies the
response object with an according error if the application
event contains an exception related with authorization.

@param MvcEvent $event

@return void
Callback used when a dispatch error occurs . Modifies the response object with an according error if the application event contains an exception related with authorization .