Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc36fcff

Browse files
smnandrefabpot
authored andcommitted
[WebProfilerBundle] Render the toolbar stylesheet
1 parentbb53ec1 commitc36fcff

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ public function toolbarAction(Request $request, ?string $token = null): Response
162162
]);
163163
}
164164

165+
/**
166+
* Renders the Web Debug Toolbar stylesheet.
167+
*
168+
* @throws NotFoundHttpException
169+
*/
170+
publicfunctiontoolbarStylesheetAction():Response
171+
{
172+
$this->denyAccessIfProfilerDisabled();
173+
174+
$this->cspHandler?->disableCsp();
175+
176+
returnnewResponse(
177+
$this->twig->render('@WebProfiler/Profiler/toolbar.css.twig'),
178+
200,
179+
[
180+
'Content-Type' =>'text/css',
181+
'Cache-Control' =>'max-age=600, private',
182+
],
183+
);
184+
}
185+
165186
/**
166187
* Renders the profiler search bar.
167188
*
@@ -383,6 +404,9 @@ protected function getTemplateManager(): TemplateManager
383404
return$this->templateManager ??=newTemplateManager($this->profiler,$this->twig,$this->templates);
384405
}
385406

407+
/**
408+
* @throws NotFoundHttpException
409+
*/
386410
privatefunctiondenyAccessIfProfilerDisabled():void
387411
{
388412
if (null ===$this->profiler) {

‎src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
66

7+
<routeid="_wdt_stylesheet"path="/styles.css">
8+
<defaultkey="_controller">web_profiler.controller.profiler::toolbarStylesheetAction</default>
9+
</route>
10+
711
<routeid="_wdt"path="/{token}">
812
<defaultkey="_controller">web_profiler.controller.profiler::toolbarAction</default>
913
</route>

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
}) }}
1010
</div>
1111

12-
<style{%ifcsp_style_nonce %}nonce="{{csp_style_nonce }}"{%endif %}>
13-
{{include('@WebProfiler/Profiler/toolbar.css.twig') }}
14-
</style>
12+
<linkrel="stylesheet"{%ifcsp_style_nonce %}nonce="{{csp_style_nonce }}"{%endif %}href="{{ url('_wdt_stylesheet') }}" />
1513

1614
{# CAUTION: the contents of this file are processed by Twig before loading
1715
them as JavaScript source code. Always use '/*' comments instead

‎src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,33 @@ public function testToolbarActionWithEmptyToken($token)
137137
$this->assertEquals(200,$response->getStatusCode());
138138
}
139139

140+
publicfunctiontestToolbarStylesheetActionWithProfilerDisabled()
141+
{
142+
$urlGenerator =$this->createMock(UrlGeneratorInterface::class);
143+
$twig =$this->createMock(Environment::class);
144+
145+
$controller =newProfilerController($urlGenerator,null,$twig, []);
146+
147+
$this->expectException(NotFoundHttpException::class);
148+
$this->expectExceptionMessage('The profiler must be enabled.');
149+
150+
$controller->toolbarStylesheetAction();
151+
}
152+
153+
publicfunctiontestToolbarStylesheetAction()
154+
{
155+
$urlGenerator =$this->createMock(UrlGeneratorInterface::class);
156+
$twig =$this->createMock(Environment::class);
157+
$profiler =$this->createMock(Profiler::class);
158+
159+
$controller =newProfilerController($urlGenerator,$profiler,$twig, []);
160+
161+
$response =$controller->toolbarStylesheetAction();
162+
$this->assertSame(200,$response->getStatusCode());
163+
$this->assertSame('text/css',$response->headers->get('Content-Type'));
164+
$this->assertSame('max-age=600, private',$response->headers->get('Cache-Control'));
165+
}
166+
140167
publicstaticfunctiongetEmptyTokenCases()
141168
{
142169
return [

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp