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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review
  • Loading branch information
wouterj committed Jun 13, 2015
commit a1d66c60b055347a2ccc6d30f6d5531fc5f64696
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<services>

<service id="security.argument_resolver.user" class="Symfony\Bundle\SecurityBundle\ArgumentResolver\UserArgumentResolver">
<service id="security.argument_resolver.user"Controller class="Symfony\Bundle\SecurityBundle\ArgumentResolver\UserArgumentResolver">
<tag name="kernel.argument_resolver" />
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ class ArgumentResolverManager
/**
* @var ArgumentResolverInterface[]
*/
private $resolvers = array();
private $resolvers;

/**
* @param ArgumentResolverInterface[] $resolvers
*/
public function __construct(array $resolvers = array())
{
$this->resolvers = $resolvers;
}

/**
* Adds an argument resolver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ControllerResolver implements ControllerResolverInterface

/**
* @var ArgumentResolverManager
* @internal
*/
private $argumentResolverManager;

Expand Down Expand Up @@ -120,7 +119,7 @@ public function getArguments(Request $request, $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);
@trigger_error('The ControllerResolverInterface::doGetArguments() method is deprecated since version 2.8 and will be removed in 3.0. Use the ArgumentResolverManager and custom ArgumentResolverInterface implementations instead.', E_USER_DEPRECATED);
}

return $this->doGetArguments($request, $controller, $r->getParameters());
Expand Down Expand Up @@ -173,9 +172,10 @@ protected function instantiateController($class)
private function getArgumentResolverManager()
{
if (null === $this->argumentResolverManager) {
$this->argumentResolverManager = new ArgumentResolverManager();
$this->argumentResolverManager->add(new RequestArgumentResolver());
$this->argumentResolverManager->add(new RequestAttributesArgumentResolver());
$this->argumentResolverManager = new ArgumentResolverManager(array(
new RequestArgumentResolver(),
new RequestAttributesArgumentResolver(),
));
}

return $this->argumentResolverManager;
Expand Down
9 changes: 5 additions & 4 deletions src/Symfony/Component/HttpKernel/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
$this->requestStack = $requestStack ?: new RequestStack();

if (null === $argumentResolverManager) {
$argumentResolverManager = new ArgumentResolverManager();
$argumentResolverManager->add(new RequestArgumentResolver());
$argumentResolverManager->add(new RequestAttributesArgumentResolver());
$argumentResolverManager = new ArgumentResolverManager(array(
new RequestArgumentResolver(),
new RequestAttributesArgumentResolver(),
));
}

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.

Expand Down Expand Up @@ -157,7 +158,7 @@ private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
// controller arguments
$reflector = new \ReflectionMethod($this->resolver, 'getArguments');
if ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\HttpKernel\Controller\ControllerResolver') {
trigger_error('['.$reflector->getDeclaringClass()->getName().'] The ControllerResolverInterface::getArguments() method is deprecated since version 2.8 and will be removed in 3.0. Use the ArgumentResolverManager and custom ArgumentResolverInterface implementations instead.', E_USER_DEPRECATED);
@trigger_error('The ControllerResolverInterface::getArguments() method is deprecated since version 2.8 and will be removed in 3.0. Use the ArgumentResolverManager and custom ArgumentResolverInterface implementations instead.', E_USER_DEPRECATED);
}

$arguments = $this->resolver->getArguments($request, $controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public function setUp()
$this->resolver1 = $this->getMock('Symfony\Component\HttpKernel\Controller\ArgumentResolver\ArgumentResolverInterface');
$this->resolver2 = $this->getMock('Symfony\Component\HttpKernel\Controller\ArgumentResolver\ArgumentResolverInterface');

$this->manager = new ArgumentResolverManager();
$this->manager->add($this->resolver1);
$this->manager->add($this->resolver2);
$this->manager = new ArgumentResolverManager(array($this->resolver1, $this->resolver2));

$this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy