Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged branch wodor/profiler_rely_on_profile_3372 (PR #3373)
Commits ------- 1472283 fixed CS bc73487 renamed template to TemplateManager , moved profiler to the deps of manager 5fd6ed6 properties protected abd0eb7 generating template names moved out from controller to another class 6138e80 [Profiler] relying on config of displayed profile instead of current config. Discussion ---------- [2.2][Profiler] relying on config of displayed profile instead of current config Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: code of ProfilerController is not covered by any test Fixes the following tickets: #3372 Todo: ~ This fixes the exception which is raised when viewed profile has other data collectors than in config of currently run profiler. explained here #3372 --------------------------------------------------------------------------- by fabpot at 2012-02-16T06:11:00Z This should probably be done on the 2.0 branch. Also, I think we need to check if the panel is actually available in the current profiler (if not, we won't be able to display it anyway). So, both checks are important. --------------------------------------------------------------------------- by wodor at 2012-02-18T10:15:40Z defects mentioned by Stof are fixed
- Loading branch information
Showing
5 changed files
with
325 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\WebProfilerBundle\Profiler; | ||
|
||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\Profiler\Profiler; | ||
use Symfony\Component\HttpKernel\Profiler\Profile; | ||
use Symfony\Bundle\TwigBundle\TwigEngine; | ||
|
||
/** | ||
* Profiler Templates Manager | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Artur Wielogórski <wodor@wodor.net> | ||
*/ | ||
class TemplateManager { | ||
|
||
/** | ||
* @var \Symfony\Bundle\TwigBundle\TwigEngine | ||
*/ | ||
protected $templating; | ||
|
||
/** | ||
* @var \Twig_Environment | ||
*/ | ||
protected $twig; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $templates; | ||
|
||
/** | ||
* @var \Symfony\Component\HttpKernel\Profiler\Profiler | ||
*/ | ||
protected $profiler; | ||
|
||
/** | ||
* @param \Symfony\Bundle\TwigBundle\TwigEngine $templating | ||
* @param \Twig_Environment $twig | ||
* @param array $templates | ||
*/ | ||
public function __construct(Profiler $profiler, TwigEngine $templating, \Twig_Environment $twig, array $templates) | ||
{ | ||
$this->profiler = $profiler; | ||
$this->templating = $templating; | ||
$this->twig = $twig; | ||
$this->templates = $templates; | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile | ||
* @param $panel | ||
* @return mixed | ||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | ||
*/ | ||
public function getName(Profile $profile, $panel) | ||
{ | ||
$templates = $this->getNames($profile); | ||
|
||
if (!isset($templates[$panel])) { | ||
throw new NotFoundHttpException(sprintf('Panel "%s" is not registered in profiler or is not present in viewed profile.', $panel)); | ||
} | ||
|
||
return $templates[$panel]; | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile | ||
* @return array | ||
*/ | ||
public function getTemplates(Profile $profile) | ||
{ | ||
$templates = $this->getNames($profile); | ||
foreach ($templates as $name => $template) { | ||
$templates[$name] = $this->twig->loadTemplate($template); | ||
} | ||
|
||
return $templates; | ||
} | ||
|
||
/** | ||
* Gets template names of templates that are | ||
* present in the viewed profile | ||
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile | ||
* @return array | ||
* @throws \UnexpectedValueException | ||
*/ | ||
protected function getNames(Profile $profile) | ||
{ | ||
$templates = array(); | ||
|
||
foreach ($this->templates as $arguments) { | ||
if (null === $arguments) { | ||
continue; | ||
} | ||
|
||
list($name, $template) = $arguments; | ||
|
||
if (!$this->profiler->has($name) || !$profile->hasCollector($name)) { | ||
continue; | ||
} | ||
|
||
if ('.html.twig' === substr($template, -10)) { | ||
$template = substr($template, 0, -10); | ||
} | ||
|
||
if (!$this->templating->exists($template.'.html.twig')) { | ||
throw new \UnexpectedValueException(sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name)); | ||
} | ||
|
||
$templates[$name] = $template.'.html.twig'; | ||
} | ||
|
||
return $templates; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.