This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Make UploadedFile Extend SplFileInfo #378
Merged
+42
−3
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
SplFileInfo
work with stream paths? PHP docs say the argument forSplFileInfo::__construct()
should be a file path while the value of$this->stream->getMetaData('uri')
could be a stream path like'php://memory'
.As commented by @michalbundyra this patch should have more tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As suspected things go kaboom when trying to use some (or many) of the
SplFileInfo
methods if the instance is created with a stream path.https://3v4l.org/klK0X
So I am not sure if this is a very good change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ADmad
Thanks for your comment! 👍
We have another discussion in the related issue report: #377
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ADmad now run getMTime() on a file that doesn't exist... SplFileInfo is doing exactly what it is supposed to do here. This is not going "kaboom" -- this is how it works. It's not intended to provide information about files that it can't get information for -- which includes any non existent file. Your test seems to be based on a false assumption about SplFileInfo that it requires an actually existing file... it doesn't. SplFileInfo is designed to grok information about files, which means the path you pass it MAY not exist, and it's up to a developer to use it properly.
There may, of course be edge cases that we'd want to handle differently. But the example provided is just SplFileInfo working as it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, "about files", not streams. Treating a valid stream path like
php://memory
as non existent file path is wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattsah —
Having the class extend
SplFileInfo
implies that the item returned has a relationship with the filesystem, and can be operated as if it were part of the filesystem. It also implies that users should be able to safely call its various methods.Considering the major use case is to use a temporary stream (Diactoros creates temporary streams by default), we absolutely need stream support to work without errors. Since it wasn't, we had to revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weierophinney
Is there a single case where SplFileInfo acts differently on a stream than it does on a non-existent file? It seems quite strange to me that SplFileInfo suggests a relationship with the filesystem while UploadedFile does not. A stream has the same relationship to the filesystem as a non-existent file. Again, the real implication (in comments) here seems to be that SplFileInfo is not about grokking information.
Additionally, if one is truly concerned with supporting streams more fully, it would be perfectly fine, for example, to overload
getMTime()
later and call parent if it's a file or examine stream meta data if it's a stream.PHP uses stream URLs in places of "files" in all sorts of cases... the implication you suggest doesn't seem well supported.
Regarding major use cases and defaults... given that this did not previously extend it, I don't see any case where anyone would be relying on SplFileInfo methods... stream support would absolutely continue working as it has historically and could be improved upon to offer even more info via overloads as mentioned above in the future.
This is non-breaking, working as expected, and providing a useful feature. It may not provide all the features you want out of the gate, e.g. functional mtime on stream, but that'd make for a nice 2.2.1 -- awell.
Very disappointed here.