Skip to content

Commit

Permalink
Merge pull request #84 from eivydas/path-and-url
Browse files Browse the repository at this point in the history
Pass path and url parameters to Filesystem
  • Loading branch information
basz authored Mar 6, 2024
2 parents 2eee1c5 + 3b57fcd commit b5f65d7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions config/bsb_flysystem.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ return [
'adapter' => 'local_default',
'adapter_options' => null,
'options' => [
'pathNormalizer' => null, // returns PathNormalizer::class
'publicUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\PublicUrlGeneratorInterface::class
'pathNormalizer' => null, // returns \League\Flysystem\PathNormalizer::class
'publicUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\PublicUrlGenerator::class
'temporaryUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\TemporaryUrlGenerator::class
],
],
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/Factory/AbstractAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
/**
* Merges the options given from the ServiceLocator Config object with the create options of the class.
*/
protected function mergeMvcConfig(ContainerInterface $container, string $requestedName = null): void
protected function mergeMvcConfig(ContainerInterface $container, ?string $requestedName = null): void
{
$config = $container->has('config') ? $container->get('config') : [];

if (! isset($config['bsb_flysystem']['adapters'][$requestedName]['options']) ||
! \is_array(($config['bsb_flysystem']['adapters'][$requestedName]['options']))
if (! isset($config['bsb_flysystem']['adapters'][$requestedName]['options'])
|| ! \is_array(($config['bsb_flysystem']['adapters'][$requestedName]['options']))
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/RequirementsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class RequirementsException extends RuntimeException
{
public function __construct(array $requirements, string $for, int $code = 0, \Exception $previous = null)
public function __construct(array $requirements, string $for, int $code = 0, ?\Exception $previous = null)
{
$requirements = array_map(function ($r) {
return sprintf("'%s'", trim($r));
Expand Down
17 changes: 16 additions & 1 deletion src/Filesystem/Factory/FilesystemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public function __invoke(ContainerInterface $container, string $requestedName, ?

$options = $configForRequestedFS['options'] ?? [];

return new Filesystem($adapter, $options);
$pathNormalizer = $options['pathNormalizer'] ?? null;
if (null !== $pathNormalizer) {
$pathNormalizer = $container->get($pathNormalizer);
}

$publicUrlGenerator = $options['publicUrlGenerator'] ?? null;
if (null !== $publicUrlGenerator) {
$publicUrlGenerator = $container->get($publicUrlGenerator);
}

$temporaryUrlGenerator = $options['temporaryUrlGenerator'] ?? null;
if (null !== $temporaryUrlGenerator) {
$temporaryUrlGenerator = $container->get($temporaryUrlGenerator);
}

return new Filesystem($adapter, $options, $pathNormalizer, $publicUrlGenerator, $temporaryUrlGenerator);
}
}
2 changes: 1 addition & 1 deletion src/Service/Factory/FilesystemManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class FilesystemManagerFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): FilesystemManager
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): FilesystemManager
{
$filesystems = ($container->has('config') ? $container->get('config') : [])['bsb_flysystem']['filesystems'] ?? [];

Expand Down
4 changes: 2 additions & 2 deletions test/Assets/bsb_flysystem.local.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
'adapter' => 'local_default',
'adapter_options' => null,
'options' => [
'pathNormalizer' => null, // returns PathNormalizer::class
'publicUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\PublicUrlGeneratorInterface::class
'pathNormalizer' => null, // returns \League\Flysystem\PathNormalizer::class
'publicUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\PublicUrlGenerator::class
'temporaryUrlGenerator' => null, // returns \League\Flysystem\UrlGeneration\TemporaryUrlGenerator::class
],
],
Expand Down

0 comments on commit b5f65d7

Please sign in to comment.