mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 13:08:45 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
<?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\Bundle\WebProfilerBundle\Controller;
|
||||
|
||||
use Symfony\Component\Debug\ExceptionHandler;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Loader\ExistsLoaderInterface;
|
||||
use Twig\Loader\SourceContextLoaderInterface;
|
||||
|
||||
/**
|
||||
* ExceptionController.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ExceptionController
|
||||
{
|
||||
protected $twig;
|
||||
protected $debug;
|
||||
protected $profiler;
|
||||
private $fileLinkFormat;
|
||||
|
||||
public function __construct(Profiler $profiler = null, Environment $twig, $debug, FileLinkFormatter $fileLinkFormat = null)
|
||||
{
|
||||
$this->profiler = $profiler;
|
||||
$this->twig = $twig;
|
||||
$this->debug = $debug;
|
||||
$this->fileLinkFormat = $fileLinkFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the exception panel for the given token.
|
||||
*
|
||||
* @param string $token The profiler token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function showAction($token)
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
|
||||
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
|
||||
$template = $this->getTemplate();
|
||||
|
||||
if (!$this->templateExists($template)) {
|
||||
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
|
||||
|
||||
return new Response($handler->getContent($exception), 200, ['Content-Type' => 'text/html']);
|
||||
}
|
||||
|
||||
$code = $exception->getStatusCode();
|
||||
|
||||
return new Response($this->twig->render(
|
||||
$template,
|
||||
[
|
||||
'status_code' => $code,
|
||||
'status_text' => Response::$statusTexts[$code],
|
||||
'exception' => $exception,
|
||||
'logger' => null,
|
||||
'currentContent' => '',
|
||||
]
|
||||
), 200, ['Content-Type' => 'text/html']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the exception panel stylesheet for the given token.
|
||||
*
|
||||
* @param string $token The profiler token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function cssAction($token)
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
|
||||
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
|
||||
$template = $this->getTemplate();
|
||||
|
||||
if (!$this->templateExists($template)) {
|
||||
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
|
||||
|
||||
return new Response($handler->getStylesheet($exception), 200, ['Content-Type' => 'text/css']);
|
||||
}
|
||||
|
||||
return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, ['Content-Type' => 'text/css']);
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
return '@Twig/Exception/'.($this->debug ? 'exception' : 'error').'.html.twig';
|
||||
}
|
||||
|
||||
// to be removed when the minimum required version of Twig is >= 2.0
|
||||
protected function templateExists($template)
|
||||
{
|
||||
$loader = $this->twig->getLoader();
|
||||
|
||||
if (1 === Environment::MAJOR_VERSION && !$loader instanceof ExistsLoaderInterface) {
|
||||
try {
|
||||
if ($loader instanceof SourceContextLoaderInterface) {
|
||||
$loader->getSourceContext($template);
|
||||
} else {
|
||||
$loader->getSource($template);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (LoaderError $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $loader->exists($template);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\Bundle\WebProfilerBundle\Controller;
|
||||
|
||||
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||
|
||||
/**
|
||||
* Renders the exception panel.
|
||||
*
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ExceptionPanelController
|
||||
{
|
||||
private $errorRenderer;
|
||||
private $profiler;
|
||||
|
||||
public function __construct(HtmlErrorRenderer $errorRenderer, Profiler $profiler = null)
|
||||
{
|
||||
$this->errorRenderer = $errorRenderer;
|
||||
$this->profiler = $profiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the exception panel stacktrace for the given token.
|
||||
*/
|
||||
public function body(string $token): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$exception = $this->profiler->loadProfile($token)
|
||||
->getCollector('exception')
|
||||
->getException()
|
||||
;
|
||||
|
||||
return new Response($this->errorRenderer->getBody($exception), 200, ['Content-Type' => 'text/html']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the exception panel stylesheet.
|
||||
*/
|
||||
public function stylesheet(): Response
|
||||
{
|
||||
return new Response($this->errorRenderer->getStylesheet(), 200, ['Content-Type' => 'text/css']);
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\WebProfilerBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FullStack;
|
||||
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
|
||||
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
|
||||
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
@@ -24,6 +27,8 @@ use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ProfilerController
|
||||
{
|
||||
@@ -32,26 +37,15 @@ class ProfilerController
|
||||
private $profiler;
|
||||
private $twig;
|
||||
private $templates;
|
||||
private $toolbarPosition;
|
||||
private $cspHandler;
|
||||
private $baseDir;
|
||||
|
||||
/**
|
||||
* @param UrlGeneratorInterface $generator The URL Generator
|
||||
* @param Profiler $profiler The profiler
|
||||
* @param Environment $twig The twig environment
|
||||
* @param array $templates The templates
|
||||
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
|
||||
* @param ContentSecurityPolicyHandler $cspHandler The Content-Security-Policy handler
|
||||
* @param string $baseDir The project root directory
|
||||
*/
|
||||
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
|
||||
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, ContentSecurityPolicyHandler $cspHandler = null, string $baseDir = null)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
$this->profiler = $profiler;
|
||||
$this->twig = $twig;
|
||||
$this->templates = $templates;
|
||||
$this->toolbarPosition = $toolbarPosition;
|
||||
$this->cspHandler = $cspHandler;
|
||||
$this->baseDir = $baseDir;
|
||||
}
|
||||
@@ -59,17 +53,11 @@ class ProfilerController
|
||||
/**
|
||||
* Redirects to the last profiles.
|
||||
*
|
||||
* @return RedirectResponse A RedirectResponse instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function homeAction()
|
||||
public function homeAction(): RedirectResponse
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
return new RedirectResponse($this->generator->generate('_profiler_search_results', ['token' => 'empty', 'limit' => 10]), 302, ['Content-Type' => 'text/html']);
|
||||
}
|
||||
@@ -77,26 +65,17 @@ class ProfilerController
|
||||
/**
|
||||
* Renders a profiler panel for the given token.
|
||||
*
|
||||
* @param Request $request The current HTTP request
|
||||
* @param string $token The profiler token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function panelAction(Request $request, $token)
|
||||
public function panelAction(Request $request, string $token): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
if (null !== $this->cspHandler) {
|
||||
$this->cspHandler->disableCsp();
|
||||
}
|
||||
|
||||
$panel = $request->query->get('panel', 'request');
|
||||
$panel = $request->query->get('panel');
|
||||
$page = $request->query->get('page', 'home');
|
||||
|
||||
if ('latest' === $token && $latest = current($this->profiler->find(null, null, 1, null, null, null))) {
|
||||
@@ -104,14 +83,30 @@ class ProfilerController
|
||||
}
|
||||
|
||||
if (!$profile = $this->profiler->loadProfile($token)) {
|
||||
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', ['about' => 'no_token', 'token' => $token, 'request' => $request]), 200, ['Content-Type' => 'text/html']);
|
||||
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/info.html.twig', ['about' => 'no_token', 'token' => $token, 'request' => $request]);
|
||||
}
|
||||
|
||||
if (null === $panel) {
|
||||
$panel = 'request';
|
||||
|
||||
foreach ($profile->getCollectors() as $collector) {
|
||||
if ($collector instanceof ExceptionDataCollector && $collector->hasException()) {
|
||||
$panel = $collector->getName();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($collector instanceof DumpDataCollector && $collector->getDumpsCount() > 0) {
|
||||
$panel = $collector->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$profile->hasCollector($panel)) {
|
||||
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
|
||||
}
|
||||
|
||||
return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), [
|
||||
return $this->renderWithCspNonces($request, $this->getTemplateManager()->getName($profile, $panel), [
|
||||
'token' => $token,
|
||||
'profile' => $profile,
|
||||
'collector' => $profile->getCollector($panel),
|
||||
@@ -121,26 +116,21 @@ class ProfilerController
|
||||
'templates' => $this->getTemplateManager()->getNames($profile),
|
||||
'is_ajax' => $request->isXmlHttpRequest(),
|
||||
'profiler_markup_version' => 2, // 1 = original profiler, 2 = Symfony 2.8+ profiler
|
||||
]), 200, ['Content-Type' => 'text/html']);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Web Debug Toolbar.
|
||||
*
|
||||
* @param Request $request The current HTTP Request
|
||||
* @param string $token The profiler token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function toolbarAction(Request $request, $token)
|
||||
public function toolbarAction(Request $request, string $token = null): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
if ($request->hasSession() && ($session = $request->getSession()) && $session->isStarted() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
|
||||
if ($request->hasSession() && ($session = $request->getSession())->isStarted() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
|
||||
// keep current flashes for one more request if using AutoExpireFlashBag
|
||||
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
|
||||
}
|
||||
@@ -155,11 +145,6 @@ class ProfilerController
|
||||
return new Response('', 404, ['Content-Type' => 'text/html']);
|
||||
}
|
||||
|
||||
// the toolbar position (top, bottom, normal, or null -- use the configuration)
|
||||
if (null === $position = $request->query->get('position')) {
|
||||
$position = $this->toolbarPosition;
|
||||
}
|
||||
|
||||
$url = null;
|
||||
try {
|
||||
$url = $this->generator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
@@ -168,8 +153,8 @@ class ProfilerController
|
||||
}
|
||||
|
||||
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/toolbar.html.twig', [
|
||||
'full_stack' => class_exists(FullStack::class),
|
||||
'request' => $request,
|
||||
'position' => $position,
|
||||
'profile' => $profile,
|
||||
'templates' => $this->getTemplateManager()->getNames($profile),
|
||||
'profiler_url' => $url,
|
||||
@@ -181,17 +166,11 @@ class ProfilerController
|
||||
/**
|
||||
* Renders the profiler search bar.
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function searchBarAction(Request $request)
|
||||
public function searchBarAction(Request $request): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
if (null !== $this->cspHandler) {
|
||||
$this->cspHandler->disableCsp();
|
||||
@@ -239,20 +218,11 @@ class ProfilerController
|
||||
/**
|
||||
* Renders the search results.
|
||||
*
|
||||
* @param Request $request The current HTTP Request
|
||||
* @param string $token The token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function searchResultsAction(Request $request, $token)
|
||||
public function searchResultsAction(Request $request, string $token): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
if (null !== $this->cspHandler) {
|
||||
$this->cspHandler->disableCsp();
|
||||
@@ -268,7 +238,7 @@ class ProfilerController
|
||||
$end = $request->query->get('end', null);
|
||||
$limit = $request->query->get('limit');
|
||||
|
||||
return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', [
|
||||
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/results.html.twig', [
|
||||
'request' => $request,
|
||||
'token' => $token,
|
||||
'profile' => $profile,
|
||||
@@ -281,23 +251,17 @@ class ProfilerController
|
||||
'end' => $end,
|
||||
'limit' => $limit,
|
||||
'panel' => null,
|
||||
]), 200, ['Content-Type' => 'text/html']);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Narrows the search bar.
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function searchAction(Request $request)
|
||||
public function searchAction(Request $request): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
$ip = $request->query->get('ip');
|
||||
$method = $request->query->get('method');
|
||||
@@ -342,17 +306,11 @@ class ProfilerController
|
||||
/**
|
||||
* Displays the PHP info.
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function phpinfoAction()
|
||||
public function phpinfoAction(): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
$this->denyAccessIfProfilerDisabled();
|
||||
|
||||
if (null !== $this->cspHandler) {
|
||||
$this->cspHandler->disableCsp();
|
||||
@@ -368,11 +326,9 @@ class ProfilerController
|
||||
/**
|
||||
* Displays the source of a file.
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function openAction(Request $request)
|
||||
public function openAction(Request $request): Response
|
||||
{
|
||||
if (null === $this->baseDir) {
|
||||
throw new NotFoundHttpException('The base dir should be set.');
|
||||
@@ -391,19 +347,17 @@ class ProfilerController
|
||||
throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file));
|
||||
}
|
||||
|
||||
return new Response($this->twig->render('@WebProfiler/Profiler/open.html.twig', [
|
||||
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/open.html.twig', [
|
||||
'filename' => $filename,
|
||||
'file' => $file,
|
||||
'line' => $line,
|
||||
]), 200, ['Content-Type' => 'text/html']);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Template Manager.
|
||||
*
|
||||
* @return TemplateManager The Template Manager
|
||||
*/
|
||||
protected function getTemplateManager()
|
||||
protected function getTemplateManager(): TemplateManager
|
||||
{
|
||||
if (null === $this->templateManager) {
|
||||
$this->templateManager = new TemplateManager($this->profiler, $this->twig, $this->templates);
|
||||
@@ -412,14 +366,23 @@ class ProfilerController
|
||||
return $this->templateManager;
|
||||
}
|
||||
|
||||
private function renderWithCspNonces(Request $request, $template, $variables, $code = 200, $headers = ['Content-Type' => 'text/html'])
|
||||
private function denyAccessIfProfilerDisabled()
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
}
|
||||
|
||||
$this->profiler->disable();
|
||||
}
|
||||
|
||||
private function renderWithCspNonces(Request $request, string $template, array $variables, int $code = 200, array $headers = ['Content-Type' => 'text/html']): Response
|
||||
{
|
||||
$response = new Response('', $code, $headers);
|
||||
|
||||
$nonces = $this->cspHandler ? $this->cspHandler->getNonces($request, $response) : [];
|
||||
|
||||
$variables['csp_script_nonce'] = isset($nonces['csp_script_nonce']) ? $nonces['csp_script_nonce'] : null;
|
||||
$variables['csp_style_nonce'] = isset($nonces['csp_style_nonce']) ? $nonces['csp_style_nonce'] : null;
|
||||
$variables['csp_script_nonce'] = $nonces['csp_script_nonce'] ?? null;
|
||||
$variables['csp_style_nonce'] = $nonces['csp_style_nonce'] ?? null;
|
||||
|
||||
$response->setContent($this->twig->render($template, $variables));
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -23,9 +24,9 @@ use Symfony\Component\Routing\RouterInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* RouterController.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RouterController
|
||||
{
|
||||
@@ -34,24 +35,26 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the profiler panel for the given token.
|
||||
*
|
||||
* @param string $token The profiler token
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function panelAction($token)
|
||||
public function panelAction(string $token): Response
|
||||
{
|
||||
if (null === $this->profiler) {
|
||||
throw new NotFoundHttpException('The profiler must be enabled.');
|
||||
@@ -77,17 +80,13 @@ class RouterController
|
||||
|
||||
/**
|
||||
* Returns the routing traces associated to the given request.
|
||||
*
|
||||
* @param string $method
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getTraces(RequestDataCollector $request, $method)
|
||||
private function getTraces(RequestDataCollector $request, string $method): array
|
||||
{
|
||||
$traceRequest = Request::create(
|
||||
$request->getPathInfo(),
|
||||
$request->getRequestServer(true)->get('REQUEST_METHOD'),
|
||||
[],
|
||||
\in_array($request->getMethod(), ['DELETE', 'PATCH', 'POST', 'PUT'], true) ? $request->getRequestRequest()->all() : $request->getRequestQuery()->all(),
|
||||
$request->getRequestCookies(true)->all(),
|
||||
[],
|
||||
$request->getRequestServer(true)->all()
|
||||
@@ -96,6 +95,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user