1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Autarky\TwigTemplating;
12:
13: use Twig_Environment;
14: use Twig_LoaderInterface;
15:
16: use Autarky\Events\EventDispatcherAwareInterface;
17: use Autarky\Events\EventDispatcherAwareTrait;
18:
19: 20: 21: 22:
23: class TwigEnvironment extends Twig_Environment implements EventDispatcherAwareInterface
24: {
25: use EventDispatcherAwareTrait;
26:
27: 28: 29:
30: public function __construct(Twig_LoaderInterface $loader = null, $options = array())
31: {
32: $options['base_template_class'] = 'Autarky\TwigTemplating\TwigTemplate';
33:
34: parent::__construct($loader, $options);
35: }
36:
37: 38: 39:
40: public function loadTemplate($path, $index = null)
41: {
42: $template = new \Autarky\TwigTemplating\Template($path);
43:
44: if ($this->eventDispatcher !== null) {
45: $this->eventDispatcher->dispatch('template.creating: '.$path,
46: new TemplateEvent($template));
47: }
48:
49:
50: $twigTemplate = parent::loadTemplate($path, $index);
51: $twigTemplate->setTemplate($template);
52: $twigTemplate->setEventDispatcher($this->eventDispatcher);
53:
54: return $twigTemplate;
55: }
56: }
57: