8000 Extracting the argument resolving from the ControllerResolver by linaori · Pull Request #18187 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Extracting the argument resolving from the ControllerResolver #18187

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 7 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
Improved the BC layer
  • Loading branch information
Iltar van der Berg committed Mar 31, 2016
commit 750dae945a8cf2ee62813b2d4dc696846f6a5c9b
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<service id="debug.controller_resolver" decorates="controller_resolver" class="Symfony\Component\HttpKernel\Controller\TraceableControllerResolver">
<argument type="service" id="debug.controller_resolver.inner" />
<argument type="service" id="debug.stopwatch" />
<argument type="service" id="argument_resolver" />
</service>

<service id="debug.argument_resolver" decorates="argument_resolver" class="Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ interface ControllerResolverInterface
* @throws \LogicException If the controller can't be found
*/
public function getController(Request $request);

/**
* Returns the arguments to pass to the controller.
*
* @param Request $request A Request instance
* @param callable $controller A PHP callable
*
* @return array An array of arguments to pass to the controller
*
* @throws \RuntimeException When value for argument given is not provided
*
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Please use the {@see ArgumentResolverInterface} instead.
*/
public function getArguments(Request $request, $controller);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TraceableControllerResolver implements ControllerResolverInterface
class TraceableControllerResolver implements ControllerResolverInterface, ArgumentResolverInterface
{
private $resolver;
private $stopwatch;
private $argumentResolver;

/**
* Constructor.
*
* @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
* @param Stopwatch $stopwatch A Stopwatch instance
* @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
* @param Stopwatch $stopwatch A Stopwatch instance
* @param ArgumentResolverInterface $argumentResolver Only required for BC
*/
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch)
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch, ArgumentResolverInterface $argumentResolver = null)
{
$this->resolver = $resolver;
$this->stopwatch = $stopwatch;
$this->argumentResolver = $argumentResolver;

if (null === $this->argumentResolver) {
$this->argumentResolver = $resolver;
}
}

/**
Expand All @@ -49,4 +56,26 @@ public function getController(Request $request)

return $ret;
}

/**
* {@inheritdoc}
*
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0.
*/
public function getArguments(Request $request, $controller)
{
@trigger_error(sprintf('This %s method is deprecated as of 3.1 and will be removed in 4.0. Please use the %s instead.', __METHOD__, TraceableArgumentResolver::class), E_USER_DEPRECATED);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops, a small typo, this should be the, will fix this after travis is done as there was an error which I failed to see


if ($this->argumentResolver instanceof TraceableArgumentResolver) {
return $this->argumentResolver->getArguments($request, $controller);
}

$e = $this->stopwatch->start('controller.get_arguments');

$ret = $this->argumentResolver->getArguments($request, $controller);

$e->stop();

return $ret;
}
}
0