Пример #1
0
 public function parse()
 {
     if (!isset($this->results)) {
         parent::parse();
         $this->appendFunctionsComments();
         $this->appendClassesComments('classes');
         $this->appendClassesComments('interfaces');
     }
 }
Пример #2
0
 public function parse()
 {
     if (!isset($this->results)) {
         parent::parse();
         $tokens = $this->getTokens();
         $startLine = 0;
         $openClass = false;
         $abstract = false;
         $name = null;
         $impl = array();
         $inClass = 0;
         $inFunction = 0;
         foreach ($tokens as $num => $token) {
             if (!is_array($token)) {
                 $tok = $token;
                 $contents = $token;
             } else {
                 $tok = $token[0];
                 $contents = $token[1];
                 $line = $token[2];
             }
             if ($tok == $this->triggerToken) {
                 if (\is_string($openClass)) {
                     throw new \Exception(sprintf("Parser error: double CLASS (%s:%s).", $this->filePath, $line));
                 }
                 $openClass = "";
                 $startLine = $line;
                 continue;
             } elseif ($tok == \T_ABSTRACT) {
                 $abstract = true;
                 continue;
             }
             if (is_string($openClass) && $contents != '{') {
                 $openClass .= $contents;
             } elseif (is_string($openClass) && $contents == '{') {
                 $openClass = trim($openClass);
                 $className = "";
                 $parentClass = null;
                 $implements = array();
                 $hasImplements = false;
                 $xxx = \explode(' ', $openClass);
                 foreach ($xxx as $x => $item) {
                     if ($x === 0) {
                         $className = $item;
                     } elseif ($item == 'extends') {
                         $parentClass = $xxx[$x + 1];
                     } elseif ($item == 'implements') {
                         $hasImplements = true;
                     }
                 }
                 if ($hasImplements) {
                     $impltmp = trim(substr($openClass, strpos($openClass, ' implements ') + 11));
                     if (strpos($impltmp, ',') !== false) {
                         $x = explode(',', $impltmp);
                         foreach ($x as $implemented) {
                             $impl[] = trim($implemented);
                         }
                     } else {
                         $impl[] = $impltmp;
                     }
                 }
                 $implements = $impl;
                 $name = $className;
                 $openClass = false;
             }
             if ($contents == '}') {
                 if ($inClass == 1 && !empty($name)) {
                     $this->results[$name] = array('name' => $name, 'abstract' => $abstract, 'implements' => $implements, 'parent' => $parentClass, 'startLine' => $startLine, 'endLine' => $line + 1);
                     $this->appendData($name, 'constants');
                     $this->appendData($name, 'attributes');
                     $this->appendData($name, 'methods');
                     $implements = array();
                     $abstract = false;
                     $parentClass = null;
                     $name = null;
                     $openClass = false;
                     $impl = array();
                 }
                 $inClass--;
             } elseif ($contents == '{') {
                 $inClass++;
             }
         }
         unset($this->results[':constants'], $this->results[':methods'], $this->results[':attributes']);
     }
     return $this->results;
 }