Skip to content

Commit

Permalink
bug #37102 [WebProfilerBundle] Fix error with custom function and web…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Jul 31, 2020
2 parents c946a25 + a086e18 commit 8c61857
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Controller/RouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -94,6 +101,9 @@ private function getTraces(RequestDataCollector $request, string $method): array
$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);
}
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/profiler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 8c61857

Please sign in to comment.