-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Filesystem] Add the readFile()
method
#54173
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5d32ad6
to
6396dd1
Compare
andrew-demb
reviewed
Mar 6, 2024
src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php
Show resolved
Hide resolved
jprivet-dev
reviewed
Mar 7, 2024
0019010
to
1a13e3e
Compare
OskarStark
approved these changes
Mar 15, 2024
src/Symfony/Component/AssetMapper/CompiledAssetMapperConfigReader.php
Outdated
Show resolved
Hide resolved
1a13e3e
to
632ff62
Compare
fabpot
approved these changes
Mar 17, 2024
Thank you @derrabus. |
Merged
fabpot
added a commit
that referenced
this pull request
Aug 19, 2024
This PR was squashed before being merged into the 7.2 branch. Discussion ---------- [AssetMapper] Leverage Filesystem | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #... | License | MIT Continue the work started in #54173 & #54724 to replace php file functions (`mkdir`, `file_get_contents` , `file_put_contents`, `unlink`) by Filesystem methods Commits ------- a1bb5a2 [AssetMapper] Leverage Filesystem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our
Filesystem
class is a tool for leveraging PHP's native filesystem functions is a sane way.For example, it provides a method
dumpFile()
which attempts to write the contents of a string to a file and throws if that attempt fails. However, it lacks a method to read the content of a file. The native function for this task,file_get_contents()
comes with a couple of traps that I don't want to think about or step into when working with a file system:file_get_contents()
returnsfalse
and triggers anE_WARNING
. I need to check the return value againstfalse
and if I want feedback on the failure, I need to work with custom error handlers. Yuck.file_get_contents()
is almost certainly a mistake that I would want to get an exception for. However,file_get_contents()
will return an empty string in that case. Fun times.With this PR, I'm proposing to add a
readFile()
method that either returns the content of a given file or throws anIOException
. Furthermore, I'm dogfooding this method in components that already depend on the Filesystem component.