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

invoke could return status and headers along with the content #18

Open
malhal opened this issue Apr 9, 2015 · 0 comments
Open

invoke could return status and headers along with the content #18

malhal opened this issue Apr 9, 2015 · 0 comments

Comments

@malhal
Copy link

malhal commented Apr 9, 2015

Hey thought I'd let you know I had trouble with the invoke method because I wanted to see the status code and headers, and that method only returns the content inside the response. No biggie I just subclassed and reimplemented that method to return an array of those things, also renamed a few variables:

        // Dispatch request.
        $response = $this->router->dispatch($request);

        if (method_exists($response, 'getOriginalContent'))
        {
            $responseBody = $response->getOriginalContent();
        }
        else
        {
            $responseBody = $response->getContent();
        }

        // Decode json content.
        if ($response->headers->get('content-type') == 'application/json')
        {
            if (function_exists('json_decode') and is_string($responseBody))
            {
                $responseBody = json_decode($responseBody, true);
            }
        }

        // Restore the request input and route back to the original state.
        $this->request->replace($originalInput);

        $result['body'] = $responseBody;
        $result['status'] = $response->getStatusCode();
        $result['header'] = $response->headers->all();

        return $result;
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

1 participant