-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[FrameworkBundle][Routing] Use a PSR-11 container in FrameworkBundle Router #24738
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 all commits
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 |
---|---|---|
|
@@ -11,13 +11,14 @@ | |
|
||
namespace Symfony\Bundle\FrameworkBundle\Routing; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; | ||
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface; | ||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; | ||
use Symfony\Component\Routing\Router as BaseRouter; | ||
use Symfony\Component\Routing\RequestContext; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; | ||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; | ||
|
@@ -32,22 +33,31 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI | |
{ | ||
private $container; | ||
private $collectedParameters = array(); | ||
private $paramFetcher; | ||
|
||
/** | ||
* @param ContainerInterface $container A ContainerInterface instance | ||
* @param mixed $resource The main resource to load | ||
* @param array $options An array of options | ||
* @param RequestContext $context The context | ||
* @param LoggerInterface|null $logger | ||
* @param ContainerInterface $container A ContainerInterface instance | ||
* @param mixed $resource The main resource to load | ||
* @param array $options An array of options | ||
* @param RequestContext $context The context | ||
* @param ContainerInterface|null $parameters A ContainerInterface instance allowing to fetch parameters | ||
* @param LoggerInterface|null $logger | ||
*/ | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null) | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, ContainerInterface $parameters = 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. the new arg should be added last, otherwise that's a BC break, isn't it? 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->container = $container; | ||
|
||
$this->resource = $resource; | ||
$this->context = $context ?: new RequestContext(); | ||
$this->logger = $logger; | ||
$this->setOptions($options); | ||
|
||
if ($parameters) { | ||
$this->paramFetcher = array($parameters, 'get'); | ||
} elseif ($container instanceof SymfonyContainerInterface) { | ||
$this->paramFetcher = array($container, 'getParameter'); | ||
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.
Not true actually. The |
||
} else { | ||
throw new \LogicException(sprintf('You should either pass a "%s" instance or provide the $parameters argument of the "%s" method.', SymfonyContainerInterface::class, __METHOD__)); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -142,9 +152,7 @@ private function resolve($value) | |
return $value; | ||
} | ||
|
||
$container = $this->container; | ||
|
||
$escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) { | ||
$escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($value) { | ||
// skip %% | ||
if (!isset($match[1])) { | ||
return '%%'; | ||
|
@@ -154,7 +162,7 @@ private function resolve($value) | |
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1])); | ||
} | ||
|
||
$resolved = $container->getParameter($match[1]); | ||
$resolved = ($this->paramFetcher)($match[1]); | ||
|
||
if (is_string($resolved) || is_numeric($resolved)) { | ||
$this->collectedParameters[$match[1]] = $resolved; | ||
|
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.
on-invalid="ignore"
, because we still allow to install the Fwb 4.x with DI component 3.4