|
23 | 23 | use Symfony\Component\Routing\RequestContext;
|
24 | 24 | use Symfony\Component\Routing\RequestContextAwareInterface;
|
25 | 25 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
| 26 | +use Symfony\Component\HttpFoundation\Request; |
26 | 27 |
|
27 | 28 | /**
|
28 | 29 | * Initializes the context from the request and sets request attributes based on a matching route.
|
@@ -59,12 +60,31 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
|
59 | 60 | $this->logger = $logger;
|
60 | 61 | }
|
61 | 62 |
|
| 63 | + /** |
| 64 | + * Sets the current Request. |
| 65 | + * |
| 66 | + * The application should call this method whenever the Request |
| 67 | + * object changes (entering a Request scope for instance, but |
| 68 | + * also when leaving a Request scope -- especially when they are |
| 69 | + * nested). |
| 70 | + * |
| 71 | + * @param Request|null $request A Request instance |
| 72 | + */ |
| 73 | + public function setRequest(Request $request = null) |
| 74 | + { |
| 75 | + if (null !== $request) { |
| 76 | + $this->context->fromRequest($request); |
| 77 | + } |
| 78 | + } |
| 79 | + |
62 | 80 | public function onKernelRequest(GetResponseEvent $event)
|
63 | 81 | {
|
64 | 82 | $request = $event->getRequest();
|
65 | 83 |
|
66 | 84 | // initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
|
67 |
| - $this->context->fromRequest($request); |
| 85 | + // we call setRequest even if most of the time, it has already been done to keep compatibility |
| 86 | + // with frameworks which do not use the Symfony service container |
| 87 | + $this->setRequest($request); |
68 | 88 |
|
69 | 89 | if ($request->attributes->has('_controller')) {
|
70 | 90 | // routing is already done
|
|
0 commit comments