-
Notifications
You must be signed in to change notification settings - Fork 13
/
DisplayStartNode.php
59 lines (48 loc) · 1.57 KB
/
DisplayStartNode.php
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
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Shoot\Shoot\Twig\Node;
use Twig_Compiler as Compiler;
use Twig_Node as Node;
use Twig_Node_Module as ModuleNode;
/**
* This node is added to the top of the display method of a Twig template and is used by Shoot to wrap the method's
* contents in a callback.
*
* @internal
*/
final class DisplayStartNode extends Node
{
/** @var FindPresentationModelInterface */
private $findPresentationModel;
/** @var ModuleNode */
private $module;
/**
* @param ModuleNode $module
* @param FindPresentationModelInterface $findPresentationModel
*/
public function __construct(ModuleNode $module, FindPresentationModelInterface $findPresentationModel)
{
parent::__construct();
$this->module = $module;
$this->findPresentationModel = $findPresentationModel;
$this->setTemplateName($module->getTemplateName());
}
/**
* @param Compiler $compiler
*
* @return void
*/
public function compile(Compiler $compiler)
{
if ($this->module->hasAttribute('is_embedded')) {
return;
}
$presentationModel = $this->findPresentationModel->for($this->getTemplateName());
$compiler
->write("\$presentationModel = new $presentationModel(\$context);\n")
->write("\$originalContext = \$context;\n\n")
->write("\$callback = function (array \$context) use (\$blocks, \$originalContext) {\n")
->indent()
->write("\$suppressedException = null;\n\n");
}
}