Bolt\Filesystem\Matcher::getFile PHP Method

getFile() public method

Gets the file object for the path given. Paths with the mount point included are preferred, but are not required for BC. If the mount point is not included a list of filesystems are checked and chosen if the file exists in that filesystem.
public getFile ( Bolt\Filesystem\Handler\FileInterface | string $path ) : Bolt\Filesystem\Handler\FileInterface
$path Bolt\Filesystem\Handler\FileInterface | string
return Bolt\Filesystem\Handler\FileInterface
    public function getFile($path)
    {
        if ($path instanceof FileInterface) {
            return $path;
        }
        if (!$this->filesystem instanceof AggregateFilesystemInterface || $this->containsMountPoint($path)) {
            $file = $this->filesystem->getFile($path);
            if (!$file->exists()) {
                throw new FileNotFoundException($path);
            }
            return $file;
        }
        // Trim "files/" from front of path for BC.
        if (strpos($path, 'files/') === 0) {
            $path = substr($path, 6);
        }
        foreach ($this->filesystemsToCheck as $mountPoint) {
            if (!$this->filesystem->hasFilesystem($mountPoint)) {
                continue;
            }
            $file = $this->filesystem->getFile("{$mountPoint}://{$path}");
            if ($file->exists()) {
                return $file;
            }
        }
        throw new FileNotFoundException($path);
    }

Usage Example

Ejemplo n.º 1
0
Archivo: Stack.php Proyecto: bolt/bolt
 /**
  * Converts a list of paths to file objects.
  *
  * @param string[] $paths
  *
  * @return FileInterface[]
  */
 private function hydrateList($paths)
 {
     $files = array_filter(array_map(function ($path) {
         try {
             return $this->matcher->getFile($path);
         } catch (FileNotFoundException $e) {
             // Guess it doesn't exist anymore or we can't find it, remove from list.
             return null;
         }
     }, $paths));
     $files = array_slice($files, 0, self::MAX_ITEMS);
     return $files;
 }