Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a1f5d4

Browse files
committed
feature #20567 [WebProfilerBundle] Improved cookie traffic (ro0NL)
This PR was merged into the 3.3-dev branch. Discussion ---------- [WebProfilerBundle] Improved cookie traffic | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | comma-separated list of tickets fixed by the PR, if any | License | MIT | Doc PR | reference to the documentation PR, if any ![image](https://cloud.githubusercontent.com/assets/1047696/20455635/a033a814-ae60-11e6-8500-e60146f4619e.png) Relates to #20569 in terms of getting _all_ the cookies. Commits ------- 171c6d1 [WebProfilerBundle] Improved cookie traffic
2 parents 0a17358 + 171c6d1 commit 6a1f5d4

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@
143143
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestattributes }, with_context = false) }}
144144
{% endif %}
145145

146-
<h3>Cookies</h3>
147-
148-
{% if collector.requestcookies.all is empty %}
149-
<div class="empty">
150-
<p>No cookies</p>
151-
</div>
152-
{% else %}
153-
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestcookies }, with_context = false) }}
154-
{% endif %}
155-
156146
<h3>Request Headers</h3>
157147
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestheaders, labels: ['Header', 'Value'], maxDepth: 1 }, with_context = false) }}
158148

@@ -187,6 +177,32 @@
187177
</div>
188178
</div>
189179

180+
<div class="tab {{ collector.requestcookies.all is empty and collector.responsecookies.all is empty ? 'disabled' }}">
181+
<h3 class="tab-title">Cookies</h3>
182+
183+
<div class="tab-content">
184+
<h3>Request Cookies</h3>
185+
186+
{% if collector.requestcookies.all is empty %}
187+
<div class="empty">
188+
<p>No request cookies</p>
189+
</div>
190+
{% else %}
191+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestcookies }, with_context = false) }}
192+
{% endif %}
193+
194+
<h3>Response Cookies</h3>
195+
196+
{% if collector.responsecookies.all is empty %}
197+
<div class="empty">
198+
<p>No response cookies</p>
199+
</div>
200+
{% else %}
201+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.responsecookies }, with_context = true) }}
202+
{% endif %}
203+
</div>
204+
</div>
205+
190206
<div class="tab {{ collector.sessionmetadata is empty ? 'disabled' }}">
191207
<h3 class="tab-title">Session</h3>
192208

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public function collect(Request $request, Response $response, \Exception $except
7676

7777
$statusCode = $response->getStatusCode();
7878

79+
$responseCookies = array();
80+
foreach ($response->headers->getCookies() as $cookie) {
81+
$responseCookies[$cookie->getName()] = $cookie;
82+
}
83+
7984
$this->data = array(
8085
'method' => $request->getMethod(),
8186
'format' => $request->getRequestFormat(),
@@ -91,6 +96,7 @@ public function collect(Request $request, Response $response, \Exception $except
9196
'request_attributes' => $attributes,
9297
'route' => $route,
9398
'response_headers' => $response->headers->all(),
99+
'response_cookies' => $responseCookies,
94100
'session_metadata' => $sessionMetadata,
95101
'session_attributes' => $sessionAttributes,
96102
'flashes' => $flashes,
@@ -190,6 +196,11 @@ public function getResponseHeaders()
190196
return new ParameterBag($this->data['response_headers']->getValue());
191197
}
192198

199+
public function getResponseCookies()
200+
{
201+
return new ParameterBag($this->data['response_cookies']->getValue());
202+
}
203+
193204
public function getSessionMetadata()
194205
{
195206
return $this->data['session_metadata']->getValue();

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\ParameterBag;
1516
use Symfony\Component\HttpFoundation\RedirectResponse;
1617
use Symfony\Component\HttpFoundation\Session\Session;
1718
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
@@ -25,8 +26,6 @@
2526
use Symfony\Component\HttpFoundation\Response;
2627
use Symfony\Component\HttpFoundation\Cookie;
2728
use Symfony\Component\EventDispatcher\EventDispatcher;
28-
use Symfony\Component\VarDumper\Cloner\Data;
29-
use Symfony\Component\VarDumper\Cloner\VarCloner;
3029

3130
class RequestDataCollectorTest extends TestCase
3231
{
@@ -36,7 +35,6 @@ public function testCollect()
3635

3736
$c->collect($request = $this->createRequest(), $this->createResponse());
3837

39-
$cloner = new VarCloner();
4038
$attributes = $c->getRequestAttributes();
4139

4240
$this->assertSame('request', $c->getName());
@@ -46,6 +44,7 @@ public function testCollect()
4644
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
4745
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
4846
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
47+
$this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies());
4948
$this->assertSame('html', $c->getFormat());
5049
$this->assertEquals('foobar', $c->getRoute());
5150
$this->assertEquals(array('name' => 'foo'), $c->getRouteParams());

0 commit comments

Comments
 (0)