Esempio n. 1
0
 /**
  * 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.
  *
  * @param FileInterface|string $path
  *
  * @throws FileNotFoundException If file was not found.
  *
  * @return 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);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getVersion($path)
 {
     $file = $this->filesystem->getFile($path);
     try {
         return substr(md5($this->baseSalt . $file->getFullPath() . $file->getTimestamp()), 0, 10);
     } catch (IOException $e) {
         return '';
     }
 }
Esempio n. 3
0
 public function testContainsAndInitializeFromSession()
 {
     $this->users->expects($this->never())->method('getCurrentUser');
     $this->assertTrue($this->stack->contains('a.jpg'), 'Stack::contains should match file paths without mount points');
     $this->assertTrue($this->stack->contains('g.txt'), 'Stack::contains should match file paths without mount points');
     $this->assertTrue($this->stack->contains('files://a.jpg'), 'Stack::contains should match file paths with mount points');
     $this->assertTrue($this->stack->contains('files://c.txt'), 'Stack should initialize file paths with mount points');
     $file = $this->filesystem->getFile('files://a.jpg');
     $this->assertTrue($this->stack->contains($file), 'Stack::contains should match file objects');
     $this->assertTrue($this->stack->contains('files/a.jpg'), 'Stack should strip "files/" from start of path');
     $this->assertFalse($this->stack->contains('does_not_exist.txt'), 'Stack should not contain nonexistent files');
     $this->assertFalse($this->stack->contains('h.txt'), 'Stack should trim list to max items on initialize');
 }