Nyholm / psr7-server

Helper classes to use any PSR7 implementation as your main request and response
MIT License
90 stars 21 forks source link

Fallback to an empty Stream in UploadedFile if no Stream could be created from a file #21

Closed Zegnat closed 6 years ago

Zegnat commented 6 years ago

It is possible for StreamFactoryInterface::createStreamFromFile to fail and throw a RuntimeException. One such case may occur when the file upload has failed and the tmp_name is empty.

ServerRequestCreator should not exit on such an error, and should be able to create a list of UploadedFile instances included those with errors. When StreamFactoryInterface::createStreamFromFile fails, use an empty Stream instead.

This hopefully fixes #20. At least as far as this package is concerned.

Would love it if you could especially review the unit test, @Nyholm. This was a bit of a head scratcher. I’m using a mock StreamFactoryInterface so I can make createStreamFromFile always throw…

emonkak commented 6 years ago

:+1:

I understood that the implementation of StreamFactoryInterface::createStreamFromFile should handle errors correctly. I am using nyholm/psr7 as psr-17 implementation so #20 issue will solve by this PR and latest of nyholm/psr7.

Nyholm commented 6 years ago

Excellent. Thank you for reporting this. And thank you @Zegnat for finding the issue and providing a fix.