1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MewesK\TwigSpreadsheetBundle\Twig\Node; |
4
|
|
|
|
5
|
|
|
use MewesK\TwigSpreadsheetBundle\Wrapper\HeaderFooterWrapper; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class HeaderFooterNode. |
9
|
|
|
*/ |
10
|
|
|
class HeaderFooterNode extends BaseNode |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $baseType; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* HeaderFooterNode constructor. |
19
|
|
|
* |
20
|
|
|
* @param array $nodes |
21
|
|
|
* @param array $attributes |
22
|
|
|
* @param int $lineNo |
23
|
|
|
* @param string|null $tag |
24
|
|
|
* @param string $baseType |
25
|
|
|
* |
26
|
|
|
* @throws \InvalidArgumentException |
27
|
|
|
*/ |
28
|
|
|
public function __construct(array $nodes = [], array $attributes = [], int $lineNo = 0, string $tag = null, string $baseType = HeaderFooterWrapper::BASETYPE_HEADER) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($nodes, $attributes, $lineNo, $tag); |
31
|
|
|
|
32
|
|
|
$this->baseType = HeaderFooterWrapper::validateBaseType(strtolower($baseType)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \Twig_Compiler $compiler |
37
|
|
|
*/ |
38
|
|
|
public function compile(\Twig_Compiler $compiler) |
39
|
|
|
{ |
40
|
|
|
$compiler->addDebugInfo($this) |
41
|
|
|
->write(self::CODE_FIX_CONTEXT) |
42
|
|
|
->write('$headerFooterType = ') |
43
|
|
|
->subcompile($this->getNode('type')) |
44
|
|
|
->raw(';'.PHP_EOL) |
45
|
|
|
->write('$headerFooterProperties = ') |
46
|
|
|
->subcompile($this->getNode('properties')) |
47
|
|
|
->raw(';'.PHP_EOL) |
48
|
|
|
->write(self::CODE_INSTANCE.'->startHeaderFooter(\''.$this->baseType.'\', $headerFooterType, $headerFooterProperties);'.PHP_EOL) |
49
|
|
|
->write('unset($headerFooterType, $headerFooterProperties);'.PHP_EOL) |
50
|
|
|
->subcompile($this->getNode('body')) |
51
|
|
|
->addDebugInfo($this) |
52
|
|
|
->write(self::CODE_INSTANCE.'->endHeaderFooter();'.PHP_EOL); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function getAllowedParents(): array |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
SheetNode::class, |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|