public function getTests() { $tests = array(); $names = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_AssignName::apishka('foo', 1)), array(), 1); $values = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1)), array(), 1); $node = Apishka_Templater_Node_Set::apishka(false, $names, $values, 1); $tests[] = array($node, <<<EOF // line 1 \$context["foo"] = "foo"; EOF ); $names = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_AssignName::apishka('foo', 1)), array(), 1); $values = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Print::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), 1)), array(), 1); $node = Apishka_Templater_Node_Set::apishka(true, $names, $values, 1); $tests[] = array($node, <<<EOF // line 1 ob_start(); echo "foo"; \$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Apishka_Templater_Markup(\$tmp, \$this->env->getCharset()); EOF ); $names = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_AssignName::apishka('foo', 1)), array(), 1); $values = Apishka_Templater_Node_Text::apishka('foo', 1); $node = Apishka_Templater_Node_Set::apishka(true, $names, $values, 1); $tests[] = array($node, <<<EOF // line 1 \$context["foo"] = ('' === \$tmp = "foo") ? '' : new Apishka_Templater_Markup(\$tmp, \$this->env->getCharset()); EOF ); $names = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_AssignName::apishka('foo', 1), Apishka_Templater_Node_Expression_AssignName::apishka('bar', 1)), array(), 1); $values = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node_Expression_Name::apishka('bar', 1)), array(), 1); $node = Apishka_Templater_Node_Set::apishka(false, $names, $values, 1); $tests[] = array($node, <<<EOF // line 1 list(\$context["foo"], \$context["bar"]) = array("foo", {$this->getVariableGetter('bar')}); EOF ); return $tests; }
public function parse(Apishka_Templater_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); $capture = false; if ($stream->nextIf(Apishka_Templater_Token::OPERATOR_TYPE, '=')) { $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); $stream->expect(Apishka_Templater_Token::BLOCK_END_TYPE); if (count($names) !== count($values)) { throw new Apishka_Templater_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getFilename()); } } else { $capture = true; if (count($names) > 1) { throw new Apishka_Templater_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getFilename()); } $stream->expect(Apishka_Templater_Token::BLOCK_END_TYPE); $values = $this->parser->subparse(array($this, 'decideBlockEnd'), true); $stream->expect(Apishka_Templater_Token::BLOCK_END_TYPE); } return Apishka_Templater_Node_Set::apishka($capture, $names, $values, $lineno, $this->getTag()); }
public function getTests() { $twig = new Apishka_Templater_Environment($this->createMock('Apishka_Templater_LoaderInterface')); $tests = array(); $body = Apishka_Templater_Node_Text::apishka('foo', 1); $extends = null; $blocks = Apishka_Templater_Node::apishka(); $macros = Apishka_Templater_Node::apishka(); $traits = Apishka_Templater_Node::apishka(); $filename = 'foo.twig'; $node = Apishka_Templater_Node_Module::apishka($body, $extends, $blocks, $macros, $traits, Apishka_Templater_Node::apishka(array()), $filename); $tests[] = array($node, <<<EOF <?php /* foo.twig */ class __TwigTemplate_%x extends Apishka_Templater_TemplateAbstract { public function __construct(Apishka_Templater_Environment \$env) { parent::__construct(\$env); \$this->parent = false; \$this->blocks = array( ); } public function getSupportedNames() { return array( 'foo.twig', ); } protected function doDisplay(array \$context, array \$blocks = array()) { // line 1 echo "foo"; } public function getTemplateName() { return "foo.twig"; } public function getDebugInfo() { return array ( 26 => 1,); } } EOF , $twig, true); $body = Apishka_Templater_Node::apishka(array()); $extends = Apishka_Templater_Node_Expression_Constant::apishka('layout.twig', 1); $node = Apishka_Templater_Node_Module::apishka($body, $extends, $blocks, $macros, $traits, Apishka_Templater_Node::apishka(array()), $filename); $tests[] = array($node, <<<EOF <?php /* foo.twig */ class __TwigTemplate_%x extends Apishka_Templater_TemplateAbstract { public function __construct(Apishka_Templater_Environment \$env) { parent::__construct(\$env); // line 1 \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1); \$this->blocks = array( ); } public function getSupportedNames() { return array( 'foo.twig', ); } protected function doGetParent(array \$context) { return "layout.twig"; } protected function doDisplay(array \$context, array \$blocks = array()) { \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks)); } public function getTemplateName() { return "foo.twig"; } public function isTraitable() { return false; } public function getDebugInfo() { return array ( 11 => 1,); } } EOF , $twig, true); $set = Apishka_Templater_Node_Set::apishka(false, Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_AssignName::apishka('foo', 4))), Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Expression_Constant::apishka('foo', 4))), 4); $body = Apishka_Templater_Node::apishka(array($set)); $extends = Apishka_Templater_Node_Expression_Conditional::apishka(Apishka_Templater_Node_Expression_Constant::apishka(true, 2), Apishka_Templater_Node_Expression_Constant::apishka('foo', 2), Apishka_Templater_Node_Expression_Constant::apishka('foo', 2), 2); $node = Apishka_Templater_Node_Module::apishka($body, $extends, $blocks, $macros, $traits, Apishka_Templater_Node::apishka(array()), $filename); $tests[] = array($node, <<<EOF <?php /* foo.twig */ class __TwigTemplate_%x extends Apishka_Templater_TemplateAbstract { public function getSupportedNames() { return array( 'foo.twig', ); } protected function doGetParent(array \$context) { // line 2 return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2); } protected function doDisplay(array \$context, array \$blocks = array()) { // line 4 \$context["foo"] = "foo"; // line 2 \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks)); } public function getTemplateName() { return "foo.twig"; } public function isTraitable() { return false; } public function getDebugInfo() { return array ( 24 => 2, 22 => 4, 16 => 2,); } } EOF , $twig, true); return $tests; }
public function getFilterBodyNodesData() { return array(array(Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Text::apishka(' ', 1))), Apishka_Templater_Node::apishka(array())), array($input = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Set::apishka(false, Apishka_Templater_Node::apishka(), Apishka_Templater_Node::apishka(), 1))), $input), array($input = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Set::apishka(true, Apishka_Templater_Node::apishka(), Apishka_Templater_Node::apishka(array(Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Text::apishka('foo', 1))))), 1))), $input)); }