Skip to content

Conversation

daniser
Copy link
Contributor

@daniser daniser commented Sep 25, 2025

Laravel have many managers, some of them bind themselves to custom driver closures, some others don't.
This PR fixes this injustice. Also, tests have been added for all managers to enforce this behavior.
Related: #13436.

Why?

When writing custom driver, you might probably need to call protected manager methods during its registration.
For example, in case of FilesystemManager, it may be createFlysystem method.

Why not 12.x?

It is a breaking change. You will still have app at your disposal, because app exists in both ServiceProvider and all managers.
But you'll lose ability to directly call ServiceProvider methods.

Upgrade steps

If you do call service provider methods inside extend callback, you'll need to move those calls outside and use use ($...) to access parent scope.

Examples

Before

$this->callAfterResolving(
    FilesystemManager::class,
    function (FilesystemManager $manager) {
        $callback = function (Application $app, array $config) {
            $adapter = new ReplicateAdapter(/* ... */);

            return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
        };

        $manager->extend('replicate', $callback->bindTo($manager, $manager));
    }
);

After

$this->callAfterResolving(
    FilesystemManager::class,
    function (FilesystemManager $manager) {
        $manager->extend('replicate', function (Application $app, array $config) {
            $adapter = new ReplicateAdapter(/* ... */);

            return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
        });
    }
);

or just

Storage::extend('replicate', function (Application $app, array $config) {
    $adapter = new ReplicateAdapter(/* ... */);

    return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant