class TemplateManager in Devel 8
Same name and namespace in other branches
- 8.3 webprofiler/src/Profiler/TemplateManager.php \Drupal\webprofiler\Profiler\TemplateManager
- 8.2 webprofiler/src/Profiler/TemplateManager.php \Drupal\webprofiler\Profiler\TemplateManager
- 4.x webprofiler/src/Profiler/TemplateManager.php \Drupal\webprofiler\Profiler\TemplateManager
Profiler Templates Manager
Hierarchy
- class \Drupal\webprofiler\Profiler\TemplateManager
Expanded class hierarchy of TemplateManager
2 files declare their use of TemplateManager
- DashboardController.php in webprofiler/
src/ Controller/ DashboardController.php - ToolbarController.php in webprofiler/
src/ Controller/ ToolbarController.php
1 string reference to 'TemplateManager'
- webprofiler.services.yml in webprofiler/
webprofiler.services.yml - webprofiler/webprofiler.services.yml
1 service uses TemplateManager
File
- webprofiler/
src/ Profiler/ TemplateManager.php, line 21
Namespace
Drupal\webprofiler\ProfilerView source
class TemplateManager {
/**
* @var \Twig_Environment
*/
protected $twig;
/**
* @var \Twig_Loader_Chain
*/
protected $twigLoader;
/**
* @var array
*/
protected $templates;
/**
* @var \Symfony\Component\HttpKernel\Profiler\Profiler
*/
protected $profiler;
/**
* Constructor.
*
* @param SymfonyProfiler $profiler
* @param \Twig_Environment $twig
* @param \Twig_Loader_Chain $twigLoader
* @param array $templates
*/
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;
}
/**
* Gets the template name for a given panel.
*
* @param Profile $profile
* @param string $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];
}
/**
* Gets the templates for a given profile.
*
* @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 = [];
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TemplateManager:: |
protected | property | ||
TemplateManager:: |
protected | property | ||
TemplateManager:: |
protected | property | ||
TemplateManager:: |
protected | property | ||
TemplateManager:: |
public | function | Gets the template name for a given panel. | |
TemplateManager:: |
protected | function | Gets template names of templates that are present in the viewed profile. | |
TemplateManager:: |
public | function | Gets the templates for a given profile. | |
TemplateManager:: |
public | function | Constructor. |