1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MewesK\TwigSpreadsheetBundle\Twig\Node; |
4
|
|
|
|
5
|
|
|
use MewesK\TwigSpreadsheetBundle\Wrapper\PhpSpreadsheetWrapper; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class XlsDocumentNode |
9
|
|
|
* |
10
|
|
|
* @package MewesK\TwigSpreadsheetBundle\Twig\Node |
11
|
|
|
*/ |
12
|
|
|
class XlsDocumentNode extends SyntaxAwareNode |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var bool |
16
|
|
|
*/ |
17
|
|
|
private $preCalculateFormulas; |
18
|
|
|
/** |
19
|
|
|
* @var null|string |
20
|
|
|
*/ |
21
|
|
|
private $diskCachingDirectory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param \Twig_Node_Expression $properties |
25
|
|
|
* @param \Twig_Node $body |
26
|
|
|
* @param int $line |
27
|
|
|
* @param string $tag |
28
|
|
|
* @param bool $preCalculateFormulas |
29
|
|
|
* @param null|string $diskCachingDirectory |
30
|
|
|
*/ |
31
|
|
|
public function __construct(\Twig_Node_Expression $properties, \Twig_Node $body, $line = 0, $tag = 'xlsdocument', $preCalculateFormulas = true, $diskCachingDirectory = null) |
32
|
|
|
{ |
33
|
|
|
parent::__construct(['properties' => $properties, 'body' => $body], [], $line, $tag); |
34
|
|
|
$this->preCalculateFormulas = $preCalculateFormulas; |
35
|
|
|
$this->diskCachingDirectory = $diskCachingDirectory; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param \Twig_Compiler $compiler |
40
|
|
|
*/ |
41
|
|
|
public function compile(\Twig_Compiler $compiler) |
42
|
|
|
{ |
43
|
|
|
$compiler->addDebugInfo($this) |
44
|
|
|
->write("ob_start();\n") |
45
|
|
|
->write('$documentProperties = ') |
46
|
|
|
->subcompile($this->getNode('properties')) |
47
|
|
|
->raw(';' . PHP_EOL) |
48
|
|
|
->write('$context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\'] = new ' . PhpSpreadsheetWrapper::class . '($context, $this->env);' . PHP_EOL) |
49
|
|
|
->write('$context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\']->startDocument($documentProperties);' . PHP_EOL) |
50
|
|
|
->write('unset($documentProperties);' . PHP_EOL) |
51
|
|
|
->subcompile($this->getNode('body')) |
52
|
|
|
->addDebugInfo($this) |
53
|
|
|
->write("ob_end_clean();\n") |
54
|
|
|
->write('$context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\']->endDocument(' . |
55
|
|
|
($this->preCalculateFormulas ? 'true' : 'false') . ', ' . |
56
|
|
|
($this->diskCachingDirectory ? '\'' . $this->diskCachingDirectory . '\'' : 'null') . ');' . PHP_EOL) |
57
|
|
|
->write('unset($context[\'' . PhpSpreadsheetWrapper::INSTANCE_KEY . '\']);' . PHP_EOL); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string[] |
62
|
|
|
*/ |
63
|
|
|
public function getAllowedParents(): array |
64
|
|
|
{ |
65
|
|
|
return []; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|