8000 [HttpKernel] Allow to inject PSR-7 ServerRequest in controllers and to return a PSR-7 response. by dunglas · Pull Request #14751 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Allow to inject PSR-7 ServerRequest in controllers and to return a PSR-7 response. #14751

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

Closed
wants to merge 4 commits into from

Conversation

dunglas
Copy link
Member
@dunglas dunglas commented May 25, 2015
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR not yet

Use the PSR-7 Bridge to inject an instance of Psr\Http\Message\ServerRequestInterface in controllers. Handle PSR-7 Psr\Http\Message\ResponseInterface returned by controllers.

continue;
}

if ($param->getClass()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if ($class = $param->getClass()) {}

@dunglas dunglas force-pushed the psr7 branch 2 times, most recently from 2f73f0f to cb6430e Compare May 25, 2015 21:07
@dunglas dunglas changed the title [HttpKernel] Allow to inject PSR-7 ServerRequest in controllers. [HttpKernel] Allow to inject PSR-7 ServerRequest in controllers and to return a PSR-7 response. May 26, 2015
@linaori
Copy link
Contributor
linaori commented May 26, 2015

@wouterj weren't you working on the argument resolver for the controller resolver?

@wouterj
Copy link
Member
wouterj commented May 26, 2015

Yes: #11457 But it can't be done in a BC way...

@linaori
Copy link
Contributor
linaori commented May 26, 2015

Ah this one is for 2.8. Will have to wait then :(

"symfony/yaml": "~2.0,>=2.0.5|~3.0.0"
"symfony/yaml": "~2.0,>=2.0.5|~3.0.0",
"symfony/psr-http-message-bridge": "dev-wip",
"zendframework/zend-diactoros": "~1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Those 2 deps are actually soft ones, not hard ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in the require-dev section (just for tests).

@stof
Copy link
Member
stof commented May 26, 2015

I don't really like how this gets mixed inside the ControllerResolver and the HttpKernel. IMO, for Symfony 2.x, this should be handled with a SensioFrameworkExtraBundle ParamConverter (for the Request injection) and a kernel.view listener (for the Response conversion).
And btw, this will be compatible with Symfony 2.3+ in this case.

@nicolas-grekas
Copy link
Member

I'm challenging this idea of handling Psr7 req/resp directly in a Sf application at this state of the psr art.
We for sure need a bridge to plug a Sf app as a Psr-7 middleware and this is the purpose of the bridge.
But coding an app against Psr-7 req/resp objects does not fit the Sf model where mutability is central.

@stof
Copy link
Member
stof commented May 26, 2015

Well, for the controller, it is possible, given that the controller generally does not mutate the Request, and it is responsible for returning a response anyway. Allowing to use PSR-7 here would allow to reuse controllers written against PSR-7, which improves interoperability for people writing controllers.

But I still don't like how the kernel gets more complex because of this PSR-7 support while it could be done outside of the kernel with the existing extension points.

@dunglas
Copy link
Member Author
dunglas commented May 26, 2015

@stof It can be moved in SensioExtraFramework easily but I've some concern about that (ordered by priority):

  • with the current implementation, PSR-7 messages can be used in any application using the HttpKernel Component such as Silex ; SensioExtraFramework requires FrameworkBundle
  • adding support of PSR-7 in the core instead of in an extra package is a strong message to the community: we are progressively embracing the PSR-7 standard
  • registering a new kernel.view event will have a performance impact (it's why using the @Template annotation isn't considered a best practice), this is not the case with the current patch

The PSR-7 support in this patch is really some line of codes. The patch has grown a little because I refactored ControllerResolver::doGetArguments to improve readability and reduce cyclomatic complexity (but this is independent of PSR-7 support).

@stof
Copy link
Member
stof commented May 26, 2015

@dunglas The kernel.view event itself is not the reason for the performance impact (dispatching an event with a few listeners is not that costly). the issue with @Template is mostly the logic inside the listener to guess the template name

Regarding having it in core, it could be the case once we provide a clean extension point in core for resolving arguments (replacing what ParamConverters are doing without the need to alter the Request attributes with the converted params). And btw, a similar way could be done without depending on SensioFrameworkExtraBundle by using a kernel.controller event directly (it would require duplicating some SensioFrameworkExtraBundle code though)

@dunglas
Copy link
Member Author
dunglas commented May 26, 2015

To summarize, we have two alternatives:

Proposal 1

Let the patch as is and refactor it when new extensions points are ready.

Pro:

  • works now for every project using HttpKernel
  • send a strong message to the community
  • the patch is almost ready (ok it's my concern :-))

Cons:

  • add complexity to the core (a few lines)

Proposal 2

Move it to SensioExtraFramework and refactor it to move it back in core when extensions points are ready.

Pros:

  • doesn't add extra complexity in the core for now

Cons:

  • usable only when the project use FrameworkBundle (no Silex for instance)

I'm for the first choice :)
What do you think @symfony/deciders and others people here?

@nicolas-grekas
Copy link
Member

If 1. is doable without changing any interface then fine, but if not, we should think twice before changing one and knowingly planning for deprecating it a few months later. I don't think we need to hurry up that much. Let's talk about it for 2.8

@dunglas
Copy link
Member Author
dunglas commented May 26, 2015

PR with ParamConveter + view listener version in SensioExtraFramework: sensiolabs/SensioFrameworkExtraBundle#360

@fabpot
Copy link
Member
fabpot commented May 28, 2015

Closing in favor of the PR on SensioFrameworkExtraBundle.

@fabpot fabpot closed this May 28, 2015
fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this pull request May 29, 2015
This PR was squashed before being merged into the 3.0.x-dev branch (closes #360).

Discussion
----------

PSR-7 ParamConverter and view listener.

Replace symfony/symfony#14751

Commits
-------

705d448 PSR-7 ParamConverter and view listener.
@dunglas dunglas deleted the psr7 branch December 5, 2015 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0