/**
  * @param Expr\ClosureUse $node
  *
  * @return string
  */
 public function convert(Expr\ClosureUse $node)
 {
     if ($node->byRef) {
         $this->logger->logNode('Zephir not support reference parameters for now. Stay tuned for https://github.com/phalcon/zephir/issues/203', $node, $this->dispatcher->getMetadata()->getClass());
     }
     return $this->reservedWordReplacer->replace($node->var);
 }
示例#2
0
 /**
  * @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));
 }
示例#3
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 public function convert(Stmt\If_ $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->cond);
     $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond);
     if (empty($node->stmts)) {
         $node->stmts = array(new Stmt\Echo_(array(new Scalar\String("not allowed"))));
         $this->logger->logNode('Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getClass());
     }
     return implode(";\n", $collected['extracted']) . "\n" . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node);
 }
示例#4
0
 /**
  * @param Stmt\Property $node
  *
  * @return string
  */
 public function convert(Stmt\Property $node)
 {
     foreach ($node->props as $key => $prop) {
         $prop->name = $this->reservedWordReplacer->replace($prop->name);
         $node->props[$key] = $prop;
     }
     if ($node->props[0]->default instanceof Expr\Array_ && $node->isStatic() === true) {
         $node->type = $node->type - Stmt\Class_::MODIFIER_STATIC;
         $this->dispatcher->moveToNonStaticVar($node->props[0]->name);
         $this->logger->logNode("Static attribute default array not supported in zephir, (see #188). Changed into non static. ", $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     }
     return $this->dispatcher->pModifiers($node->type) . $this->dispatcher->pCommaSeparated($node->props) . ';';
 }
 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;
         }
     }
 }