コード例 #1
0
 /**
  * @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;
 }
コード例 #3
0
 public function convert($node)
 {
     if ($node instanceof Expr) {
         return '{' . $this->dispatcher->p($node) . '}';
     } else {
         return $this->reservedWordReplacer->replace($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;
     }
     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() : '') . '}';
 }
コード例 #7
0
 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" . '}';
 }
コード例 #8
0
 /**
  * @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
ファイル: TypeFinder.php プロジェクト: noikiy/php-to-zephir
 /**
  * @param string $string
  */
 private function replaceReservedWords($string)
 {
     return $this->reservedWordReplacer->replace($string);
 }
コード例 #11
0
ファイル: NamePrinter.php プロジェクト: noikiy/php-to-zephir
 /**
  * @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" . '}';
 }