예제 #1
0
 private function loadCache()
 {
     try {
         if (!empty($this->cachePath) && $this->io->exists($this->cachePath)) {
             $data = json_decode($this->io->read($this->cachePath), true);
             if (!is_array($data) || !isset($data['files']) || !isset($data['data'])) {
                 throw new IOException("Corrupted indexer cache");
             }
             $this->data = $data;
         }
     } catch (IOException $e) {
         $this->logger->notice("Can't load indexed data: " . $e->getMessage(), ['exception' => $e]);
     }
 }
 public function getProjectRootDir($path)
 {
     $rootDir = null;
     foreach (static::PROJECT_FILES as $projectFile) {
         $oldPath = $path;
         $curPath = dirname($path);
         while ($oldPath !== $curPath) {
             $projectFilePath = $curPath . '/' . $projectFile;
             if ($this->io->exists($projectFilePath)) {
                 $rootDir = $curPath;
             }
             $oldPath = $curPath;
             $curPath = dirname($curPath);
         }
         if ($rootDir !== null) {
             return $rootDir;
         }
     }
     return null;
 }
예제 #3
0
 /**
  * Find a composer (root) package given file belongs to.
  *
  * @param string          $phpFilePath
  * @param FileIOInterface $io
  *
  * @return ComposerPackage|null
  */
 public static function get($phpFilePath, FileIOInterface $io)
 {
     $baseDir = null;
     $oldPath = $phpFilePath;
     $path = dirname($oldPath);
     while ($oldPath !== $path) {
         $config = $path . '/' . self::COMPOSER_CONFIG;
         if ($io->exists($config)) {
             $baseDir = $path;
         }
         $oldPath = $path;
         $path = dirname($path);
     }
     if ($baseDir === null) {
         return null;
     }
     if (array_key_exists($baseDir, self::$packages)) {
         return self::$packages[$baseDir];
     }
     return self::$packages[$baseDir] = new static($baseDir);
 }