| @@ 13-53 (lines=41) @@ | ||
| 10 | HttpKernel\Event\GetResponseEvent |
|
| 11 | }; |
|
| 12 | ||
| 13 | final class DefinitionLoaderListener implements EventSubscriberInterface |
|
| 14 | { |
|
| 15 | private $locate; |
|
| 16 | ||
| 17 | public function __construct(Locator $locator) |
|
| 18 | { |
|
| 19 | $this->locate = $locator; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * {@inheritdoc} |
|
| 24 | */ |
|
| 25 | public static function getSubscribedEvents() |
|
| 26 | { |
|
| 27 | return [ |
|
| 28 | KernelEvents::REQUEST => [['loadDefinition', 30]], |
|
| 29 | ]; |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Inject in the request attributes the resource definition |
|
| 34 | * |
|
| 35 | * @param GetResponseEvent $event |
|
| 36 | * |
|
| 37 | * @return void |
|
| 38 | */ |
|
| 39 | public function loadDefinition(GetResponseEvent $event) |
|
| 40 | { |
|
| 41 | $request = $event->getRequest(); |
|
| 42 | ||
| 43 | if (!$request->attributes->has('_innmind_resource')) { |
|
| 44 | return; |
|
| 45 | } |
|
| 46 | ||
| 47 | $name = $request->attributes->get('_innmind_resource'); |
|
| 48 | $request->attributes->set( |
|
| 49 | '_innmind_resource_definition', |
|
| 50 | ($this->locate)($name) |
|
| 51 | ); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 13-45 (lines=33) @@ | ||
| 10 | HttpKernel\Event\GetResponseEvent |
|
| 11 | }; |
|
| 12 | ||
| 13 | final class RequestVerifierListener implements EventSubscriberInterface |
|
| 14 | { |
|
| 15 | private $verify; |
|
| 16 | ||
| 17 | public function __construct(Verifier $verifier) |
|
| 18 | { |
|
| 19 | $this->verify = $verifier; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * {@inheritdoc} |
|
| 24 | */ |
|
| 25 | public static function getSubscribedEvents() |
|
| 26 | { |
|
| 27 | return [ |
|
| 28 | KernelEvents::REQUEST => [['verifyRequest', 24]], |
|
| 29 | ]; |
|
| 30 | } |
|
| 31 | ||
| 32 | public function verifyRequest(GetResponseEvent $event) |
|
| 33 | { |
|
| 34 | $request = $event->getRequest(); |
|
| 35 | ||
| 36 | if (!$request->attributes->has('_innmind_resource_definition')) { |
|
| 37 | return; |
|
| 38 | } |
|
| 39 | ||
| 40 | ($this->verify)( |
|
| 41 | $request->attributes->get('_innmind_request'), |
|
| 42 | $request->attributes->get('_innmind_resource_definition') |
|
| 43 | ); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||