Skip to content
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

[5.5] Add stream download response #22764

Closed
wants to merge 1 commit into from
Closed

[5.5] Add stream download response #22764

wants to merge 1 commit into from

Conversation

TheoKouzelis
Copy link
Contributor

Adds the ability to respond with remote files as downloads.

<?php

    Route::get('/', function () {
        return response()->streamDownload(function () {
            echo file_get_contents('https://my.remote.com/file/store-12345.jpg');
        }, 'nice-name.jpg');
    });

Copy link
Contributor

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests?

* Return a new streamed response as a file download from the application.
*
* @param \Closure $callback
* @param string $name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string|null according to your method signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mfn

Thanks for the PR review. I have pretty much copied the doc block from the "download" method. Would you also like me to make the same change to that doc block as well?

@GrahamCampbell GrahamCampbell changed the title Add stream download response [5.5] Add stream download response Jan 13, 2018
@TheoKouzelis
Copy link
Contributor Author

@mfn I couldn't find any tests for this class to add to. Do you know where a test for this method should go?

@sisve
Copy link
Contributor

sisve commented Jan 13, 2018

  1. This looks very similar to the existing stream() method. Can't it be used for this purpose?
  2. Should this new method be part of the ResponseFactory contract?

@TheoKouzelis
Copy link
Contributor Author

Hi @sisve

Thanks for the PR review.

I was trying to copy the feel of the existing API of "file" and "download". Where file is just a basic wrapper around the Symfony class BinaryFileResponse and download goes one step further and sets up the content disposition. This PR was kind of born out of this stackoverflow question where it felt like people where searching for a similar function to download for remote files.

Good point about the ResponseFactory contract. I have missed that and I will get this added to this PR tonight.

@m1guelpf
Copy link
Contributor

m1guelpf commented Jan 13, 2018

@TheoKouzelis If you are going to modify a contract, then you should target 5.6

@TheoKouzelis
Copy link
Contributor Author

@m1guelpf OK cool thanks. Should I remove this PR and make a new branch of 5.6?

@mfn
Copy link
Contributor

mfn commented Jan 13, 2018

Yes, thanks!

@TheoKouzelis
Copy link
Contributor Author

TheoKouzelis commented Jan 13, 2018

What is the discussion process behind adding a method to a contract? Because I'm looking at the ResponseFactory Contract in more detail and I can see "stream" and "download" are part of the interface but not "file". So it now makes me wonder if this method should be?

@TheoKouzelis
Copy link
Contributor Author

This has now been moved to a PR on the 5.6 branch with @mfn doc block change and @sisve contract change added

@TheoKouzelis TheoKouzelis deleted the feature/stream-download branch January 18, 2018 08:36
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.

4 participants