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

Skip to content

Commit 6266b72

Browse files
committed
merged branch dlsniper/wdt-session-metadata (PR #4428)
Commits ------- 8dd2af7 Added Session Metadata info to the Request section of the WDT Discussion ---------- [WebProfilerBundle] Added Session Metadata info to the Request section of the WDT Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/dlsniper/symfony.png?branch=wdt-session-metadata)](http://travis-ci.org/dlsniper/symfony) Fixes the following tickets: #4181 Todo: ~ License of the code: MIT Documentation PR: ~ This PR adds some session metadata available into the WDT (Created, Last used, Lifetime specifically). If you'd like to see more info then let me know. --------------------------------------------------------------------------- by travisbot at 2012-05-26T21:11:56Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1443801) (merged 9b0b4383 into 9e95199). --------------------------------------------------------------------------- by travisbot at 2012-05-26T21:24:27Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1443856) (merged 31858319 into 9e95199). --------------------------------------------------------------------------- by drak at 2012-05-27T00:48:37Z Nice addition. --------------------------------------------------------------------------- by dlsniper at 2012-05-31T21:21:37Z @Drak While using this patch on a production application I've noticed that the `$request->hasSession()` section will fail to recognize that there's no session anymore in the app if I'm not using the auto-start feature. I'm using the latest master branch, updated today around 12:00 UTC. Clearly this is not the right place to discuss that there's a problem with ::hasSession() but I wanted to ask someone else for an opinion before creating the issue/fix for it. --------------------------------------------------------------------------- by stof at 2012-06-09T10:14:05Z @dlsniper create an ticket for it, and it will become the best place to discuss it :) --------------------------------------------------------------------------- by dlsniper at 2012-06-09T10:42:58Z Ok, but then can this be merged meanwhile? --------------------------------------------------------------------------- by stof at 2012-06-09T10:58:39Z @fabpot 👍 --------------------------------------------------------------------------- by dlsniper at 2012-06-09T17:36:24Z I've opened #4529 to address the issue seen in the comment.
2 parents 1787992 + 8dd2af7 commit 6266b72

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<b>Route name</b>
3535
<span>{{ request_route }}</span>
3636
</div>
37+
<div class="sf-toolbar-info-piece">
38+
<b>Has session</b>
39+
<span>{% if collector.sessionmetadata|length %}yes{% else %}no{% endif %}</span>
40+
</div>
3741
{% endspaceless %}
3842
{% endset %}
3943
{% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
@@ -109,6 +113,16 @@
109113

110114
{% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.responseheaders } only %}
111115

116+
<h2>Session Metadata</h2>
117+
118+
{% if collector.sessionmetadata|length %}
119+
{% include 'WebProfilerBundle:Profiler:table.html.twig' with { 'data': collector.sessionmetadata } only %}
120+
{% else %}
121+
<p>
122+
<em>No session metadata</em>
123+
</p>
124+
{% endif %}
125+
112126
<h2>Session Attributes</h2>
113127

114128
{% if collector.sessionattributes|length %}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public function collect(Request $request, Response $response, \Exception $except
5959
$content = false;
6060
}
6161

62+
$sessionMetadata = array();
63+
64+
if ($request->hasSession()) {
65+
$sessionMetadata['Created'] = date(DATE_RFC822, $request->getSession()->getMetadataBag()->getCreated());
66+
$sessionMetadata['Last used'] = date(DATE_RFC822, $request->getSession()->getMetadataBag()->getLastUsed());
67+
$sessionMetadata['Lifetime'] = $request->getSession()->getMetadataBag()->getLifetime();
68+
}
69+
6270
$this->data = array(
6371
'format' => $request->getRequestFormat(),
6472
'content' => $content,
@@ -71,6 +79,7 @@ public function collect(Request $request, Response $response, \Exception $except
7179
'request_cookies' => $request->cookies->all(),
7280
'request_attributes' => $attributes,
7381
'response_headers' => $responseHeaders,
82+
'session_metadata' => $sessionMetadata,
7483
'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(),
7584
'flashes' => $request->hasSession() ? $request->getSession()->getFlashBag()->peekAll() : array(),
7685
'path_info' => $request->getPathInfo(),
@@ -117,6 +126,11 @@ public function getResponseHeaders()
117126
return new ResponseHeaderBag($this->data['response_headers']);
118127
}
119128

129+
public function getSessionMetadata()
130+
{
131+
return $this->data['session_metadata'];
132+
}
133+
120134
public function getSessionAttributes()
121135
{
122136
return $this->data['session_attributes'];

0 commit comments

Comments
 (0)