bug #37102 [WebProfilerBundle] Fix error with custom function and web profiler routing tab (JakeFr)

This PR was merged into the 4.4 branch.

Discussion
----------

[WebProfilerBundle] Fix error with custom function and web profiler routing tab

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36985
| License       | MIT
| Doc PR        | no

Here is a simple solution for #36985 as it only concerns WebProfilerBundle.

Due to the limitation in the routing tab as explained in the footnote, the route in my repo did not match in profiler (no query string in the new context) but there is no more syntax error.

Commits
-------

b35c81becb fix error with custom function and web profiler routing tab
This commit is contained in:
Fabien Potencier 2020-07-31 09:05:14 +02:00
commit 909158bdb7
2 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\WebProfilerBundle\Controller;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
@ -36,12 +37,18 @@ class RouterController
private $matcher;
private $routes;
public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null)
/**
* @var ExpressionFunctionProviderInterface[]
*/
private $expressionLanguageProviders = [];
public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
{
$this->profiler = $profiler;
$this->twig = $twig;
$this->matcher = $matcher;
$this->routes = (null === $routes && $matcher instanceof RouterInterface) ? $matcher->getRouteCollection() : $routes;
$this->expressionLanguageProviders = $expressionLanguageProviders;
}
/**
@ -94,6 +101,9 @@ class RouterController
$context = $this->matcher->getContext();
$context->setMethod($method);
$matcher = new TraceableUrlMatcher($this->routes, $context);
foreach ($this->expressionLanguageProviders as $provider) {
$matcher->addExpressionLanguageProvider($provider);
}
return $matcher->getTracesForRequest($traceRequest);
}

View File

@ -20,6 +20,8 @@
<argument type="service" id="profiler" on-invalid="null" />
<argument type="service" id="twig" />
<argument type="service" id="router" on-invalid="null" />
<argument>null</argument>
<argument type="tagged_iterator" tag="routing.expression_language_provider" />
</service>
<service id="web_profiler.controller.exception" class="Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController" public="true">