merged branch stloyd/profile_info (PR #1594)

Commits
-------

fea74db Added information page with better messages for Profiler

Discussion
----------

[WebProfiler] Added information page with better messages

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

by stloyd at 2011/08/30 23:29:27 -0700

@fabpot Any decision about this ?
This commit is contained in:
Fabien Potencier 2011-09-22 08:59:08 +02:00
commit 0547059250
5 changed files with 77 additions and 12 deletions

View File

@ -87,7 +87,7 @@ class ProfilerController extends ContainerAware
$profiler->disable();
$profiler->purge();
return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => '-')));
return new RedirectResponse($this->container->get('router')->generate('_profiler_info', array('about' => 'purge')));
}
/**
@ -100,16 +100,36 @@ class ProfilerController extends ContainerAware
$profiler = $this->container->get('profiler');
$profiler->disable();
$router = $this->container->get('router');
$file = $this->container->get('request')->files->get('file');
if (empty($file) || UPLOAD_ERR_OK !== $file->getError()) {
throw new \RuntimeException('Problem uploading the data.');
if (empty($file) || !$file->isValid()) {
return new RedirectResponse($router->generate('_profiler_info', array('about' => 'upload_error')));
}
if (!$profile = $profiler->import(file_get_contents($file->getPathname()))) {
throw new \RuntimeException('Problem uploading the data (token already exists).');
return new RedirectResponse($router->generate('_profiler_info', array('about' => 'already_exists')));
}
return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => $profile->getToken())));
return new RedirectResponse($router->generate('_profiler', array('token' => $profile->getToken())));
}
/**
* Displays information page.
*
* @param string $about
*
* @return Response A Response instance
*/
public function infoAction($about)
{
$profiler = $this->container->get('profiler');
$profiler->disable();
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:info.html.twig', array(
'about' => $about
));
}
/**

View File

@ -12,6 +12,10 @@
<default key="_controller">WebProfilerBundle:Profiler:purge</default>
</route>
<route id="_profiler_info" pattern="/info/{about}">
<default key="_controller">WebProfilerBundle:Profiler:info</default>
</route>
<route id="_profiler_import" pattern="/import">
<default key="_controller">WebProfilerBundle:Profiler:import</default>
</route>

View File

@ -5,12 +5,14 @@
</h3>
<form action="{{ path('_profiler_import') }}" method="post" enctype="multipart/form-data">
<div style="margin-bottom: 10px">
&raquo;&nbsp;<a href="{{ path('_profiler_purge', { 'token': token }) }}">Purge</a>
</div>
<div style="margin-bottom: 10px">
&raquo;&nbsp;<a href="{{ path('_profiler_export', { 'token': token }) }}">Export</a>
</div>
{% if token is not empty %}
<div style="margin-bottom: 10px">
&raquo;&nbsp;<a href="{{ path('_profiler_purge', { 'token': token }) }}">Purge</a>
</div>
<div style="margin-bottom: 10px">
&raquo;&nbsp;<a href="{{ path('_profiler_export', { 'token': token }) }}">Export</a>
</div>
{% endif %}
&raquo;&nbsp;<label for="file">Import</label><br />
<input type="file" name="file" id="file" /><br />
<button type="submit">

View File

@ -0,0 +1,39 @@
{% extends 'WebProfilerBundle:Profiler:base.html.twig' %}
{% block body %}
<div id="content">
{% include 'WebProfilerBundle:Profiler:header.html.twig' only %}
<div id="main">
<div class="clear_fix">
<div id="collector_wrapper">
<div id="collector_content">
{% block panel %}
{% if about == 'purge' %}
<h2>Profiler database was purged successful</h2>
<p>
<em>Now you need to browse some pages with Symfony Profiler enabled to collect data.</em>
</p>
{% elseif about == 'upload_error' %}
<h2>Problem with uploading the data</h2>
<p>
<em>No file given or file was not uploaded successful.</em>
</p>
{% elseif about == 'already_exists' %}
<h2>Problem with uploading the data</h2>
<p>
<em>Token already exists in database.</em>
</p>
{% endif %}
{% endblock %}
</div>
</div>
<div id="navigation">
{% render 'WebProfilerBundle:Profiler:searchBar' with { 'token': '' } %}
{% include 'WebProfilerBundle:Profiler:admin.html.twig' with { 'token': '' } only %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -14,7 +14,7 @@
<div class="clear_fix">
<div id="collector_wrapper">
<div id="collector_content">
{% block panel%}
{% block panel %}
<h2>Token not found</h2>
<p>
<em>No request matching the token "{{ token }}".</em>