Skip to content

[2.8] Move argument resolving from ControllerResolver #14971

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 9 commits into from

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Jun 13, 2015

Description

This closes #11457. Changes since that PR:

  • The ControllerResolver has a new method setArgumentResolver, too keep BC with people overriding ControllerResolver#doGetArguments
  • Deprecations instead of removal, so it can be merged into 2.8
  • Added 2 new argument resolvers: A Security user resolver (which was the original problem to create this PR) and a PSR Request resolver

PR Info Table

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #1547, #10710
License MIT
Doc PR tbd

Todo

  • Add priority (is this actually needed?)
  • Make tests pass
  • Update docs

@@ -102,34 +118,20 @@ public function getArguments(Request $request, $controller)
$r = new \ReflectionFunction($controller);
}

$reflector = new \ReflectionMethod($this, 'doGetArguments');
if ($reflector->getDeclaringClass()->getName() !== __CLASS__) {
trigger_error('The ControllerResolverInterface::doGetArguments() method is deprecated since version 2.7 and will be removed in 3.0. Use the ArgumentResolverManager and custom ArgumentResolverInterface implementations instead.', E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe 2.8?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW deprecation errors now comes with @ operator

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, both mistakes are fixed now

/**
* @author Wouter J <wouter@wouterj.nl>
*/
class UserArgumentResolver implements ArgumentResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be confused if we want to resolve User by ParamConverter ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure I understand what you try to say.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, do you mean using the Doctrine Param Converter? That's why I made this resolver only work with UserInterface. When using the Doctrine Param Converter, one would actually need to typehint to a specific implementation.

Btw, this may be a good reason to implement priority for argument resolvers.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I mean Doctrine Param Converter and implement priority sound good to me.

@fabpot
Copy link
Member

fabpot commented Jun 15, 2015

I would be interested in having measures in terms of performance impact of these changes.

@wouterj
Copy link
Member Author

wouterj commented Jun 30, 2015

Unfortunately, I can't make benchmarks using Blackfire on my Windows PC. The timeline in the profiler doesn't show much difference between applying this PR and using the 2.8 branch.

I would appreciate if someone with a Linux machine could run some benchmarks using blackfire on this :)

@@ -153,6 +153,10 @@ public function load(array $configs, ContainerBuilder $container)
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
}

if (interface_exists('Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface')) {
Copy link
Member

Choose a reason for hiding this comment

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

there should also be a config setting to force disabling it in case you don't want to use the parameter converter, allowing to get rid of its overhead

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case, we should have a configure option for all resolvers imo (so one config option in SecurityBundle too). I'm not sure I like that.

@stof
Copy link
Member

stof commented Jun 30, 2015

and all the argument resolvers are missing their test coverage

*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->managerService) && !$container->hasAlias($this->managerService)) {
Copy link
Member

Choose a reason for hiding this comment

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

if (!$container->has($this->managerService)

@henrikbjorn
Copy link
Contributor

@wouterj how far along is this? Also could the Argument resolvement be put into a seperate repository so we can play around with it (want to use some in Silex context)

@wouterj
Copy link
Member Author

wouterj commented Aug 23, 2015

@henrikbjorn imo, it's just waiting for someone with an UNIX based PC to benchmark it properly (I'm on Windows).

If you want to play around with it, you can do something like this in a Silex test app:

$ composer require "symfony/symfony"
$ cd vendor/symfony
$ rm -rf symfony
$ git clone http://github.com/WouterJ/symfony
$ git checkout -b pr_11457

@henrikbjorn
Copy link
Contributor

Well im am on a Mac, so i could benchmark it if you have instructions on how to do so.

));
}

if (method_exists($resolver, 'setArgumentResolverManager')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If i create a ControllerResolver and use the method setArgumentResolverManager on it to set the manager directly on the resolver, and i then do not give HttpKernel an instance of that manager, the HttpKernel class will set it and overwrite the correct bootstrapping that was done.

Is there a purpose for having this code here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ControllerResolver#setArgumentResolverManager() method is tagged as @internal, which means you shouldn't use it in your own code. It only exists, so we can call it here in the HttpKernel.

This is to be BC. In 3.0, ControllerResolver#setArgumentResolverManager() will be removed and the complete argument resolving part will be called by HTTP kernel directly (ControllerResolver will only resolve the controller then). So if you want to add custom argument resolvers, do it by customizing HttpKernel instead of ControllerResolver.

@wouterj
Copy link
Member Author

wouterj commented Aug 23, 2015

I think a good benchmark would be to fork the standard edition and create 2 controllers (doing nothing more than returning a response): One controller with no arguments and one controller with some arguments (e.g. (Request $request, $someRoutePlaceholder)).

These 2 controllers then should be benchmarked with Blackfire (for instance) against the current 2.8 codebase and the code base of this PR.

@henrikbjorn
Copy link
Contributor

I dont want to do stuff with Blackfire!
If there is an alternative solution (terminal based) i am all for helping.

* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\ArgumentResolver;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this would be better suited in the Component?

@Koc
Copy link
Contributor

Koc commented Oct 1, 2015

So does only missing performance test blocks merging this PR?

//cc @fabpot

@fabpot
Copy link
Member

fabpot commented Oct 1, 2015

@Koc Performance testing is indeed blocking this PR.

@wouterj wouterj closed this Dec 11, 2015
@Koc
Copy link
Contributor

Koc commented Dec 11, 2015

Sad that this PR wouldn't merged. @wouterj has maked awesome work.

@wouterj
Copy link
Member Author

wouterj commented Dec 11, 2015

Well, I left my branch in my fork, so if someone has the time and energy to benchmark + improve this PR, feel free to base your contributions on my branch. For now, I don't have time and resources to work on this PR.

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.

10 participants