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

[6.0] Moved Response code from the Pipeline to the Routing Pipeline #29273

Merged
merged 6 commits into from
Aug 12, 2019
Merged

[6.0] Moved Response code from the Pipeline to the Routing Pipeline #29273

merged 6 commits into from
Aug 12, 2019

Conversation

DarkGhostHunter
Copy link
Contributor

Responsable check is now done on the Route Pipeline. This cleans the Base Pipeline class, avoiding unwanted behaviour when using it with Responsable objects in other parts of the developer application.

Also added a test to check if a Middleware that returns a Responsable (instead of keep going with the pipeline) transforms it to a Response.

Responsable check is now done on the Route Pipeline. This cleans the Base Pipeline class, avoiding unwanted behaviour when using it with Responsable objects.

Also added a test to check if a Middleware that returns a Responsable (instead of keep going with the pipeline) transforms it to a Response.
@DarkGhostHunter
Copy link
Contributor Author

Fuck yeah all green. Hitting the bed til tomorrow.

@DarkGhostHunter DarkGhostHunter changed the title This is a more elegant solution to #24156. [5.9] Moved Response code from the Pipeline to the Routing Pipeline Jul 23, 2019
@driesvints driesvints changed the title [5.9] Moved Response code from the Pipeline to the Routing Pipeline [6.0] Moved Response code from the Pipeline to the Routing Pipeline Jul 25, 2019
@taylorotwell
Copy link
Member

Please describe any breaking changes users would need to account for.

@DarkGhostHunter
Copy link
Contributor Author

DarkGhostHunter commented Jul 29, 2019

For developers using the Pipeline class, if a pipe returns a value it will be returned next as-is. The Pipeline won't check if the value returned by a pipe is a Responsable instance and transform it to a Response instance.

The Pipeline is used on the Middleware processing, which will keep that behaviour. That means, if one the middlewares returns a Responsable class, it will be automatically transformed to a Response.

@florentpoujol
Copy link
Contributor

Hey

Note that this would negate the effect of #29251.
Also the original PR (#24201) is more than 1 year old already.

But if the Laravel team is OK to move this special handling of Responsable objects exclusively for the middleware and in the Routing Pipeline, could we consider adding a hook method instead of overriding the whole carry() method and nest the closure (the point of #29251) .

The end of the try block in the carry method would then be:

                    $response = method_exists($pipe, $this->method)
                                    ? $pipe->{$this->method}(...$parameters)
                                    : $pipe(...$parameters);

                    return $this->handleResponse($response);

In the base class the method would just return the response, but in the Routing Pipeline it would be:

protected function handleResponse($response)
{
     return $response instanceof Responsable
                    ? $response->toResponse($this->getContainer()->make(Request::class))
                    : $response;
}

@DarkGhostHunter
Copy link
Contributor Author

Hey

Note that this would negate the effect of #29251.
Also the original PR (#24201) is more than 1 year old already.

But if the Laravel team is OK to move this special handling of Responsable objects exclusively for the middleware and in the Routing Pipeline, could we consider adding a hook method instead of overriding the whole carry() method and nest the closure (the point of #29251) .

The end of the try block in the carry method would then be:

                    $response = method_exists($pipe, $this->method)
                                    ? $pipe->{$this->method}(...$parameters)
                                    : $pipe(...$parameters);

                    return $this->handleResponse($response);

In the base class the method would just return the response, but in the Routing Pipeline it would be:

protected function handleResponse($response)
{
     return $response instanceof Responsable
                    ? $response->toResponse($this->getContainer()->make(Request::class))
                    : $response;
}

Welp, that seems better. Does the code looks more understandable now?

@DarkGhostHunter
Copy link
Contributor Author

I think this should be more important now that the Pipeline class is being used for Job Middlewares

@taylorotwell taylorotwell merged commit cf5e364 into laravel:master Aug 12, 2019
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