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