Describe "accessDenied" event in Events class

This commit is contained in:
Dmitriy Simushev 2014-10-17 13:36:20 +00:00
parent 86f6d6429e
commit 5c52ec61da
2 changed files with 19 additions and 8 deletions

View File

@ -26,6 +26,7 @@ use Mibew\Authentication\AuthenticationManagerInterface;
use Mibew\Authentication\AuthenticationManagerAwareInterface; use Mibew\Authentication\AuthenticationManagerAwareInterface;
use Mibew\Controller\ControllerResolver; use Mibew\Controller\ControllerResolver;
use Mibew\EventDispatcher\EventDispatcher; use Mibew\EventDispatcher\EventDispatcher;
use Mibew\EventDispatcher\Events;
use Mibew\Http\CookieFactory; use Mibew\Http\CookieFactory;
use Mibew\Http\CookieFactoryAwareInterface; use Mibew\Http\CookieFactoryAwareInterface;
use Mibew\Http\Exception\AccessDeniedException as AccessDeniedHttpException; use Mibew\Http\Exception\AccessDeniedException as AccessDeniedHttpException;
@ -255,14 +256,10 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt
} }
/** /**
* Builds response for pages with denied access * Builds response for a page if access to it is denied.
* *
* Triggers "accessDenied' event to provide an ability for plugins to set custom response. * Triggers {@link \Mibew\EventDispatcher\Events::RESOURCE_ACCESS_DENIED}
* an associative array with folloing keys is passed to event listeners: * event.
* - 'request': {@link Symfony\Component\HttpFoundation\Request} object.
*
* An event listener can attach custom response to the arguments array
* (using "response" key) to send it to the client.
* *
* @param Request $request Incoming request * @param Request $request Incoming request
* @return Response * @return Response
@ -275,7 +272,7 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt
'response' => false, 'response' => false,
); );
$dispatcher = EventDispatcher::getInstance(); $dispatcher = EventDispatcher::getInstance();
$dispatcher->triggerEvent('accessDenied', $args); $dispatcher->triggerEvent(Events::RESOURCE_ACCESS_DENIED, $args);
if ($args['response'] && ($args['response'] instanceof Response)) { if ($args['response'] && ($args['response'] instanceof Response)) {
// If one of event listeners returned the response object send it // If one of event listeners returned the response object send it

View File

@ -127,4 +127,18 @@ final class Events
* options. * options.
*/ */
const PAGE_ADD_JS_PLUGIN_OPTIONS = 'pageAddJsPluginOptions'; const PAGE_ADD_JS_PLUGIN_OPTIONS = 'pageAddJsPluginOptions';
/**
* Access for resource is denied.
*
* This event is triggered if the access for resource is denied. An
* associative array with the following items is passed to the event
* handlers:
* - "request": {@link Symfony\Component\HttpFoundation\Request}, incoming
* request object.
* - "response": {@link Symfony\Component\HttpFoundation\Response}, if a
* plugin wants to send a custom response to the client it should attach
* a response object to this field.
*/
const RESOURCE_ACCESS_DENIED = 'resourceAccessDenied';
} }