|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MewesK\TwigSpreadsheetBundle\Twig\Node; |
|
4
|
|
|
|
|
5
|
|
|
use MewesK\TwigSpreadsheetBundle\Wrapper\PhpSpreadsheetWrapper; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class XlsHeaderNode |
|
9
|
|
|
* |
|
10
|
|
|
* @package MewesK\TwigSpreadsheetBundle\Twig\Node |
|
11
|
|
|
*/ |
|
12
|
|
|
class XlsHeaderNode extends SyntaxAwareNode |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param \Twig_Node_Expression $type |
|
16
|
|
|
* @param \Twig_Node_Expression $properties |
|
17
|
|
|
* @param \Twig_Node $body |
|
18
|
|
|
* @param int $line |
|
19
|
|
|
* @param string $tag |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(\Twig_Node_Expression $type, \Twig_Node_Expression $properties, \Twig_Node $body, $line = 0, $tag = 'xlsheader') |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct(['type' => $type, 'properties' => $properties, 'body' => $body], [], $line, $tag); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param \Twig_Compiler $compiler |
|
28
|
|
|
*/ |
|
29
|
|
|
public function compile(\Twig_Compiler $compiler) |
|
30
|
|
|
{ |
|
31
|
|
|
$compiler->addDebugInfo($this) |
|
32
|
|
|
->write('$context = ' . PhpSpreadsheetWrapper::class . '::fixContext($context);' . PHP_EOL) |
|
33
|
|
|
->write('$headerType = ') |
|
34
|
|
|
->subcompile($this->getNode('type')) |
|
35
|
|
|
->raw(';' . PHP_EOL) |
|
36
|
|
|
->write('$headerType = $headerType ? $headerType : \'header\';' . PHP_EOL) |
|
37
|
|
|
->write('$headerProperties = ') |
|
38
|
|
|
->subcompile($this->getNode('properties')) |
|
39
|
|
|
->raw(';' . PHP_EOL) |
|
40
|
|
|
->write('$context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\']->startHeaderFooter($headerType, $headerProperties);' . PHP_EOL) |
|
41
|
|
|
->write('unset($headerType, $headerProperties);' . PHP_EOL) |
|
42
|
|
|
->subcompile($this->getNode('body')) |
|
43
|
|
|
->addDebugInfo($this) |
|
44
|
|
|
->write('$context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\']->endHeaderFooter();' . PHP_EOL); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return string[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getAllowedParents(): array |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
XlsSheetNode::class |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|