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

Smarter service #88

Open
garak opened this issue May 28, 2015 · 6 comments
Open

Smarter service #88

garak opened this issue May 28, 2015 · 6 comments

Comments

@garak
Copy link

garak commented May 28, 2015

Currently, there is only a lonely service, that just exposes underlying library.
It would be nice to offer a smarter service. This is the example provided in the bundle:

    public function streamAction()
    {
        // create an empty object
        $phpExcelObject = $this->createXSLObject();
        // create the writer
        $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
        // create the response
        $response = $this->get('phpexcel')->createStreamedResponse($writer);
        // adding headers
        $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
        $response->headers->set('Content-Disposition', 'attachment;filename=stream-file.xls');
        $response->headers->set('Pragma', 'public');
        $response->headers->set('Cache-Control', 'maxage=1');

        return $response;
    }

It's too way long. All the headers should be set by a service, and the final action should be something like this:

    public function streamAction()
    {
        // create an empty object
        $phpExcelObject = $this->createXSLObject();
        // create the writer
        $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
        // create the response
        $response = $this->get('smart_phpexcel')->createStreamedResponse($writer);

        return $response;
    }
@liuggio
Copy link
Owner

liuggio commented May 28, 2015

@garak I don't really like hiding the cache and the filename,
but I do really like the idea of reducing the code...

WDYT about

        $response = $this->get('phpexcel')->applyStandardHeader($response, filename);
// or
       $response = $this->get('phpexcel')->createStreamedResponseWithStandardHeader($writer, $filename)

@garak
Copy link
Author

garak commented May 28, 2015

Yes yes, of course I was just giving an example, I agree that hiding too much is not good.

@liuggio
Copy link
Owner

liuggio commented May 28, 2015

which choice you prefer between the 2?

applyStandardHeader
createStreamedResponseWithStandardHeader

can you provide PR?

@garak
Copy link
Author

garak commented May 28, 2015

I'll work on a PR in the next long weekend

@liuggio
Copy link
Owner

liuggio commented May 29, 2015

👍

@liuggio
Copy link
Owner

liuggio commented Jun 24, 2015

@garak ping

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

No branches or pull requests

2 participants