-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTwigProfiledEngine.php
More file actions
49 lines (41 loc) · 1.57 KB
/
TwigProfiledEngine.php
File metadata and controls
49 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace CoreSphere\TwigProfilerBundle;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Component\Templating\TemplateNameParserInterface;
class TwigProfiledEngine extends TwigEngine
{
protected $profilerService;
/**
* Constructor.
*
* @param \Twig_Environment $environment A \Twig_Environment instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param GlobalVariables|null $globals A GlobalVariables instance or null
*/
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, GlobalVariables $globals = null, $profilerService)
{
$this->environment = $environment;
$this->parser = $parser;
if (null !== $globals) {
$environment->addGlobal('app', $globals);
}
$this->profilerService = $profilerService;
}
/**
* Renders a template.
*
* @param mixed $name A template name
* @param array $parameters An array of parameters to pass to the template
*
* @return string The evaluated template as a string
*
* @throws \InvalidArgumentException if the template does not exist
* @throws \RuntimeException if the template cannot be rendered
*/
public function render($name, array $parameters = array())
{
$this->profilerService->collectTemplateParameters($name, $parameters);
return $this->load($name)->render($parameters);
}
}