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 9e951991).

---------------------------------------------------------------------------

by travisbot at 2012-05-26T21:24:27Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1443856) (merged 31858319 into 9e951991).

---------------------------------------------------------------------------

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.
This commit is contained in:
Fabien Potencier 2012-06-09 21:44:05 +02:00
commit 6266b72ddc
2 changed files with 28 additions and 0 deletions

View File

@ -34,6 +34,10 @@
<b>Route name</b>
<span>{{ request_route }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Has session</b>
<span>{% if collector.sessionmetadata|length %}yes{% else %}no{% endif %}</span>
</div>
{% endspaceless %}
{% endset %}
{% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
@ -109,6 +113,16 @@
{% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.responseheaders } only %}
<h2>Session Metadata</h2>
{% if collector.sessionmetadata|length %}
{% include 'WebProfilerBundle:Profiler:table.html.twig' with { 'data': collector.sessionmetadata } only %}
{% else %}
<p>
<em>No session metadata</em>
</p>
{% endif %}
<h2>Session Attributes</h2>
{% if collector.sessionattributes|length %}

View File

@ -59,6 +59,14 @@ class RequestDataCollector extends DataCollector
$content = false;
}
$sessionMetadata = array();
if ($request->hasSession()) {
$sessionMetadata['Created'] = date(DATE_RFC822, $request->getSession()->getMetadataBag()->getCreated());
$sessionMetadata['Last used'] = date(DATE_RFC822, $request->getSession()->getMetadataBag()->getLastUsed());
$sessionMetadata['Lifetime'] = $request->getSession()->getMetadataBag()->getLifetime();
}
$this->data = array(
'format' => $request->getRequestFormat(),
'content' => $content,
@ -71,6 +79,7 @@ class RequestDataCollector extends DataCollector
'request_cookies' => $request->cookies->all(),
'request_attributes' => $attributes,
'response_headers' => $responseHeaders,
'session_metadata' => $sessionMetadata,
'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(),
'flashes' => $request->hasSession() ? $request->getSession()->getFlashBag()->peekAll() : array(),
'path_info' => $request->getPathInfo(),
@ -117,6 +126,11 @@ class RequestDataCollector extends DataCollector
return new ResponseHeaderBag($this->data['response_headers']);
}
public function getSessionMetadata()
{
return $this->data['session_metadata'];
}
public function getSessionAttributes()
{
return $this->data['session_attributes'];