示例#1
0
 /**
  * @covers Twig_Node_Expression_Binary_Concat::__construct
  */
 public function testConstructor()
 {
     $left = new Twig_Node_Expression_Constant(1, 0);
     $right = new Twig_Node_Expression_Constant(2, 0);
     $node = new Twig_Node_Expression_Binary_Concat($left, $right, 0);
     $this->assertEquals($left, $node->getNode('left'));
     $this->assertEquals($right, $node->getNode('right'));
 }
 /**
  * @param \Twig_Node_Expression_Binary_Concat $node
  * @return array
  */
 public function findValuesInNodeExpressionConcat(\Twig_Node_Expression_Binary_Concat $node)
 {
     $values = array();
     $leftValues = array();
     $rightValues = array();
     $left = $node->getNode('left');
     $right = $node->getNode('right');
     if ($left instanceof \Twig_Node_Expression_Binary_Concat) {
         $leftValues = $this->findValuesInNodeExpressionConcat($left);
     } else {
         if ($left instanceof \Twig_Node_Expression_Name) {
             $name = $left->getAttribute('name');
             $leftValues = $this->findValuesOfExpressionName($name);
         } else {
             if ($left instanceof \Twig_Node_Expression_Constant) {
                 $leftValues[] = $left->getAttribute('value');
             }
         }
     }
     if ($right instanceof \Twig_Node_Expression_Name) {
         $name = $right->getAttribute('name');
         $rightValues = $this->findValuesOfExpressionName($name);
     } else {
         if ($right instanceof \Twig_Node_Expression_Constant) {
             $rightValues[] = $right->getAttribute('value');
         }
     }
     foreach ($leftValues as $leftKey) {
         foreach ($rightValues as $rightKey) {
             $values[] = $leftKey . $rightKey;
         }
     }
     return $values;
 }