Skip to content

Conversation

@daniser
Copy link
Contributor

@daniser daniser commented Sep 24, 2025

This PR fixes discrepancy between Flysystem adapter passed as a 2nd argument to Laravel adapter, and actual used adapter in case it was decorated by ReadOnlyFilesystemAdapter and/or PathPrefixedAdapter within createFlysystem method.
It was done by passing FlysystemAdapter into createFlysystem by reference.

@taylorotwell
Copy link
Member

Aren't objects passed by reference in PHP by default. 👀

@daniser
Copy link
Contributor Author

daniser commented Sep 24, 2025

Aren't objects passed by reference in PHP by default. 👀

I asked myself this question too. Test results differ nevertheless.
I think in PHP world it is something like C's "pointer to a pointer".

@taylorotwell taylorotwell merged commit f9e75e7 into laravel:12.x Sep 24, 2025
65 checks passed
@macropay-solutions
Copy link

macropay-solutions commented Oct 6, 2025

Aren't objects passed by reference in PHP by default. 👀

I asked myself this question too. Test results differ nevertheless. I think in PHP world it is something like C's "pointer to a pointer".

@daniser This could happen if the $adapter variable is overwritten instead of the object being altered.

And in fact that is exactly what is happening

        if (($config['read-only'] ?? false) === true) {
            $adapter = new ReadOnlyFilesystemAdapter($adapter);
        }

        if (!empty($config['prefix'])) {
            $adapter = new PathPrefixedAdapter($adapter, $config['prefix']);
        }

@SyuTingSong
Copy link

I was troubled by this pass-by-reference adapter last week, because I have some application-level logic that needs to check what type the underlying adapter is.

Some want to retrieve the decorated adapter, while others want to retrieve the underlying adapter before decoration. Directly modifying the adapter is not a good solution.

@daniser \Illuminate\Filesystem\FilesystemAdapter provides a getDriver method that allows you to obtain the instance of \League\Flysystem\Filesystem. I am not sure if this will help as the flysystem refuses to provide a getAdapter method to retrieve the underlying decorated adapter.

@daniser
Copy link
Contributor Author

daniser commented Oct 10, 2025

Some want to retrieve the decorated adapter, while others want to retrieve the underlying adapter before decoration. Directly modifying the adapter is not a good solution.

This is exactly what I wanted (decorated adapter), unfortunately my change was short-sighted and I broke people's setups (sorry).
For now I rolled back to using reflection to retrieve adapter from a driver.

NickSdot pushed a commit to NickSdot/laravel-framework that referenced this pull request Oct 30, 2025
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.

4 participants