/**
  * @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;
     }
     return $this->dispatcher->pModifiers($node->type) . $this->dispatcher->pCommaSeparated($node->props) . ';';
 }
Exemplo n.º 2
0
 /**
  * @param Expr\FuncCall $node
  *
  * @return string
  */
 public function convert(Expr\FuncCall $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->args);
     $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args);
     if ($node->name instanceof Expr\Variable) {
         $instanciation = '{' . $this->dispatcher->p($node->name) . '}';
     } else {
         $instanciation = $this->dispatcher->p($node->name);
     }
     return (!empty($collected['extracted']) ? implode(";\n", $collected['extracted']) . "\n" : '') . $instanciation . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
 }
Exemplo n.º 3
0
 /**
  * @param Expr\Array_ $node
  * @param bool        $returnAsArray
  *
  * @return string|array
  */
 public function convert(Expr\Array_ $node, $returnAsArray = false)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->items);
     $node->items = $this->assignManipulator->transformAssignInConditionTest($node->items);
     $collected['expr'] = '[' . $this->dispatcher->pCommaSeparated($node->items) . ']';
     if ($returnAsArray === true) {
         return $collected;
     } else {
         return (!empty($collected['extracted']) ? implode(";\n", $collected['extracted']) . "\n" : '') . $collected['expr'];
     }
 }
 /**
  * @param Expr\FuncCall $node
  *
  * @return string
  */
 public function convert(Expr\FuncCall $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->args);
     $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args);
     if ($node->name instanceof Expr\Variable) {
         $instanciation = '{' . $this->dispatcher->p($node->name) . '}';
     } else {
         $instanciation = $this->dispatcher->p($node->name);
     }
     return $collected->getCollected() . $instanciation . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
 }
Exemplo n.º 5
0
 /**
  * @param Expr\Array_ $node
  * @param bool        $returnAsArray
  *
  * @return string|array
  */
 public function convert(Expr\Array_ $node, $returnAsArray = false)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->items);
     $node->items = $this->assignManipulator->transformAssignInConditionTest($node->items);
     $collected->setExpr('[' . $this->dispatcher->pCommaSeparated($node->items) . ']');
     if ($returnAsArray === true) {
         return $collected;
     } else {
         return $collected->getCollected() . $collected->getExpr();
     }
 }
Exemplo n.º 6
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) . ';';
 }
Exemplo n.º 7
0
 /**
  * @param string $name
  * @param string $namespace
  */
 private function createClass($name, $namespace, Expr\Closure $node)
 {
     $class = "namespace {$namespace};\n\nclass {$name}\n{\n";
     foreach ($node->uses as $use) {
         $class .= "    private " . $use->var . ";\n";
     }
     $class .= "\n    public function __construct(" . (!empty($node->uses) ? '' . $this->dispatcher->pCommaSeparated($node->uses) : '') . ")\n    {\n        ";
     foreach ($node->uses as $use) {
         $class .= "        let this->" . $use->var . " = " . $use->var . ";\n";
     }
     $class .= "\n    }\n\n    public function __invoke(" . $this->dispatcher->pCommaSeparated($node->params) . ")\n    {" . $this->dispatcher->pStmts($this->convertUseToMemberAttribute($node->stmts, $node->uses)) . "\n    }\n}\n    ";
     return $class;
 }
Exemplo n.º 8
0
 public function convert(Stmt\Class_ $node)
 {
     $this->classManipulator->registerClassImplements($node);
     $node->name = $this->reservedWordReplacer->replace($node->name);
     $addArrayPlusMethod = false;
     foreach ($this->nodeFetcher->foreachNodes($node->stmts) as $stmt) {
         if ($stmt['node'] instanceof AssignOp\Plus && $stmt['node']->expr instanceof Array_) {
             $addArrayPlusMethod = true;
             break;
         }
     }
     return $this->dispatcher->pModifiers($node->type) . 'class ' . $node->name . (null !== $node->extends ? ' extends ' . $this->dispatcher->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->dispatcher->pCommaSeparated($node->implements) : '') . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . ($addArrayPlusMethod === true ? $this->printArrayPlusMethod() : '') . '}';
 }
 /**
  * @param Expr\MethodCall $node
  *
  * @return string
  */
 public function convert(Expr\MethodCall $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->args);
     $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args);
     return $collected->getCollected() . $this->dispatcher->pVarOrNewExpr($node->var) . '->' . $this->dispatcher->pObjectProperty($node->name) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
 }
Exemplo n.º 10
0
 /**
  * @param Expr\MethodCall $node
  *
  * @return string
  */
 public function convert(Expr\MethodCall $node)
 {
     $collected = $this->assignManipulator->collectAssignInCondition($node->args);
     $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args);
     return (!empty($collected['extracted']) ? implode("\n", $collected['extracted']) . "\n" : '') . $this->dispatcher->pVarOrNewExpr($node->var) . '->' . $this->dispatcher->pObjectProperty($node->name) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
 }
Exemplo n.º 11
0
 public function convert(Stmt\Class_ $node)
 {
     $node->name = $this->reservedWordReplacer->replace($node->name);
     return $this->dispatcher->pModifiers($node->type) . 'class ' . $node->name . (null !== $node->extends ? ' extends ' . $this->dispatcher->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->dispatcher->pCommaSeparated($node->implements) : '') . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}';
 }