Skip to content

Commit

Permalink
Merge branch 'on-demand-filesystem' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 18, 2021
2 parents 77f45b7 + c21fc12 commit ed5da1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public function cloud()
return $this->disks[$name] = $this->get($name);
}

/**
* Build an on-demand disk.
*
* @param string|array $config
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
public function build($config)
{
return $this->resolve('ondemand', is_array($config) ? $config : [
'driver' => 'local',
'root' => $config
]);
}

/**
* Attempt to get the disk from the local cache.
*
Expand All @@ -109,9 +123,9 @@ protected function get($name)
*
* @throws \InvalidArgumentException
*/
protected function resolve($name)
protected function resolve($name, $config = null)
{
$config = $this->getConfig($name);
$config = $config ?? $this->getConfig($name);

if (empty($config['driver'])) {
throw new InvalidArgumentException("Disk [{$name}] does not have a configured driver.");
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertExists(string|array $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertMissing(string|array $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem cloud()
* @method static \Illuminate\Contracts\Filesystem\Filesystem build(string|array $root)
* @method static \Illuminate\Contracts\Filesystem\Filesystem disk(string|null $name = null)
* @method static \Illuminate\Filesystem\FilesystemManager extend(string $driver, \Closure $callback)
* @method static \Symfony\Component\HttpFoundation\StreamedResponse download(string $path, string|null $name = null, array|null $headers = [])
Expand Down
15 changes: 15 additions & 0 deletions tests/Filesystem/FilesystemManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Tests\Filesystem;

use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Foundation\Application;
use InvalidArgumentException;
Expand All @@ -20,4 +21,18 @@ public function testExceptionThrownOnUnsupportedDriver()

$filesystem->disk('local');
}

public function testCanBuildOnDemandDisk()
{
$filesystem = new FilesystemManager(new Application);

$this->assertInstanceOf(Filesystem::class, $filesystem->build('my-custom-path'));

$this->assertInstanceOf(Filesystem::class, $filesystem->build([
'driver' => 'local',
'root' => 'my-custom-path',
'url' => 'my-custom-url',
'visibility' => 'public',
]));
}
}

0 comments on commit ed5da1a

Please sign in to comment.