예제 #1
0
파일: Document.php 프로젝트: dotink/sage
 /**
  * Parses a doc comment (intelligently)
  *
  * Unlike other docblock parsers, we do not require the "short description" to be a single
  * line.  Instead we look for the first line break to split the "description" vs. the
  * details which is every line that follows until the first `@`.
  *
  * @access private
  * @return void
  */
 private function parseDocComment()
 {
     $doc_comment = trim($this->reflection->getDocComment());
     $description = array();
     $details = array();
     $info = array();
     if (!$doc_comment) {
         //
         // These can use the file doc comment instead of their own as we assume
         // there is only one per file.
         //
         $file_compatible_types = [self::TYPE_CLASS, self::TYPE_TRAIT, self::TYPE_INTERFACE];
         if (in_array($this->type, $file_compatible_types)) {
             $doc_comment = $this->reflection->getFileReflection()->getDocComment();
         }
     }
     $lines = explode("\n", $doc_comment);
     foreach ($lines as $i => $line) {
         $line = ltrim($line, "/* \t");
         if (isset($line[0]) && $line[0] == '@') {
             break;
         }
         if (is_array($description)) {
             $description[] = $line;
             if (!isset($lines[$i + 1]) || !ltrim($lines[$i + 1], "/* \t")) {
                 break;
             }
         } else {
             $details[] = $line;
         }
     }
     $description = trim(implode("\n", $description));
     $details = trim(implode("\n", $details));
     for ($x = $i; $x < count($lines); $x++) {
         $parts = preg_split('/[\\s]+/', ltrim($lines[$x], "/@ *\t"), 2);
         $token = $parts[0];
         $value = isset($parts[1]) ? $parts[1] : NULL;
         if ($token) {
             try {
                 $this->parseToken($token, $value);
             } catch (Exception $e) {
                 echo PHP_EOL;
                 echo $e->getMessage();
                 echo PHP_EOL;
                 exit(-1);
             }
         }
     }
     $this->description = $description;
     $this->details = $details;
 }