/**
  * @param null|string $lastMethod
  * @param integer     $number
  */
 public function createClosureClass(Expr\Closure $node, $lastMethod, $number)
 {
     $this->logger->trace(__METHOD__ . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     $name = $this->dispatcher->getMetadata()->getClass() . $lastMethod . "Closure" . $this->N2L($number);
     $this->logger->logNode(sprintf('Closure does not exist in Zephir, class "%s" with __invoke is created', $name), $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     return array('name' => $name, 'code' => $this->createClass($name, $this->dispatcher->getMetadata()->getNamespace(), $node));
 }
Exemple #2
0
 /**
  * Pretty prints a node.
  *
  * @param \PhpParser\Node $node Node to be pretty printed
  *
  * @return string Pretty printed node
  */
 public function p($node)
 {
     if (null === $node) {
         return;
     }
     $this->logger->trace('p' . $node->getType(), $node, $this->getMetadata()->getFullQualifiedNameClass());
     return $this->getClass('p' . $node->getType())->convert($node);
 }
 /**
  * Pretty prints a node.
  *
  * @param \PhpParser\Node $node Node to be pretty printed
  *
  * @return string Pretty printed node
  */
 public function p()
 {
     $args = func_get_args();
     $node = $args[0];
     if (null === $node) {
         return;
     }
     $this->logger->trace('p' . $node->getType(), $node, $this->getMetadata()->getFullQualifiedNameClass());
     $class = $this->getClass('p' . $node->getType());
     return call_user_func_array(array($class, "convert"), $args);
 }
 /**
  * @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;
 }
 /**
  * @param Expr\ArrayDimFetch $node
  */
 private function findComplexArrayDimFetch($node, $collected = array())
 {
     if ($this->isInvalidInArrayDimFetch($node) === true) {
         if ($node->dim instanceof Expr\FuncCall) {
             $this->logger->trace(__METHOD__ . ' ' . __LINE__ . ' Non supported funccall in array', $node, $this->dispatcher->getMetadata()->getClass());
         } else {
             $collected[] = array('expr' => $this->dispatcher->p($node->dim) . ";\n", 'splitTab' => true, 'var' => $this->dispatcher->p($node->dim->var));
         }
     } else {
         if ($node->dim === null) {
             $collected[] = array('expr' => $this->dispatcher->p($node->var), 'splitTab' => false);
         } else {
             $collected[] = array('expr' => $this->dispatcher->p($node->dim), 'splitTab' => false);
         }
     }
     if ($node->var instanceof Expr\ArrayDimFetch) {
         $collected = $this->findComplexArrayDimFetch($node->var, $collected);
     } else {
         $collected[] = $node->var;
     }
     return $collected;
 }