Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Allow lock to be configured in local filesystems #28124

Merged
merged 1 commit into from Apr 8, 2019

Conversation

Projects
None yet
5 participants
@sebdesign
Copy link
Contributor

sebdesign commented Apr 5, 2019

The Local adapter from Flysystem uses a lock for read/writes by default, but it allows this parameter to be changed in the constructor: https://flysystem.thephpleague.com/docs/adapter/local/

This commit allows developers to change this behavior in the filesystems.php configuration, because currently LOCK_EX is hardcoded:

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
    'lock' => 0,
],

@GrahamCampbell GrahamCampbell changed the title Allow lock to be configured in local filesystems [5.8] Allow lock to be configured in local filesystems Apr 6, 2019

@reindert-vetter

This comment has been minimized.

Copy link
Contributor

reindert-vetter commented Apr 8, 2019

Yes, yes and yes!!! 🎉

I had to make a ServiceProvider to get this done. Here you have my code for a (temporary) fix.

<?php declare(strict_types=1);

namespace App\Providers;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Adapter\Local as LocalAdapter;
use League\Flysystem\Filesystem;

class LocalStorageServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Storage::extend('local', function ($app, $config) {
            $permissions = $config['permissions'] ?? [];

            $links = ($config['links'] ?? null) === 'skip'
                ? LocalAdapter::SKIP_LINKS
                : LocalAdapter::DISALLOW_LINKS;

            $adapter = new LocalAdapter($config['root'], 0, $links, $permissions);
            return new FilesystemAdapter($this->createFlysystem($adapter, $config));
        });
    }

    public function register()
    {
        //
    }

    protected function createFlysystem(\League\Flysystem\AdapterInterface $adapter, array $config)
    {
        $config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);

        return new Filesystem($adapter, count($config) > 0 ? $config : null);
    }
}

Add App\Providers\LocalStorageServiceProvider::class, to 'providers' => [] in config/app.php

@taylorotwell taylorotwell merged commit c05b718 into laravel:5.8 Apr 8, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.