Example #1
0
 public function parseFile($file)
 {
     if (empty(self::$parsed[$file])) {
         $parser = new File($file);
         self::$parsed[$file] = $parser->getAnnotations();
     }
     return self::$parsed[$file];
 }
Example #2
0
 public function readDirectory($path)
 {
     $filter = $this->filter;
     $modtime = filemtime($path);
     $cached = Cache::get('dir://' . $path, $has, $this->localCache);
     if ($has && $cached['modtime'] >= $modtime) {
         if ($this->cacheTs < $modtime) {
             $this->cacheTs = $modtime;
         }
         foreach ($cached['cache'] as $file => $cache) {
             $this->files[] = $file;
             $this->addFile(File::fromCache($file, $cache, $this->localCache));
         }
         return;
     }
     $this->cached = false;
     $iter = new RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);
     $cache = array();
     foreach (new RecursiveIteratorIterator($iter) as $file) {
         if (!$file->isfile() || $filter && !$filter($file)) {
             continue;
         }
         $rpath = realpath($file->getPathname());
         $this->files[] = $rpath;
         $file = $this->addFile(new File($file->getPathname(), $this->localCache));
         $cache[$rpath] = $file->ToCache();
     }
     Cache::set('dir://' . $path, compact('modtime', 'cache'), $this->localCache);
     return $this->annotations;
 }
Example #3
0
 public function generate()
 {
     $output = $this->getOutput();
     if (empty($output)) {
         throw new \RuntimeException("You need to set an output file");
     }
     $cache = new Watch($output . '.cache');
     $dirs = $this->dirs;
     foreach ($this->files as $file) {
         $dirs[] = dirname($file);
     }
     $cache->watchFiles($this->files);
     $cache->watchDirs($dirs);
     if (!$cache->hasChanged()) {
         return;
     }
     $annotations = new Annotations();
     $isCached = $output && file_exists($output);
     $files = array();
     $dirs = array();
     foreach (array_unique($this->files) as $file) {
         $ann = new FileParser($file);
         $ann->getAnnotations($annotations);
         $files[] = $file;
         $dirs[] = dirname($file);
     }
     foreach (array_unique($this->dirs) as $dir) {
         $ann = new DirParser($dir);
         $ann->getAnnotations($annotations);
         $dirs[] = $dir;
         $files = array_merge($files, $ann->getFiles());
     }
     foreach ($files as $file) {
         $dirs[] = dirname($file);
     }
     $cache->watchFiles($files)->watchDirs($dirs);
     $cache->watch();
     foreach ($files as $file) {
         $dirs[] = dirname($file);
     }
     $compiler = new Compiler($this, $annotations);
     if (!empty($output)) {
         file_put_contents($output, $compiler->getOutput());
     }
     return $compiler->getOutput();
 }
Example #4
0
File: Dir.php Project: crodas/notoj
 protected function addFile(File $file)
 {
     $this->annotations->merge($file->getAnnotations());
     $this->objs = array_merge($this->objs, $file->objs);
     return $file;
 }