Skip to content

Commit

Permalink
[9.x] Add supportsTemporaryUrl to FilesystemAdapter (#43317)
Browse files Browse the repository at this point in the history
* add supportsTemporaryUrl to FilesystemAdapter

* fix code style
  • Loading branch information
Jasonej authored Jul 20, 2022
1 parent 66bfa61 commit ff0dc5b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,17 @@ protected function getLocalUrl($path)
return $path;
}

/**
* Check if temporary urls are supported.
*
* @return bool
*/
public function supportsTemporaryUrl(): bool
{
return method_exists($this->adapter, 'getTemporaryUrl')
|| $this->temporaryUrlCallback;
}

/**
* Get a temporary URL for the file at the given path.
*
Expand Down
32 changes: 32 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,36 @@ public function testGetAllFiles()

$this->assertSame($filesystemAdapter->files(), ['body.txt', 'existing.txt', 'file.txt', 'file1.txt']);
}

public function testSupportsTemporaryUrl()
{
$localAdapter = new class($this->tempDir) extends LocalFilesystemAdapter
{
public function getTemporaryUrl($path, Carbon $expiration, $options): string
{
return $path.$expiration->toString().implode('', $options);
}
};
$filesystemAdapter = new FilesystemAdapter($this->filesystem, $localAdapter);

$this->assertTrue($filesystemAdapter->supportsTemporaryUrl());
}

public function testSupportsTemporaryUrlWithCustomCallback()
{
$filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter);

$filesystemAdapter->buildTemporaryUrlsUsing(function ($path, Carbon $expiration, $options) {
return $path.$expiration->toString().implode('', $options);
});

$this->assertTrue($filesystemAdapter->supportsTemporaryUrl());
}

public function testSupportsTemporaryUrlForAdapterWithoutTemporaryUrlSupport()
{
$filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter);

$this->assertFalse($filesystemAdapter->supportsTemporaryUrl());
}
}

0 comments on commit ff0dc5b

Please sign in to comment.