TemplateManager.php in Devel 8
File
webprofiler/src/Profiler/TemplateManager.php
View source
<?php
namespace Drupal\webprofiler\Profiler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profiler as SymfonyProfiler;
use Symfony\Component\HttpKernel\Profiler\Profile;
class TemplateManager {
protected $twig;
protected $twigLoader;
protected $templates;
protected $profiler;
public function __construct(SymfonyProfiler $profiler, \Twig_Environment $twig, \Twig_Loader_Chain $twigLoader, array $templates) {
$this->profiler = $profiler;
$this->twig = $twig;
$this->twigLoader = $twigLoader;
$this->templates = $templates;
}
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];
}
public function getTemplates(Profile $profile) {
$templates = $this
->getNames($profile);
foreach ($templates as $name => $template) {
$templates[$name] = $this->twig
->loadTemplate($template);
}
return $templates;
}
protected function getNames(Profile $profile) {
$templates = [];
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->twigLoader
->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;
}
}