예제 #1
0
 /**
  * Locate and return list of every method or function call in specified file. Only static class
  * methods will be indexed.
  *
  * @return ReflectionCall[]
  */
 public function getCalls()
 {
     if (empty($this->calls)) {
         $this->locateCalls($this->tokens ?: $this->tokenizer->fetchTokens($this->filename));
     }
     return $this->calls;
 }
예제 #2
0
 /**
  * Colorize PHP source using given styles. In addition can automatically return only specified
  * line with few lines around it.
  *
  * Example: target = 10, return = 10
  * Output: lines from 5 - 15 will be displayed, line 10 will be highlighted.
  *
  * @param string $filename
  * @param int    $target Target line to highlight.
  * @param int    $return Total lines to be returned.
  * @return string
  */
 public function highlight($filename, $target = null, $return = 10)
 {
     $result = "";
     foreach ($this->tokenizer->fetchTokens($filename) as $position => $token) {
         $source = htmlentities($token[TokenizerInterface::CODE]);
         foreach ($this->options['styles'] as $style => $tokens) {
             if (!in_array($token[TokenizerInterface::TYPE], $tokens)) {
                 continue;
             }
             if (strpos($source, "\n") === false) {
                 $source = \Spiral\interpolate($this->options['templates']['token'], ['style' => $style, 'token' => $token[TokenizerInterface::CODE]]);
                 break;
             }
             $lines = [];
             foreach (explode("\n", $source) as $line) {
                 $lines[] = \Spiral\interpolate($this->options['templates']['token'], ['style' => $style, 'token' => $line]);
             }
             $source = join("\n", $lines);
         }
         $result .= $source;
     }
     return $this->lines($result, (int) $target, $return);
 }
예제 #3
0
 /**
  * Load configuration doc headers from existed file.
  *
  * @param string $filename
  * @return $this
  */
 protected function readHeader($filename)
 {
     $this->header = '';
     foreach ($this->tokenizer->fetchTokens($filename) as $token) {
         if (isset($token[0]) && $token[0] == T_RETURN) {
             //End of header
             break;
         }
         $this->header .= $token[TokenizerInterface::CODE];
     }
     return $this;
 }