public function testEscape() { $scope = new Scope(); $scope->bind('foo', 'l\'baré'); $twigExecutor = new TwigExecutor($scope->getFunctions()); $this->assertEquals('l\'baré', $twigExecutor->parse('{{ foo }}', $scope)); }
/** * {@inheritdoc} * @throws ParsingException */ public function build(Sheet $sheet, $yamlContent, Scope $scope) { // Init TwigExecutor with all user functions. $this->twigExecutor = new TwigExecutor($scope->getFunctions()); // Table. $table = new Table(); $sheet->addTable($table); if (isset($yamlContent) && isset($yamlContent['label'])) { $table->setLabel($this->twigExecutor->parse($yamlContent['label'], $scope)); } // Columns. if (!isset($yamlContent) || !array_key_exists('columns', $yamlContent)) { throw new ParsingException("'content' of type 'VerticalTable' must contains 'columns'"); } foreach ($yamlContent['columns'] as $yamlColumn) { $this->parseColumn($table, $yamlColumn, $scope); } // Lines. if (!isset($yamlContent) || !array_key_exists('lines', $yamlContent)) { throw new ParsingException("'content' of type 'VerticalTable' must contains 'lines'"); } foreach ($yamlContent['lines'] as $yamlLine) { $this->parseLine($table, $yamlLine, $scope); } }
/** * Build a model. * * @param MappingReader $mappingReader * @throws ParsingException * @return Document */ public function build(MappingReader $mappingReader) { // Init TwigExecutor with all user functions. $this->twigExecutor = new TwigExecutor($this->scope->getFunctions()); $document = new Document(); $this->parseRoot($document, $mappingReader->getMapping(), $this->scope); return $document; }
public function testBindFunction() { $scope = new Scope(); $scope->bindFunction('foo', function () { return 'hello'; }); $function = $scope->getFunction('foo'); $this->assertEquals('hello', $function()); $functions = $scope->getFunctions(); $this->assertCount(1, $functions); $this->assertEquals('hello', $functions['foo']()); }