Пример #1
0
 public function getTests()
 {
     $tests = array();
     $expr1 = Apishka_Templater_Node_Expression_Constant::apishka(1, 1);
     $expr2 = Apishka_Templater_Node_Expression_Constant::apishka(2, 1);
     $expr3 = Apishka_Templater_Node_Expression_Constant::apishka(3, 1);
     $node = Apishka_Templater_Node_Expression_Conditional::apishka($expr1, $expr2, $expr3, 1);
     $tests[] = array($node, '((1) ? (2) : (3))');
     return $tests;
 }
Пример #2
0
 private function parseConditionalExpression($expr)
 {
     while ($this->parser->getStream()->nextIf(Apishka_Templater_Token::PUNCTUATION_TYPE, '?')) {
         if (!$this->parser->getStream()->nextIf(Apishka_Templater_Token::PUNCTUATION_TYPE, ':')) {
             $expr2 = $this->parseExpression();
             if ($this->parser->getStream()->nextIf(Apishka_Templater_Token::PUNCTUATION_TYPE, ':')) {
                 $expr3 = $this->parseExpression();
             } else {
                 $expr3 = Apishka_Templater_Node_Expression_Constant::apishka('', $this->parser->getCurrentToken()->getLine());
             }
         } else {
             $expr2 = $expr;
             $expr3 = $this->parseExpression();
         }
         $expr = Apishka_Templater_Node_Expression_Conditional::apishka($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine());
     }
     return $expr;
 }
Пример #3
0
    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;
    }