/**
  * @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 Node[]  $stmts
  * @param unknown $fileName
  *
  * @return string
  */
 public function collect(array $stmts, $fileName)
 {
     $namespace = null;
     $class = null;
     foreach ($this->nodeFetcher->foreachNodes($stmts) as $nodeData) {
         $node = $nodeData['node'];
         if ($node instanceof Expr\Include_) {
             throw new \Exception('Include not supported in ' . $fileName . ' on line ' . $node->getLine());
         } elseif ($node instanceof Stmt\Goto_) {
             throw new \Exception('Goto not supported in ' . $fileName . ' on line ' . $node->getLine());
         } elseif ($node instanceof Stmt\InlineHTML) {
             throw new \Exception('InlineHTML not supported in ' . $fileName . ' on line ' . $node->getLine());
         } elseif ($node instanceof Stmt\HaltCompiler) {
             throw new \Exception('HaltCompiler not supported in ' . $fileName . ' on line ' . $node->getLine());
         } elseif ($node instanceof MagicConst\Trait_) {
             throw new \Exception('MagicConst\\Trait_ not supported in ' . $fileName . ' on line ' . $node->getLine());
         } elseif ($node instanceof Stmt\Namespace_) {
             $namespace = implode('\\', $node->name->parts);
         } elseif ($node instanceof Stmt\Interface_ || $node instanceof Stmt\Class_) {
             if ($class !== null) {
                 throw new \Exception('Multiple class find in ' . $fileName);
             }
             $class = $namespace . '\\' . $this->reservedWordReplacer->replace($node->name);
         }
     }
     if ($namespace === null) {
         throw new \Exception('Namespace not found in ' . $fileName);
     }
     if ($class === null) {
         throw new \Exception('No class found in ' . $fileName);
     }
     $this->collected[$class] = $stmts;
     return $class;
 }
 public function convert($node)
 {
     if ($node instanceof Expr) {
         return '{' . $this->dispatcher->p($node) . '}';
     } else {
         return $this->reservedWordReplacer->replace($node);
     }
 }
 /**
  * @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) . ';';
 }
예제 #5
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) . ';';
 }
예제 #6
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() : '') . '}';
 }
 public function convert(Stmt\Interface_ $node)
 {
     $node->name = $this->reservedWordReplacer->replace($node->name);
     $extendsStmt = '';
     if (!empty($node->extends)) {
         $extendsStmt = ' extends ';
         $extends = array();
         foreach ($node->extends as $extend) {
             $extends[] = $this->classManipulator->findRightClass($extend, $this->dispatcher->getMetadata());
         }
         $extendsStmt .= implode(', ', $extends);
     }
     return 'interface ' . $node->name . $extendsStmt . "\n" . '{' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}';
 }
 /**
  * @param Node\Name     $node
  * @param ClassMetadata $metadata
  * @param array         $classCollected
  *
  * @return string
  */
 public function findRightClass(Node\Name $node, ClassMetadata $metadata, array $classCollected = array())
 {
     $class = implode('\\', $node->parts);
     $lastPartsClass = array_map(function ($value) {
         return substr(strrchr($value, '\\'), 1);
     }, $classCollected);
     $class = $this->reservedWordReplacer->replace($class);
     if (in_array($class, $classCollected)) {
         return '\\' . $class;
     } elseif (array_key_exists($class, $metadata->getClassesAlias())) {
         $alias = $metadata->getClassesAlias();
         return '\\' . $alias[$class];
     } elseif (false !== ($key = array_search($class, $lastPartsClass))) {
         return '\\' . $classCollected[$key];
     } elseif (false !== ($key = array_search($metadata->getNamespace() . '\\' . $class, $classCollected))) {
         return '\\' . $classCollected[$key];
     } else {
         return $class;
     }
 }
예제 #9
0
 /**
  * @param array         $nodes
  * @param ClassMetadata $classMetadata
  *
  * @return ClassMetadata
  */
 public function build(array $nodes, ClassMetadata $classMetadata)
 {
     $class = null;
     foreach ($this->nodeFetcher->foreachNodes($nodes) as $nodeData) {
         $node = $nodeData['node'];
         if ($node instanceof Stmt\UseUse) {
             $classMetadata->addUse($node);
             $classMetadata->addClasses($this->reservedWordReplacer->replace(implode('\\', $node->name->parts)));
             if ($node->name->getLast() !== $node->alias) {
                 $classMetadata->addClassesAlias($node->alias, $this->reservedWordReplacer->replace(implode('\\', $node->name->parts)));
             }
         } elseif ($node instanceof Stmt\Namespace_) {
             $classMetadata->setNamespace(implode('\\', $node->name->parts));
         } elseif ($node instanceof Stmt\Interface_ || $node instanceof Stmt\Class_) {
             if ($class !== null) {
                 throw new \Exception('Multiple class find in ' . $fileName);
             }
             $class = $this->reservedWordReplacer->replace($node->name);
             $classMetadata->setClass($class);
         }
     }
     return $classMetadata;
 }
예제 #10
0
 /**
  * @param string $string
  */
 private function replaceReservedWords($string)
 {
     return $this->reservedWordReplacer->replace($string);
 }
예제 #11
0
 /**
  * @param Name $node
  *
  * @return Ambigous <string, unknown>
  */
 public function convert(Name $node)
 {
     return $this->reservedWordReplacer->replace(implode('\\', $node->parts));
 }
예제 #12
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" . '}';
 }