Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Add CSV Response Class #361
Why is the new feature needed? What purpose does it serve?
After doing a bit of searching, I didn't find a class that would send a CSV response. There were the Text, JSON, HTML, Redirect, XML, and Empty response classes, but nothing specific to CSV. So I created this PR to add a CSV response class, which can send both plain CSV text as well as a response that will be interpreted by the client as a downloadable file.
How will users use the new feature?
Users can use the CSV response class very similarly to how they use the existing response classes. The only difference is that if they supply a file name as the third parameter to the constructor, then a download response will be sent, not a textual response.
webimpress left a comment
Hi @settermjd !
I am not maintainer so I can't approve this PR, but please see my comments. As I said I don't know if this feature is gonna be accepted.
I would consider passing the array to CsvResponse and build the body inside from the array. Similar we have with JSON response - we are passing array and json is build inside.
weierophinney left a comment
I like the idea of this a lot. However, I would argue we need two things here:
You can do multiple constructors by using static constuctor methods:
Finally, this could be interesting either as part of Diactoros, or as a stand-alone package that uses PSR-17 to create the initial stream and response instances. If you want to push it here, we can definitely maintain it, though.