Skip to content

[12.x] Add streamableUri function to FilesystemAdapter class #55375

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

Conversation

mateuszanella
Copy link

Description

This PR adds two new methods to the Illuminate/Filesystem/FilesystemAdapter.php class.

Theese methods are intended to offer a way for developers to set a default PHP stream wrapper prefix in the filesystem configuration, and get a proper URI to directly access a file through PHP default file manipulation functions (fopen, file_get_contents, etc).

The reasoning behind this PR is to add a convenient way to integrate Laravel filesystems to external file manipulation libraries that work exclusively with resources.

Usage

A user may define a default stream wrapper in the filesystems.php config file:

's3' => [
    'driver' => 's3',
    'stream_wrapper' => 's3',
    ...
],

Then, through the Storage facade, the user may check if a given filesystem can provide a streamable URI:

Storage::disk('s3')->providesStreamableUris(); // true

For getting the actual path, the user can use the following function:

Storage::disk('s3')->streamableUri('path/to/file'); // "s3://path/to/file"

Conclusion

I am open to feedback on this. The feature has been relevant to my workspace, and I believe it could be a good addition to the framework.

@mateuszanella mateuszanella marked this pull request as draft April 12, 2025 00:37
@mateuszanella
Copy link
Author

Also, another thing that could be added is an override to both functions on the LocalFilesystemAdapter class to just return the path if no wrapper is provided in the configuration file, since every path in a local filesystem should be streamable. Also open to suggestions on this.

@mateuszanella mateuszanella marked this pull request as ready for review April 14, 2025 11:16
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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.

2 participants