Skip to content

Commit

Permalink
[10.x] Support inline disk for scoped driver (#47776)
Browse files Browse the repository at this point in the history
* Support inline disk for scoped driver

* added test

* Improve tests and remove warnings in test
  • Loading branch information
alexbowers authored Jul 24, 2023
1 parent 971e822 commit d44b529
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function createScopedDriver(array $config)
}

return $this->build(tap(
$this->getConfig($config['disk']),
is_string($config['disk']) ? $this->getConfig($config['disk']) : $config['disk'],
fn (&$parent) => $parent['prefix'] = $config['prefix']
));
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Filesystem/FilesystemManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,29 @@ public function testCanBuildScopedDisks()
rmdir(__DIR__.'/../../to-be-scoped');
}
}

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

$scoped = $filesystem->build([
'driver' => 'scoped',
'disk' => [
'driver' => 'local',
'root' => 'to-be-scoped',
],
'prefix' => 'path-prefix',
]);

$scoped->put('dirname/filename.txt', 'file content');
$this->assertTrue(is_dir(__DIR__ . '/../../to-be-scoped/path-prefix'));
$this->assertEquals(file_get_contents(__DIR__.'/../../to-be-scoped/path-prefix/dirname/filename.txt'), 'file content');
} finally {
unlink(__DIR__.'/../../to-be-scoped/path-prefix/dirname/filename.txt');
rmdir(__DIR__.'/../../to-be-scoped/path-prefix/dirname');
rmdir(__DIR__.'/../../to-be-scoped/path-prefix');
rmdir(__DIR__.'/../../to-be-scoped');
}
}
}

0 comments on commit d44b529

Please sign in to comment.