Пример #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
 /**
  * Internal method to fetch all migration filenames.
  */
 private function getFiles()
 {
     foreach ($this->files->getFiles($this->config['directory'], '*.php') as $filename) {
         $reflection = $this->tokenizer->fileReflection($filename);
         $definition = explode('_', basename($filename));
         (yield ['filename' => $filename, 'class' => $reflection->getClasses()[0], 'created' => \DateTime::createFromFormat(self::TIMESTAMP_FORMAT, $definition[0]), 'name' => str_replace('.php', '', join('_', array_slice($definition, 2)))]);
     }
 }
Пример #3
0
 /**
  * Available file reflections. Generator.
  *
  *
  * @generate ReflectionFile[]
  */
 protected function availableReflections()
 {
     /**
      * @var SplFileInfo $file
      */
     foreach ($this->finder->getIterator() as $file) {
         $reflection = $this->tokenizer->fileReflection((string) $file);
         //We are not analyzing files which has includes, it's not safe to require such reflections
         if ($reflection->hasIncludes()) {
             $this->logger()->warning("File '{filename}' has includes and will be excluded from analysis.", ['filename' => (string) $file]);
             continue;
         }
         /**
          * @var ReflectionFile $reflection
          */
         (yield $reflection);
     }
 }
Пример #4
0
 /**
  * Locate every available Symfony command using Tokenizer.
  *
  * @return array
  */
 public function findCommands()
 {
     $this->commands = [];
     foreach ($this->tokenizer->getClasses(SymfonyCommand::class, null, 'Command') as $class) {
         if ($class['abstract']) {
             continue;
         }
         $this->commands[] = $class['name'];
     }
     $this->memory->saveData('commands', $this->commands);
     return $this->commands;
 }
Пример #5
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);
 }
Пример #6
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;
 }
Пример #7
0
 /**
  * Locate every available Record class.
  *
  * @param TokenizerInterface $tokenizer
  * @throws SchemaException
  */
 protected function locateRecords(TokenizerInterface $tokenizer)
 {
     //Table names associated with records
     $sources = [];
     foreach ($tokenizer->getClasses(RecordEntity::class) as $class => $definition) {
         if ($class == RecordEntity::class || $class == Record::class) {
             continue;
         }
         $this->records[$class] = $record = new RecordSchema($this, $class);
         if (!$record->isAbstract()) {
             //See comment near exception
             continue;
         }
         //Record associated tableID (includes resolved database name)
         $sourceID = $record->getSourceID();
         if (isset($sources[$sourceID])) {
             //We are not allowing multiple records talk to same database, unless they one of them
             //is abstract
             throw new SchemaException("Record '{$record}' associated with " . "same source table '{$sourceID}' as '{$sources[$sourceID]}'.");
         }
         $sources[$sourceID] = $record;
     }
 }
Пример #8
0
 /**
  * Locate every available Document class.
  *
  * @param TokenizerInterface $tokenizer
  */
 protected function locateDocuments(TokenizerInterface $tokenizer)
 {
     foreach ($tokenizer->getClasses(DocumentEntity::class) as $class => $definition) {
         if ($class == DocumentEntity::class || $class == Document::class) {
             continue;
         }
         $this->documents[$class] = new DocumentSchema($this, $class);
     }
 }