|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MewesK\TwigExcelBundle\Twig\TokenParser; |
|
4
|
|
|
|
|
5
|
|
|
use MewesK\TwigExcelBundle\Twig\Node\XlsDocumentNode; |
|
6
|
|
|
use MewesK\TwigExcelBundle\Twig\TokenParser\Traits\FixMacroCallsTrait; |
|
7
|
|
|
use MewesK\TwigExcelBundle\Twig\TokenParser\Traits\RemoveTextNodeTrait; |
|
8
|
|
|
use Twig_Token; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class XlsDocumentTokenParser |
|
12
|
|
|
* |
|
13
|
|
|
* @package MewesK\TwigExcelBundle\Twig\TokenParser |
|
14
|
|
|
*/ |
|
15
|
|
|
class XlsDocumentTokenParser extends AbstractTokenParser |
|
16
|
|
|
{ |
|
17
|
|
|
use FixMacroCallsTrait; |
|
18
|
|
|
use RemoveTextNodeTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
private $preCalculateFormulas; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var null|string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $diskCachingDirectory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param bool $preCalculateFormulas |
|
31
|
|
|
* @param null|string $diskCachingDirectory |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($preCalculateFormulas = true, $diskCachingDirectory = null) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->preCalculateFormulas = $preCalculateFormulas; |
|
36
|
|
|
$this->diskCachingDirectory = $diskCachingDirectory; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param Twig_Token $token |
|
41
|
|
|
* |
|
42
|
|
|
* @return XlsDocumentNode |
|
43
|
|
|
* @throws \Twig_Error_Syntax |
|
44
|
|
|
*/ |
|
45
|
|
|
public function parse(Twig_Token $token) |
|
46
|
|
|
{ |
|
47
|
|
|
// parse attributes |
|
48
|
|
|
$properties = $this->parseProperties($token); |
|
49
|
|
|
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); |
|
50
|
|
|
|
|
51
|
|
|
// parse body |
|
52
|
|
|
$body = $this->parseBody(); |
|
53
|
|
|
$this->removeTextNodesRecursively($body); |
|
54
|
|
|
$this->fixMacroCallsRecursively($body); |
|
55
|
|
|
|
|
56
|
|
|
// return node |
|
57
|
|
|
return new XlsDocumentNode($properties, $body, $token->getLine(), $this->getTag(), $this->preCalculateFormulas, $this->diskCachingDirectory); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getTag() |
|
64
|
|
|
{ |
|
65
|
|
|
return 'xlsdocument'; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|