示例#1
0
 public function parse(SourceScanner $scanner)
 {
     $ref = $this->reflection;
     $returnType = $ref->getReturnType();
     if (!empty($returnType)) {
         $returnType = $returnType->__toString();
     }
     $file = $scanner->filterFile($ref->getFileName());
     $filePath = $file !== false ? $file['path'] : '';
     $this->name = $ref->getName();
     $this->namespace = $ref->getNamespaceName();
     $this->file = $filePath;
     $this->startLine = $ref->getStartLine();
     $this->endLine = $ref->getEndLine();
     $this->returnType = $returnType;
     if ($ref instanceof ReflectionMethod) {
         $access = ReflectionProperty::IS_PUBLIC;
         if ($ref->isPrivate()) {
             $access = ReflectionProperty::IS_PRIVATE;
         } elseif ($ref->isProtected()) {
             $access = ReflectionProperty::IS_PROTECTED;
         }
         $this->access = $access;
         $this->class = $ref->getDeclaringClass()->getName();
         $this->fullName = $this->class . '::' . $this->name;
         $this->isStatic = $ref->isStatic();
         $this->isFinal = $ref->isFinal();
         $this->isAbstract = $ref->isAbstract();
         $this->isInternal = $ref->isInternal();
         $this->isConstructor = $ref->isConstructor();
         $this->isDestructor = $ref->isDestructor();
         $this->doc = DocCommentParser::autoParse($ref->getDocComment(), $scanner, DocMen::METHOD, $this->class, $this->name);
     } else {
         $this->access = ReflectionProperty::IS_PUBLIC;
         $this->fullName = (empty($this->namespace) ? '' : $this->namespace . '\\') . $this->name;
         $this->isStatic = true;
         $this->isFinal = true;
         $this->isAbstract = false;
         $this->isInternal = $ref->isInternal();
         $this->isConstructor = false;
         $this->isDestructor = false;
         $this->doc = DocCommentParser::autoParse($ref->getDocComment(), $scanner, DocMen::FUNC, null, $this->name);
     }
     $this->pushParams($scanner, $ref);
     if ($ref instanceof ReflectionMethod) {
         $scanner->addIndex(DocMen::METHOD, $this->fullName);
     }
     return $this;
 }
示例#2
0
 protected function onExecute($argv = null)
 {
     $startParse = microtime();
     $this->scanner->start();
     $this->console->println("Parse", count($this->scanner->getFiles()), 'files used', round(diff_milli($startParse), 4), 'ms,', 'total parsed', count($this->scanner->getClasses()), 'classes,', count($this->scanner->getNamespaces()), 'namespaces,', count($this->scanner->getFunctions()), 'functions');
     $startWrite = microtime();
     $this->scanner->export();
     $this->console->println("Write all data", 'used', round(diff_milli($startWrite), 4), 'ms');
 }
示例#3
0
 public function parse(SourceScanner $scanner)
 {
     //		if (!$this->isExists()) {
     //			$scanner->addNotExistsClass($this->class);
     //			return $this;
     //		}
     try {
         // 这里还是有可能会出错的,所以还是要try ... catch
         $ref = $this->getReflection();
     } catch (Throwable $thrown) {
         $scanner->addMissItem(DocMen::CLS, $this->class, $this->inputPath, $thrown->getMessage());
         return $this;
     }
     $file = $scanner->filterFile($ref->getFileName());
     $filePath = $file !== false ? $file['path'] : '';
     // 基础信息解析
     $this->name = $ref->getName();
     $this->shortName = $ref->getShortName();
     $this->namespace = $ref->getNamespaceName();
     $this->parent = $this->getParentClass($ref);
     $this->doc = DocCommentParser::autoParse($ref->getDocComment(), $scanner, $this->scope, $this->name, null);
     $this->file = $filePath;
     $this->startLine = $ref->getStartLine();
     $this->endLine = $ref->getEndLine();
     $this->isAbstract = $ref->isAbstract();
     $this->isFinal = $ref->isFinal();
     $this->isInternal = $ref->isInternal();
     $nsStyle = $scanner->getOption(SourceScanner::OPS_NS_STYLE);
     if ($nsStyle === DocMen::NS_STYLE_OLD_PEAR || $nsStyle === DocMen::NS_STYLE_MIXED && empty($this->namespace)) {
         $split = explode('_', $this->name);
         array_pop($split);
         if (!empty($split)) {
             $this->namespace = implode('\\', $split);
         }
     }
     // 使用的Traits
     $traits = $ref->getTraits();
     foreach ($traits as $trait) {
         $name = $trait->getName();
         $this->traits[$name] = $name;
         $this->traitsCount += 1;
     }
     // 实现的接口
     $impls = $ref->getInterfaces();
     foreach ($impls as $impl) {
         $name = $impl->getName();
         $this->impls[$name] = $name;
         $this->implsCount += 1;
     }
     $this->pushConstants($scanner, $ref);
     $this->pushMethods($scanner, $ref);
     $this->pushProperties($scanner, $ref);
     if (!empty($this->sort)) {
         array_multisort($this->sort, SORT_ASC, $this->packages);
     }
     $scanner->addClass($this);
     return $this;
 }