1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Autarky\TwigTemplating;
12:
13: use Autarky\Events\EventDispatcherAwareInterface;
14: use Autarky\Events\EventDispatcherAwareTrait;
15:
16: 17: 18: 19:
20: abstract class TwigTemplate extends \Twig_Template implements EventDispatcherAwareInterface
21: {
22: use EventDispatcherAwareTrait;
23:
24: 25: 26:
27: protected $template;
28:
29: 30: 31: 32: 33:
34: public function setTemplate(\Autarky\TwigTemplating\Template $template)
35: {
36: $this->template = $template;
37: }
38:
39: 40: 41:
42: public function display(array $context, array $blocks = array())
43: {
44: $templateContext = clone $this->template->getContext();
45:
46: if ($context) {
47: $templateContext->replace($context);
48: }
49:
50: if ($this->eventDispatcher !== null) {
51: $this->eventDispatcher->dispatch(
52: 'template.rendering: '.$this->template->getName(),
53: new TemplateEvent($this->template, $templateContext)
54: );
55: }
56:
57: parent::display($templateContext->toArray(), $blocks);
58: }
59: }
60: