Beispiel #1
0
 /**
  * @param $query string
  * @return string[]|null
  */
 private function guessContext($query)
 {
     $context = [];
     // first clause between `...` is probably the name of the table
     $table_name = mParse($query, BQ, BQ);
     if ($table_name) {
         $class_name = Dao::classNameOf($table_name);
         if ($class_name) {
             $context[] = $class_name;
         }
     }
     // every JOIN `...` may be the name of a table
     $joins = explode('JOIN ' . BQ, $query);
     array_shift($joins);
     foreach ($joins as $join) {
         $table_name = lParse($join, BQ);
         if ($table_name) {
             $class_name = Dao::classNameOf($table_name);
             if ($class_name) {
                 $context[] = $class_name;
             }
         }
     }
     return $context ? $context : null;
 }
Beispiel #2
0
 /**
  * Scans all PHP files into the project (excluding vendor) and store their paths to the cache
  */
 public function update($last_time = 0)
 {
     $files = Application::current()->include_path->getSourceFiles();
     $this->full_class_names = [];
     $this->paths = [];
     foreach ($files as $file_path) {
         if (substr($file_path, -4) == '.php') {
             $buffer = file_get_contents($file_path);
             $short_class = trim(mParse($buffer, LF . 'class' . SP, LF)) ?: trim(mParse($buffer, LF . 'final class' . SP, LF)) ?: trim(mParse($buffer, LF . 'abstract class' . SP, LF)) ?: trim(mParse($buffer, LF . 'final abstract class' . SP, LF));
             if ($short_class) {
                 $type = 'class';
             } else {
                 $short_class = trim(mParse($buffer, LF . 'interface' . SP, LF));
                 if ($short_class) {
                     $type = 'interface';
                 } else {
                     $short_class = trim(mParse($buffer, LF . 'trait' . SP, LF));
                     if ($short_class) {
                         $type = 'trait';
                     }
                 }
             }
             if ($short_class && isset($type)) {
                 if ($i = strpos($short_class, SP)) {
                     $short_class = substr($short_class, 0, $i);
                 }
                 $namespace = trim(mParse($buffer, LF . 'namespace' . SP, LF));
                 if (substr($namespace, -1) == ';') {
                     $namespace = trim(substr($namespace, 0, -1));
                 }
                 $full_class = $namespace . BS . $short_class;
                 if ($type == 'class' && !isset($this->full_class_names[$short_class])) {
                     $this->full_class_names[$short_class] = $full_class;
                 }
                 if (!isset($this->paths[$full_class])) {
                     $this->paths[$full_class] = $file_path;
                 }
             }
         }
     }
     if (!is_dir($this->cache_path)) {
         mkdir($this->cache_path);
     }
     script_put_contents($this->cache_path . SL . 'autoload.php', '<?php' . LF . LF . '$this->full_class_names = ' . var_export($this->full_class_names, true) . ';' . LF . LF . '$this->paths = ' . var_export($this->paths, true) . ';' . LF);
 }