-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Synchronized Service alternative, backwards compatible #8904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c55f1ea
a58a8a6
f9b10ba
018b719
93e60ea
b1a062d
1b2ef74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Event; | ||
|
||
/** | ||
* Triggered whenever a request is fully processed. | ||
* | ||
* @author Benjamin Eberlei <kontakt@beberlei.de> | ||
*/ | ||
class RequestFinishedEvent extends KernelEvent | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,11 @@ | |
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpKernel\Event\RequestFinishedEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\RequestContext as KernelRequestContext; | ||
use Symfony\Component\Routing\Exception\MethodNotAllowedException; | ||
use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface; | ||
|
@@ -36,6 +38,7 @@ class RouterListener implements EventSubscriberInterface | |
private $context; | ||
private $logger; | ||
private $request; | ||
private $kernelContext; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -46,7 +49,7 @@ class RouterListener implements EventSubscriberInterface | |
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null) | ||
public function __construct($matcher, KernelRequestContext $kernelContext, RequestContext $context = null, LoggerInterface $logger = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also a BC break so the PR summary is wrong when telling there is none There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR is not finished yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class should now work in 2.3 or 2.4+ without any change. |
||
{ | ||
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) { | ||
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.'); | ||
|
@@ -58,6 +61,7 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte | |
|
||
$this->matcher = $matcher; | ||
$this->context = $context ?: $matcher->getContext(); | ||
$this->kernelContext = $kernelContext; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the naming here is indeed weird, but the duplication makes it hard anyways. |
||
$this->logger = $logger; | ||
} | ||
|
||
|
@@ -71,22 +75,27 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte | |
* | ||
* @param Request|null $request A Request instance | ||
*/ | ||
public function setRequest(Request $request = null) | ||
private function populateRoutingContext(Request $request = null) | ||
{ | ||
if (null !== $request && $this->request !== $request) { | ||
$this->context->fromRequest($request); | ||
} | ||
$this->request = $request; | ||
} | ||
|
||
public function onKernelRequestFinished(RequestFinishedEvent $event) | ||
{ | ||
$this->populateRoutingContext($this->kernelContext->getParentRequest()); | ||
} | ||
|
||
public function onKernelRequest(GetResponseEvent $event) | ||
{ | ||
$request = $event->getRequest(); | ||
|
||
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance) | ||
// we call setRequest even if most of the time, it has already been done to keep compatibility | ||
// with frameworks which do not use the Symfony service container | ||
$this->setRequest($request); | ||
$this->populateRoutingContext($request); | ||
|
||
if ($request->attributes->has('_controller')) { | ||
// routing is already done | ||
|
@@ -139,6 +148,7 @@ public static function getSubscribedEvents() | |
{ | ||
return array( | ||
KernelEvents::REQUEST => array(array('onKernelRequest', 32)), | ||
KernelEvents::REQUEST_FINISHED => array(array('onKernelRequestFinished', 0)), | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This BC break still need to be handled (it affects Silex for instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class is not
@api
and constructors are not part of the interface of an class in terms of API Backwards compatiblitiy in my opinion, because their construction is another concern and handled by a factory of sorts.Same for the other constructor change below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beberlei This is valid only if the factories are themselves part of the component and so updated at the same time. It is not the case here. Merging this as is will break Silex code while the component was marked as stable and so Silex is already using
~2.3
as requirement based on this expectation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While i see the validity of this argument, this would mean that Symfonys path using DIC without factories has a flaw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should now work in 2.3 or 2.4+ without any change.