public function convert(Expr\ArrayDimFetch $node, $returnAsArray = false) { $collected = $this->arrayManipulator->arrayNeedToBeSplit($node); if ($collected !== false) { return $this->splitArray($collected, $returnAsArray); } $result = $this->dispatcher->pVarOrNewExpr($node->var) . '[' . (null !== $node->dim ? $this->dispatcher->p($node->dim) : '') . ']'; if ($returnAsArray === true) { return array('head' => '', 'lastExpr' => $result, 'vars' => array()); } return $result; }
/** * @param Assign $node * @param Expr $leftNode * @param Expr $rightNode * @param string $operatorString */ private function arrayDimFetchCase($node, $leftNode, $rightNode, $operatorString, $precedence, $associativity) { $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass()); $head = ''; if ($leftNode instanceof ArrayDimFetch) { if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($leftNode))) { $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, 1); } else { $result = $this->dispatcher->pExpr_ArrayDimFetch($leftNode, true); $head .= $result['head']; $leftString = $result['lastExpr']; } } else { $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1); } if ($rightNode instanceof ArrayDimFetch) { if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($rightNode))) { $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1); } else { $result = $this->dispatcher->pExpr_ArrayDimFetch($rightNode, true); $head .= $result['head']; $rightString = $result['lastExpr']; } } elseif ($this->isSomething($rightNode)) { $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass()); // @TODO add test case for each $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1); } else { $head .= $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1) . ";\n"; $rightString = $this->dispatcher->p($rightNode->var); } return $head . 'let ' . $leftString . $operatorString . $rightString; }
public function convert(Expr\ArrayDimFetch $node, $returnAsArray = false) { $collected = $this->arrayManipulator->arrayNeedToBeSplit($node); if ($node->var instanceof Expr\StaticPropertyFetch) { if ($node->var->class->parts[0] === 'self') { $node->var = new Expr\PropertyFetch(new Expr\Variable('this'), $node->var->name); $this->logger->logNode("Change StaticProperty into PropertyFetch due to #188", $node); } else { $this->logger->logNode("StaticProperty on array not supported, see #188", $node); } } if ($collected !== false) { return $this->splitArray($collected, $returnAsArray); } else { $result = $this->dispatcher->pVarOrNewExpr($node->var) . '[' . (null !== $node->dim ? $this->dispatcher->p($node->dim) : '') . ']'; if ($returnAsArray === true) { return array('head' => '', 'lastExpr' => $result); } else { return $result; } } }