From 1053dd4a3c904b60ce3914fae02aa450d9acf085 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 20 Jun 2024 17:52:34 +0200 Subject: [PATCH 01/11] Prefix all sprintf() calls --- Controller/ProfilerController.php | 8 ++++---- Csp/ContentSecurityPolicyHandler.php | 4 ++-- EventListener/WebDebugToolbarListener.php | 2 +- Profiler/CodeExtension.php | 18 +++++++++--------- Profiler/TemplateManager.php | 4 ++-- Tests/Controller/ProfilerControllerTest.php | 4 ++-- Tests/Profiler/CodeExtensionTest.php | 2 +- Tests/Resources/IconTest.php | 8 ++++---- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Controller/ProfilerController.php b/Controller/ProfilerController.php index 9ca5c1c0..41dd481c 100644 --- a/Controller/ProfilerController.php +++ b/Controller/ProfilerController.php @@ -99,7 +99,7 @@ public function panelAction(Request $request, string $token): Response } if (!$profile->hasCollector($panel)) { - throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token)); + throw new NotFoundHttpException(\sprintf('Panel "%s" is not available for token "%s".', $panel, $token)); } return $this->renderWithCspNonces($request, $this->getTemplateManager()->getName($profile, $panel), [ @@ -336,12 +336,12 @@ public function fontAction(string $fontName): Response { $this->denyAccessIfProfilerDisabled(); if ('JetBrainsMono' !== $fontName) { - throw new NotFoundHttpException(sprintf('Font file "%s.woff2" not found.', $fontName)); + throw new NotFoundHttpException(\sprintf('Font file "%s.woff2" not found.', $fontName)); } $fontFile = \dirname(__DIR__).'/Resources/fonts/'.$fontName.'.woff2'; if (!is_file($fontFile) || !is_readable($fontFile)) { - throw new NotFoundHttpException(sprintf('Cannot read font file "%s".', $fontFile)); + throw new NotFoundHttpException(\sprintf('Cannot read font file "%s".', $fontFile)); } $this->profiler?->disable(); @@ -368,7 +368,7 @@ public function openAction(Request $request): Response $filename = $this->baseDir.\DIRECTORY_SEPARATOR.$file; if (preg_match("'(^|[/\\\\])\.'", $file) || !is_readable($filename)) { - throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file)); + throw new NotFoundHttpException(\sprintf('The file "%s" cannot be opened.', $file)); } return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/open.html.twig', [ diff --git a/Csp/ContentSecurityPolicyHandler.php b/Csp/ContentSecurityPolicyHandler.php index 3ac92aba..3fca0b97 100644 --- a/Csp/ContentSecurityPolicyHandler.php +++ b/Csp/ContentSecurityPolicyHandler.php @@ -151,7 +151,7 @@ private function updateCspHeaders(Response $response, array $nonces = []): array if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) { $headers[$header][$type][] = '\'unsafe-inline\''; } - $headers[$header][$type][] = sprintf('\'nonce-%s\'', $nonces[$tokenName]); + $headers[$header][$type][] = \sprintf('\'nonce-%s\'', $nonces[$tokenName]); } } @@ -179,7 +179,7 @@ private function generateNonce(): string */ private function generateCspHeader(array $directives): string { - return array_reduce(array_keys($directives), fn ($res, $name) => ('' !== $res ? $res.'; ' : '').sprintf('%s %s', $name, implode(' ', $directives[$name])), ''); + return array_reduce(array_keys($directives), fn ($res, $name) => ('' !== $res ? $res.'; ' : '').\sprintf('%s %s', $name, implode(' ', $directives[$name])), ''); } /** diff --git a/EventListener/WebDebugToolbarListener.php b/EventListener/WebDebugToolbarListener.php index f3e818ba..a13421e7 100644 --- a/EventListener/WebDebugToolbarListener.php +++ b/EventListener/WebDebugToolbarListener.php @@ -59,7 +59,7 @@ public function isEnabled(): bool public function setMode(int $mode): void { if (self::DISABLED !== $mode && self::ENABLED !== $mode) { - throw new \InvalidArgumentException(sprintf('Invalid value provided for mode, use one of "%s::DISABLED" or "%s::ENABLED".', self::class, self::class)); + throw new \InvalidArgumentException(\sprintf('Invalid value provided for mode, use one of "%s::DISABLED" or "%s::ENABLED".', self::class, self::class)); } $this->mode = $mode; diff --git a/Profiler/CodeExtension.php b/Profiler/CodeExtension.php index c74744c4..cd7f2d44 100644 --- a/Profiler/CodeExtension.php +++ b/Profiler/CodeExtension.php @@ -57,18 +57,18 @@ public function abbrClass(string $class): string $parts = explode('\\', $class); $short = array_pop($parts); - return sprintf('%s', $class, $short); + return \sprintf('%s', $class, $short); } public function abbrMethod(string $method): string { if (str_contains($method, '::')) { [$class, $method] = explode('::', $method, 2); - $result = sprintf('%s::%s()', $this->abbrClass($class), $method); + $result = \sprintf('%s::%s()', $this->abbrClass($class), $method); } elseif ('Closure' === $method) { - $result = sprintf('%1$s', $method); + $result = \sprintf('%1$s', $method); } else { - $result = sprintf('%1$s()', $method); + $result = \sprintf('%1$s()', $method); } return $result; @@ -85,9 +85,9 @@ public function formatArgs(array $args): string $item[1] = htmlspecialchars($item[1], \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset); $parts = explode('\\', $item[1]); $short = array_pop($parts); - $formattedValue = sprintf('object(%s)', $item[1], $short); + $formattedValue = \sprintf('object(%s)', $item[1], $short); } elseif ('array' === $item[0]) { - $formattedValue = sprintf('array(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset)); + $formattedValue = \sprintf('array(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset)); } elseif ('null' === $item[0]) { $formattedValue = 'null'; } elseif ('boolean' === $item[0]) { @@ -100,7 +100,7 @@ public function formatArgs(array $args): string $formattedValue = str_replace("\n", '', htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset)); } - $result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", htmlspecialchars($key, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $formattedValue); + $result[] = \is_int($key) ? $formattedValue : \sprintf("'%s' => %s", htmlspecialchars($key, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $formattedValue); } return implode(', ', $result); @@ -164,7 +164,7 @@ public function formatFile(string $file, int $line, ?string $text = null): strin if (null === $text) { if (null !== $rel = $this->getFileRelative($file)) { $rel = explode('/', htmlspecialchars($rel, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), 2); - $text = sprintf('%s%s', htmlspecialchars($this->projectDir, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $rel[0], '/'.($rel[1] ?? '')); + $text = \sprintf('%s%s', htmlspecialchars($this->projectDir, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $rel[0], '/'.($rel[1] ?? '')); } else { $text = htmlspecialchars($file, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset); } @@ -177,7 +177,7 @@ public function formatFile(string $file, int $line, ?string $text = null): strin } if (false !== $link = $this->getFileLink($file, $line)) { - return sprintf('%s', htmlspecialchars($link, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $text); + return \sprintf('%s', htmlspecialchars($link, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $text); } return $text; diff --git a/Profiler/TemplateManager.php b/Profiler/TemplateManager.php index 2b3f8c2f..23b88b1d 100644 --- a/Profiler/TemplateManager.php +++ b/Profiler/TemplateManager.php @@ -41,7 +41,7 @@ public function getName(Profile $profile, string $panel): mixed $templates = $this->getNames($profile); if (!isset($templates[$panel])) { - throw new NotFoundHttpException(sprintf('Panel "%s" is not registered in profiler or is not present in viewed profile.', $panel)); + throw new NotFoundHttpException(\sprintf('Panel "%s" is not registered in profiler or is not present in viewed profile.', $panel)); } return $templates[$panel]; @@ -73,7 +73,7 @@ public function getNames(Profile $profile): array } if (!$loader->exists($template.'.html.twig')) { - throw new \UnexpectedValueException(sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name)); + throw new \UnexpectedValueException(\sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name)); } $templates[$name] = $template.'.html.twig'; diff --git a/Tests/Controller/ProfilerControllerTest.php b/Tests/Controller/ProfilerControllerTest.php index 6b6b6cf9..0e4e9e0d 100644 --- a/Tests/Controller/ProfilerControllerTest.php +++ b/Tests/Controller/ProfilerControllerTest.php @@ -225,7 +225,7 @@ public function testSearchBarActionDefaultPage() $this->assertSame(200, $client->getResponse()->getStatusCode()); foreach (['ip', 'status_code', 'url', 'token', 'start', 'end'] as $searchCriteria) { - $this->assertSame('', $crawler->filter(sprintf('form input[name="%s"]', $searchCriteria))->text()); + $this->assertSame('', $crawler->filter(\sprintf('form input[name="%s"]', $searchCriteria))->text()); } } @@ -334,7 +334,7 @@ public function testSearchActionWithoutToken() $client->request('GET', '/_profiler/search?ip=&method=GET&status_code=&url=&token=&start=&end=&limit=10'); $this->assertStringContainsString('results found', $client->getResponse()->getContent()); - $this->assertStringContainsString(sprintf('%s', $token, $token), $client->getResponse()->getContent()); + $this->assertStringContainsString(\sprintf('%s', $token, $token), $client->getResponse()->getContent()); } public function testPhpinfoActionWithProfilerDisabled() diff --git a/Tests/Profiler/CodeExtensionTest.php b/Tests/Profiler/CodeExtensionTest.php index 8a2c88a3..7cdedfe8 100644 --- a/Tests/Profiler/CodeExtensionTest.php +++ b/Tests/Profiler/CodeExtensionTest.php @@ -21,7 +21,7 @@ class CodeExtensionTest extends TestCase { public function testFormatFile() { - $expected = sprintf('%s at line 25', substr(__FILE__, 5), __FILE__); + $expected = \sprintf('%s at line 25', substr(__FILE__, 5), __FILE__); $this->assertEquals($expected, $this->getExtension()->formatFile(__FILE__, 25)); } diff --git a/Tests/Resources/IconTest.php b/Tests/Resources/IconTest.php index 8b9cf721..4cddbe0f 100644 --- a/Tests/Resources/IconTest.php +++ b/Tests/Resources/IconTest.php @@ -23,13 +23,13 @@ public function testIconFileContents($iconFilePath) $iconFilePath = realpath($iconFilePath); $svgFileContents = file_get_contents($iconFilePath); - $this->assertStringContainsString('xmlns="http://www.w3.org/2000/svg"', $svgFileContents, sprintf('The SVG metadata of the "%s" icon must use "http://www.w3.org/2000/svg" as its "xmlns" value.', $iconFilePath)); + $this->assertStringContainsString('xmlns="http://www.w3.org/2000/svg"', $svgFileContents, \sprintf('The SVG metadata of the "%s" icon must use "http://www.w3.org/2000/svg" as its "xmlns" value.', $iconFilePath)); - $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), sprintf('The SVG file of the "%s" icon must include a "width" attribute.', $iconFilePath)); + $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), \sprintf('The SVG file of the "%s" icon must include a "width" attribute.', $iconFilePath)); - $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), sprintf('The SVG file of the "%s" icon must include a "height" attribute.', $iconFilePath)); + $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), \sprintf('The SVG file of the "%s" icon must include a "height" attribute.', $iconFilePath)); - $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), sprintf('The SVG file of the "%s" icon must include a "viewBox" attribute.', $iconFilePath)); + $this->assertMatchesRegularExpression('~.*~s', file_get_contents($iconFilePath), \sprintf('The SVG file of the "%s" icon must include a "viewBox" attribute.', $iconFilePath)); } public static function provideIconFilePaths(): array From 84c680e565722fe027e52807dc75e82c512b2d07 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 8 Jul 2024 16:16:51 +0200 Subject: [PATCH 02/11] [WebProfilerBundle] Format workflow calls duration --- Resources/views/Collector/workflow.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/Collector/workflow.html.twig b/Resources/views/Collector/workflow.html.twig index 385e6c13..03c1d015 100644 --- a/Resources/views/Collector/workflow.html.twig +++ b/Resources/views/Collector/workflow.html.twig @@ -319,7 +319,7 @@ {% endif %} - {{ call.duration }}ms + {{ '%0.2f ms'|format(call.duration) }} {% endfor %} From 72d021feb52ece09aeba98f073d53cabaf92d3ad Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 29 Aug 2024 10:25:47 +0200 Subject: [PATCH 03/11] bump requirement for Twig to 3.12+ --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a6a1cf2d..6be16ebc 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "symfony/http-kernel": "^6.4|^7.0", "symfony/routing": "^6.4|^7.0", "symfony/twig-bundle": "^6.4|^7.0", - "twig/twig": "^3.10" + "twig/twig": "^3.12" }, "require-dev": { "symfony/browser-kit": "^6.4|^7.0", From 5c73432fcba36d4dccf0c9056f7f8dbc4b99316c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 30 Aug 2024 09:35:32 +0200 Subject: [PATCH 04/11] allow Twig 4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6be16ebc..a6efec17 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "symfony/http-kernel": "^6.4|^7.0", "symfony/routing": "^6.4|^7.0", "symfony/twig-bundle": "^6.4|^7.0", - "twig/twig": "^3.12" + "twig/twig": "^3.12|^4.0" }, "require-dev": { "symfony/browser-kit": "^6.4|^7.0", From 53ec37c259d528fb1489a8cc75a41fba3bcbf4ab Mon Sep 17 00:00:00 2001 From: HypeMC Date: Mon, 20 May 2024 06:59:56 +0200 Subject: [PATCH 05/11] [Serializer] Introduce named serializers --- CHANGELOG.md | 5 ++ .../views/Collector/serializer.html.twig | 85 +++++++++++-------- composer.json | 3 +- 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cb8328..6d2f8eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.2 +--- + + * Add support for displaying profiles of multiple serializer instances + 7.1 --- diff --git a/Resources/views/Collector/serializer.html.twig b/Resources/views/Collector/serializer.html.twig index b297ebff..8276385c 100644 --- a/Resources/views/Collector/serializer.html.twig +++ b/Resources/views/Collector/serializer.html.twig @@ -115,20 +115,33 @@
- {{ _self.render_serialize_tab(collector.data, true) }} - {{ _self.render_serialize_tab(collector.data, false) }} - - {{ _self.render_normalize_tab(collector.data, true) }} - {{ _self.render_normalize_tab(collector.data, false) }} - - {{ _self.render_encode_tab(collector.data, true) }} - {{ _self.render_encode_tab(collector.data, false) }} + {% for serializer in collector.serializerNames %} + {{ _self.render_serializer_tab(collector, serializer) }} + {% endfor %}
{% endif %} {% endblock %} -{% macro render_serialize_tab(collectorData, serialize) %} +{% macro render_serializer_tab(collector, serializer) %} +
+

{{ serializer }} {{ collector.handledCount(serializer) }}

+
+
+ {{ _self.render_serialize_tab(collector.data(serializer), true, serializer) }} + {{ _self.render_serialize_tab(collector.data(serializer), false, serializer) }} + + {{ _self.render_normalize_tab(collector.data(serializer), true, serializer) }} + {{ _self.render_normalize_tab(collector.data(serializer), false, serializer) }} + + {{ _self.render_encode_tab(collector.data(serializer), true, serializer) }} + {{ _self.render_encode_tab(collector.data(serializer), false, serializer) }} +
+
+
+{% endmacro %} + +{% macro render_serialize_tab(collectorData, serialize, serializer) %} {% set data = serialize ? collectorData.serialize : collectorData.deserialize %} {% set cellPrefix = serialize ? 'serialize' : 'deserialize' %} @@ -154,12 +167,12 @@ {% for item in data %} - {{ _self.render_data_cell(item, loop.index, cellPrefix) }} - {{ _self.render_context_cell(item, loop.index, cellPrefix) }} - {{ _self.render_normalizer_cell(item, loop.index, cellPrefix) }} - {{ _self.render_encoder_cell(item, loop.index, cellPrefix) }} + {{ _self.render_data_cell(item, loop.index, cellPrefix, serializer) }} + {{ _self.render_context_cell(item, loop.index, cellPrefix, serializer) }} + {{ _self.render_normalizer_cell(item, loop.index, cellPrefix, serializer) }} + {{ _self.render_encoder_cell(item, loop.index, cellPrefix, serializer) }} {{ _self.render_time_cell(item) }} - {{ _self.render_caller_cell(item, loop.index, cellPrefix) }} + {{ _self.render_caller_cell(item, loop.index, cellPrefix, serializer) }} {% endfor %} @@ -169,8 +182,10 @@ {% endmacro %} -{% macro render_caller_cell(item, index, method) %} +{% macro render_caller_cell(item, index, method, serializer) %} {% if item.caller is defined %} + {% set trace_id = 'sf-trace-' ~ serializer ~ '-' ~ method ~ '-' ~ index %} + - {% endmacro %} -{% macro render_context_cell(item, index, method) %} - {% set context_id = 'context-' ~ method ~ '-' ~ index %} +{% macro render_context_cell(item, index, method, serializer) %} + {% set context_id = 'context-' ~ serializer ~ '-' ~ method ~ '-' ~ index %} {% if item.type %} Type: {{ item.type }} @@ -308,8 +323,8 @@ {% endmacro %} -{% macro render_normalizer_cell(item, index, method) %} - {% set nested_normalizers_id = 'nested-normalizers-' ~ method ~ '-' ~ index %} +{% macro render_normalizer_cell(item, index, method, serializer) %} + {% set nested_normalizers_id = 'nested-normalizers-' ~ serializer ~ '-' ~ method ~ '-' ~ index %} {% if item.normalizer is defined %} {{ item.normalizer.class }} ({{ '%.2f'|format(item.normalizer.time * 1000) }} ms) @@ -329,8 +344,8 @@ {% endif %} {% endmacro %} -{% macro render_encoder_cell(item, index, method) %} - {% set nested_encoders_id = 'nested-encoders-' ~ method ~ '-' ~ index %} +{% macro render_encoder_cell(item, index, method, serializer) %} + {% set nested_encoders_id = 'nested-encoders-' ~ serializer ~ '-' ~ method ~ '-' ~ index %} {% if item.encoder is defined %} {{ item.encoder.class }} ({{ '%.2f'|format(item.encoder.time * 1000) }} ms) diff --git a/composer.json b/composer.json index a6efec17..22752414 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "conflict": { "symfony/form": "<6.4", "symfony/mailer": "<6.4", - "symfony/messenger": "<6.4" + "symfony/messenger": "<6.4", + "symfony/serializer": "<7.2" }, "autoload": { "psr-4": { "Symfony\\Bundle\\WebProfilerBundle\\": "" }, From 25184a8df1d5083b74517ea2f7c27ad1b1ae2fc1 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 24 Sep 2024 13:28:07 +0200 Subject: [PATCH 06/11] Remove useless parent method calls in tests --- Tests/DependencyInjection/WebProfilerExtensionTest.php | 4 ---- Tests/Profiler/TemplateManagerTest.php | 2 -- 2 files changed, 6 deletions(-) diff --git a/Tests/DependencyInjection/WebProfilerExtensionTest.php b/Tests/DependencyInjection/WebProfilerExtensionTest.php index 8d244d8d..2daa2d41 100644 --- a/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -54,8 +54,6 @@ public static function assertSaneContainer(Container $container) protected function setUp(): void { - parent::setUp(); - $this->kernel = $this->createMock(KernelInterface::class); $profiler = $this->createMock(Profiler::class); @@ -88,8 +86,6 @@ protected function setUp(): void protected function tearDown(): void { - parent::tearDown(); - $this->container = null; } diff --git a/Tests/Profiler/TemplateManagerTest.php b/Tests/Profiler/TemplateManagerTest.php index b837fc66..e5bf05b3 100644 --- a/Tests/Profiler/TemplateManagerTest.php +++ b/Tests/Profiler/TemplateManagerTest.php @@ -30,8 +30,6 @@ class TemplateManagerTest extends TestCase protected function setUp(): void { - parent::setUp(); - $this->profiler = $this->createMock(Profiler::class); $twigEnvironment = $this->mockTwigEnvironment(); $templates = [ From 9011a4af813b26aeb57189c4a29bbdd6364fc64b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 25 Sep 2024 14:43:29 +0200 Subject: [PATCH 07/11] [WebProfilerBundle] Update the contents of the Config panel --- Resources/views/Collector/config.html.twig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Resources/views/Collector/config.html.twig b/Resources/views/Collector/config.html.twig index ca51978f..d82701e2 100644 --- a/Resources/views/Collector/config.html.twig +++ b/Resources/views/Collector/config.html.twig @@ -72,6 +72,14 @@ {% endset %} {% set text %} + {% if symfony_version_status %} +
+
+ {{ symfony_version_status }} +
+
+ {% endif %} +
Profiler token @@ -149,7 +157,7 @@
{% endset %} - {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: true, name: 'config', status: block_status, additional_classes: 'sf-toolbar-block-right', block_attrs: 'title="' ~ symfony_version_status ~ '"' }) }} + {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: true, name: 'config', status: block_status, additional_classes: 'sf-toolbar-block-right' }) }} {% endblock %} {% block menu %} From c7133734fec38fa7c8cfc241846031a157db3f6e Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 23 Sep 2024 16:14:41 +0200 Subject: [PATCH 08/11] [HttpKernel] Improve accessibility --- Resources/views/Icon/symfony.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/Icon/symfony.svg b/Resources/views/Icon/symfony.svg index ad38fdf9..209afed7 100644 --- a/Resources/views/Icon/symfony.svg +++ b/Resources/views/Icon/symfony.svg @@ -1 +1 @@ - + From eb8f6fb0370978e5133a437f435a06a2f337357f Mon Sep 17 00:00:00 2001 From: JoppeDC Date: Thu, 25 Jul 2024 12:32:12 +0200 Subject: [PATCH 09/11] [FrameworkBundle] Finetune `AboutCommand` --- Resources/views/Collector/config.html.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/views/Collector/config.html.twig b/Resources/views/Collector/config.html.twig index ca51978f..77ec5cd0 100644 --- a/Resources/views/Collector/config.html.twig +++ b/Resources/views/Collector/config.html.twig @@ -250,17 +250,17 @@
- {{ source('@WebProfiler/Icon/' ~ (collector.haszendopcache ? 'yes' : 'no') ~ '.svg') }} + {{ source('@WebProfiler/Icon/' ~ (collector.haszendopcache ? 'yes' : 'no') ~ '.svg') }} OPcache
- {{ source('@WebProfiler/Icon/' ~ (collector.hasapcu ? 'yes' : 'no') ~ '.svg') }} + {{ source('@WebProfiler/Icon/' ~ (collector.hasapcu ? 'yes' : 'no') ~ '.svg') }} APCu
- {{ source('@WebProfiler/Icon/' ~ (collector.hasxdebug ? 'yes' : 'no') ~ '.svg') }} + {{ source('@WebProfiler/Icon/' ~ (collector.hasxdebug ? 'yes' : 'no') ~ '.svg') }} Xdebug
From d3984b81706b4e0c182307c86f38e09c316bc5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Tue, 17 Sep 2024 09:07:58 +0200 Subject: [PATCH 10/11] [WebProfilerBundle] Render the toolbar stylesheet --- Controller/ProfilerController.php | 24 +++++++++++++++++ Resources/config/routing/wdt.xml | 4 +++ Resources/views/Profiler/toolbar_js.html.twig | 4 +-- Tests/Controller/ProfilerControllerTest.php | 27 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Controller/ProfilerController.php b/Controller/ProfilerController.php index 79db4520..0e0d4f89 100644 --- a/Controller/ProfilerController.php +++ b/Controller/ProfilerController.php @@ -162,6 +162,27 @@ public function toolbarAction(Request $request, ?string $token = null): Response ]); } + /** + * Renders the Web Debug Toolbar stylesheet. + * + * @throws NotFoundHttpException + */ + public function toolbarStylesheetAction(): Response + { + $this->denyAccessIfProfilerDisabled(); + + $this->cspHandler?->disableCsp(); + + return new Response( + $this->twig->render('@WebProfiler/Profiler/toolbar.css.twig'), + 200, + [ + 'Content-Type' => 'text/css', + 'Cache-Control' => 'max-age=600, private', + ], + ); + } + /** * Renders the profiler search bar. * @@ -383,6 +404,9 @@ protected function getTemplateManager(): TemplateManager return $this->templateManager ??= new TemplateManager($this->profiler, $this->twig, $this->templates); } + /** + * @throws NotFoundHttpException + */ private function denyAccessIfProfilerDisabled(): void { if (null === $this->profiler) { diff --git a/Resources/config/routing/wdt.xml b/Resources/config/routing/wdt.xml index 0f7e960c..26bbd964 100644 --- a/Resources/config/routing/wdt.xml +++ b/Resources/config/routing/wdt.xml @@ -4,6 +4,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd"> + + web_profiler.controller.profiler::toolbarStylesheetAction + + web_profiler.controller.profiler::toolbarAction diff --git a/Resources/views/Profiler/toolbar_js.html.twig b/Resources/views/Profiler/toolbar_js.html.twig index f6b37b37..eaf9329a 100644 --- a/Resources/views/Profiler/toolbar_js.html.twig +++ b/Resources/views/Profiler/toolbar_js.html.twig @@ -9,9 +9,7 @@ }) }}
- - {{ include('@WebProfiler/Profiler/toolbar.css.twig') }} - + {# CAUTION: the contents of this file are processed by Twig before loading them as JavaScript source code. Always use '/*' comments instead diff --git a/Tests/Controller/ProfilerControllerTest.php b/Tests/Controller/ProfilerControllerTest.php index 0e4e9e0d..3933d30e 100644 --- a/Tests/Controller/ProfilerControllerTest.php +++ b/Tests/Controller/ProfilerControllerTest.php @@ -137,6 +137,33 @@ public function testToolbarActionWithEmptyToken($token) $this->assertEquals(200, $response->getStatusCode()); } + public function testToolbarStylesheetActionWithProfilerDisabled() + { + $urlGenerator = $this->createMock(UrlGeneratorInterface::class); + $twig = $this->createMock(Environment::class); + + $controller = new ProfilerController($urlGenerator, null, $twig, []); + + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('The profiler must be enabled.'); + + $controller->toolbarStylesheetAction(); + } + + public function testToolbarStylesheetAction() + { + $urlGenerator = $this->createMock(UrlGeneratorInterface::class); + $twig = $this->createMock(Environment::class); + $profiler = $this->createMock(Profiler::class); + + $controller = new ProfilerController($urlGenerator, $profiler, $twig, []); + + $response = $controller->toolbarStylesheetAction(); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('text/css', $response->headers->get('Content-Type')); + $this->assertSame('max-age=600, private', $response->headers->get('Cache-Control')); + } + public static function getEmptyTokenCases() { return [ From 1827c2cf600a760334b4fbbc610a9fe308a3f73a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 23 Oct 2024 10:11:04 +0200 Subject: [PATCH 11/11] revert allowing Twig 4 As Twig 4 will not be released before Symfony 7.2 we should not claim compatibility before a stable Twig 4 release. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 22752414..ce94b4b6 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "symfony/http-kernel": "^6.4|^7.0", "symfony/routing": "^6.4|^7.0", "symfony/twig-bundle": "^6.4|^7.0", - "twig/twig": "^3.12|^4.0" + "twig/twig": "^3.12" }, "require-dev": { "symfony/browser-kit": "^6.4|^7.0", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy