diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index a162488d4236..7511936b7986 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -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. * diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index be7bcd6cb7b5..b02fde8236f8 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -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()); + } }