Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ed9cb3

Browse filesBrowse files
feature #22779 [4.0][BC Break] Removed BC layers for ControllerResolver::getArguments() (iltar)
This PR was squashed before being merged into the 4.0-dev branch (closes #22779). Discussion ---------- [4.0][BC Break] Removed BC layers for ControllerResolver::getArguments() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Removes the Backwards Compatibility layer for the `ControllerResolver` that depends on the `ArgumentValueResolver`. ~~There's still 1 bit left in the `HttpKernel`, but I don't quite know how this is solved in the best way:~~ ```php public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver, RequestStack $requestStack = null, ArgumentResolverInterface $argumentResolver = null) { $this->dispatcher = $dispatcher; $this->resolver = $resolver; $this->requestStack = $requestStack ?: new RequestStack(); $this->argumentResolver = $argumentResolver; if (null === $this->argumentResolver) { @trigger_error(sprintf('As of 3.1 an %s is used to resolve arguments. In 4.0 the $argumentResolver becomes the %s if no other is provided instead of using the $resolver argument.', ArgumentResolverInterface::class, ArgumentResolver::class), E_USER_DEPRECATED); // fallback in case of deprecations $this->argumentResolver = $resolver; } } ``` ~~The 4th argument is now mandatory, but I can't make it mandatory without switching it with the request stack.~~ - ~~I can make both mandatory~~ - ~~I can make it `?RequestStack`~~ - ~~I can switch the arguments~~ ~~Each of those area a BC break but for the request stack or the switch, there is no BC layer yet (could be done in 3.4).~~ Commits ------- 64ac6e5 [4.0][BC Break] Removed BC layers for ControllerResolver::getArguments()
2 parents d1aede9 + 64ac6e5 commit 5ed9cb3
Copy full SHA for 5ed9cb3

File tree

8 files changed

+14
-301
lines changed
Filter options

8 files changed

+14
-301
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<service id="debug.controller_resolver" decorates="controller_resolver" class="Symfony\Component\HttpKernel\Controller\TraceableControllerResolver" public="true">
2222
<argument type="service" id="debug.controller_resolver.inner" />
2323
<argument type="service" id="debug.stopwatch" />
24-
<argument type="service" id="argument_resolver" />
2524
</service>
2625

2726
<service id="debug.argument_resolver" decorates="argument_resolver" class="Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver" public="true">

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
4.0.0
5+
-----
6+
7+
* removed `ControllerResolverInterface::getArguments()`
8+
* removed `TraceableControllerResolver::getArguments()`
9+
* removed `ControllerResolver::getArguments()` and the ability to resolve arguments
10+
* removed the `argument_resolver` service dependency from the `debug.controller_resolver`
11+
412
3.3.0
513
-----
614

‎src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php
+1-85Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,10 @@
2323
*
2424
* @author Fabien Potencier <fabien@symfony.com>
2525
*/
26-
class ControllerResolver implements ArgumentResolverInterface, ControllerResolverInterface
26+
class ControllerResolver implements ControllerResolverInterface
2727
{
2828
private $logger;
2929

30-
/**
31-
* If the ...$arg functionality is available.
32-
*
33-
* Requires at least PHP 5.6.0 or HHVM 3.9.1
34-
*
35-
* @var bool
36-
*/
37-
private $supportsVariadic;
38-
39-
/**
40-
* If scalar types exists.
41-
*
42-
* @var bool
43-
*/
44-
private $supportsScalarTypes;
45-
4630
/**
4731
* Constructor.
4832
*
@@ -51,9 +35,6 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
5135
public function __construct(LoggerInterface $logger = null)
5236
{
5337
$this->logger = $logger;
54-
55-
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
56-
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
5738
}
5839

5940
/**
@@ -101,71 +82,6 @@ public function getController(Request $request)
10182
return $callable;
10283
}
10384

104-
/**
105-
* {@inheritdoc}
106-
*
107-
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface and inject it in the HttpKernel instead.
108-
*/
109-
public function getArguments(Request $request, $controller)
110-
{
111-
@trigger_error(sprintf('%s is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
112-
113-
if (is_array($controller)) {
114-
$r = new \ReflectionMethod($controller[0], $controller[1]);
115-
} elseif (is_object($controller) && !$controller instanceof \Closure) {
116-
$r = new \ReflectionObject($controller);
117-
$r = $r->getMethod('__invoke');
118-
} else {
119-
$r = new \ReflectionFunction($controller);
120-
}
121-
122-
return $this->doGetArguments($request, $controller, $r->getParameters());
123-
}
124-
125-
/**
126-
* @param Request $request
127-
* @param callable $controller
128-
* @param \ReflectionParameter[] $parameters
129-
*
130-
* @return array The arguments to use when calling the action
131-
*
132-
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface and inject it in the HttpKernel instead.
133-
*/
134-
protected function doGetArguments(Request $request, $controller, array $parameters)
135-
{
136-
@trigger_error(sprintf('%s is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
137-
138-
$attributes = $request->attributes->all();
139-
$arguments = array();
140-
foreach ($parameters as $param) {
141-
if (array_key_exists($param->name, $attributes)) {
142-
if ($this->supportsVariadic && $param->isVariadic() && is_array($attributes[$param->name])) {
143-
$arguments = array_merge($arguments, array_values($attributes[$param->name]));
144-
} else {
145-
$arguments[] = $attributes[$param->name];
146-
}
147-
} elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
148-
$arguments[] = $request;
149-
} elseif ($param->isDefaultValueAvailable()) {
150-
$arguments[] = $param->getDefaultValue();
151-
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
152-
$arguments[] = null;
153-
} else {
154-
if (is_array($controller)) {
155-
$repr = sprintf('%s::%s()', get_class($controller[0]), $controller[1]);
156-
} elseif (is_object($controller)) {
157-
$repr = get_class($controller);
158-
} else {
159-
$repr = $controller;
160-
}
161-
162-
throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->name));
163-
}
164-
}
165-
166-
return $arguments;
167-
}
168-
16985
/**
17086
* Returns a callable for the given controller.
17187
*

‎src/Symfony/Component/HttpKernel/Controller/ControllerResolverInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ControllerResolverInterface.php
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,4 @@ interface ControllerResolverInterface
4242
* @throws \LogicException If the controller can't be found
4343
*/
4444
public function getController(Request $request);
45-
46-
/**
47-
* Returns the arguments to pass to the controller.
48-
*
49-
* @param Request $request A Request instance
50-
* @param callable $controller A PHP callable
51-
*
52-
* @return array An array of arguments to pass to the controller
53-
*
54-
* @throws \RuntimeException When value for argument given is not provided
55-
*
56-
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Please use the {@see ArgumentResolverInterface} instead.
57-
*/
58-
public function getArguments(Request $request, $controller);
5945
}

‎src/Symfony/Component/HttpKernel/Controller/TraceableControllerResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/TraceableControllerResolver.php
+4-30Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,21 @@
1919
*
2020
* @author Fabien Potencier <fabien@symfony.com>
2121
*/
22-
class TraceableControllerResolver implements ControllerResolverInterface, ArgumentResolverInterface
22+
class TraceableControllerResolver implements ControllerResolverInterface
2323
{
2424
private $resolver;
2525
private $stopwatch;
26-
private $argumentResolver;
2726

2827
/**
2928
* Constructor.
3029
*
31-
* @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
32-
* @param Stopwatch $stopwatch A Stopwatch instance
33-
* @param ArgumentResolverInterface $argumentResolver Only required for BC
30+
* @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
31+
* @param Stopwatch $stopwatch A Stopwatch instance
3432
*/
35-
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch, ArgumentResolverInterface $argumentResolver = null)
33+
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch)
3634
{
3735
$this->resolver = $resolver;
3836
$this->stopwatch = $stopwatch;
39-
$this->argumentResolver = $argumentResolver;
40-
41-
// BC
42-
if (null === $this->argumentResolver) {
43-
$this->argumentResolver = $resolver;
44-
}
45-
46-
if (!$this->argumentResolver instanceof TraceableArgumentResolver) {
47-
$this->argumentResolver = new TraceableArgumentResolver($this->argumentResolver, $this->stopwatch);
48-
}
4937
}
5038

5139
/**
@@ -61,18 +49,4 @@ public function getController(Request $request)
6149

6250
return $ret;
6351
}
64-
65-
/**
66-
* {@inheritdoc}
67-
*
68-
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0.
69-
*/
70-
public function getArguments(Request $request, $controller)
71-
{
72-
@trigger_error(sprintf('The %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);
73-
74-
$ret = $this->argumentResolver->getArguments($request, $controller);
75-
76-
return $ret;
77-
}
7852
}

‎src/Symfony/Component/HttpKernel/HttpKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpKernel.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
5151
$this->argumentResolver = $argumentResolver;
5252

5353
if (null === $this->argumentResolver) {
54-
@trigger_error(sprintf('As of 3.1 an %s is used to resolve arguments. In 4.0 the $argumentResolver becomes the %s if no other is provided instead of using the $resolver argument.', ArgumentResolverInterface::class, ArgumentResolver::class), E_USER_DEPRECATED);
55-
// fallback in case of deprecations
56-
$this->argumentResolver = $resolver;
54+
$this->argumentResolver = new ArgumentResolver();
5755
}
5856
}
5957

‎src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Controller/ControllerResolverTest.php
-147Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Log\LoggerInterface;
1616
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
17-
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
18-
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
1917
use Symfony\Component\HttpFoundation\Request;
2018

2119
class ControllerResolverTest extends TestCase
@@ -144,139 +142,6 @@ public function getUndefinedControllers()
144142
);
145143
}
146144

147-
/**
148-
* @group legacy
149-
*/
150-
public function testGetArguments()
151-
{
152-
$resolver = $this->createControllerResolver();
153-
154-
$request = Request::create('/');
155-
$controller = array(new self(), 'testGetArguments');
156-
$this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
157-
158-
$request = Request::create('/');
159-
$request->attributes->set('foo', 'foo');
160-
$controller = array(new self(), 'controllerMethod1');
161-
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
162-
163-
$request = Request::create('/');
164-
$request->attributes->set('foo', 'foo');
165-
$controller = array(new self(), 'controllerMethod2');
166-
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
167-
168-
$request->attributes->set('bar', 'bar');
169-
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
170-
171-
$request = Request::create('/');
172-
$request->attributes->set('foo', 'foo');
173-
$controller = function ($foo) {};
174-
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));
175-
176-
$request = Request::create('/');
177-
$request->attributes->set('foo', 'foo');
178-
$controller = function ($foo, $bar = 'bar') {};
179-
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
180-
181-
$request = Request::create('/');
182-
$request->attributes->set('foo', 'foo');
183-
$controller = new self();
184-
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
185-
$request->attributes->set('bar', 'bar');
186-
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
187-
188-
$request = Request::create('/');
189-
$request->attributes->set('foo', 'foo');
190-
$request->attributes->set('foobar', 'foobar');
191-
$controller = 'Symfony\Component\HttpKernel\Tests\Controller\some_controller_function';
192-
$this->assertEquals(array('foo', 'foobar'), $resolver->getArguments($request, $controller));
193-
194-
$request = Request::create('/');
195-
$request->attributes->set('foo', 'foo');
196-
$request->attributes->set('foobar', 'foobar');
197-
$controller = array(new self(), 'controllerMethod3');
198-
199-
try {
200-
$resolver->getArguments($request, $controller);
201-
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
202-
} catch (\Exception $e) {
203-
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
204-
}
205-
206-
$request = Request::create('/');
207-
$controller = array(new self(), 'controllerMethod5');
208-
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
209-
}
210-
211-
/**
212-
* @requires PHP 5.6
213-
* @group legacy
214-
*/
215-
public function testGetVariadicArguments()
216-
{
217-
$resolver = new ControllerResolver();
218-
219-
$request = Request::create('/');
220-
$request->attributes->set('foo', 'foo');
221-
$request->attributes->set('bar', array('foo', 'bar'));
222-
$controller = array(new VariadicController(), 'action');
223-
$this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
224-
}
225-
226-
public function testCreateControllerCanReturnAnyCallable()
227-
{
228-
$mock = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolver')->setMethods(array('createController'))->getMock();
229-
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function'));
230-
231-
$request = Request::create('/');
232-
$request->attributes->set('_controller', 'foobar');
233-
$mock->getController($request);
234-
}
235-
236-
/**
237-
* @expectedException \RuntimeException
238-
* @group legacy
239-
*/
240-
public function testIfExceptionIsThrownWhenMissingAnArgument()
241-
{
242-
$resolver = new ControllerResolver();
243-
$request = Request::create('/');
244-
245-
$controller = array($this, 'controllerMethod1');
246-
247-
$resolver->getArguments($request, $controller);
248-
}
249-
250-
/**
251-
* @requires PHP 7.1
252-
* @group legacy
253-
*/
254-
public function testGetNullableArguments()
255-
{
256-
$resolver = new ControllerResolver();
257-
258-
$request = Request::create('/');
259-
$request->attributes->set('foo', 'foo');
260-
$request->attributes->set('bar', new \stdClass());
261-
$request->attributes->set('mandatory', 'mandatory');
262-
$controller = array(new NullableController(), 'action');
263-
$this->assertEquals(array('foo', new \stdClass(), 'value', 'mandatory'), $resolver->getArguments($request, $controller));
264-
}
265-
266-
/**
267-
* @requires PHP 7.1
268-
* @group legacy
269-
*/
270-
public function testGetNullableArgumentsWithDefaults()
271-
{
272-
$resolver = new ControllerResolver();
273-
274-
$request = Request::create('/');
275-
$request->attributes->set('mandatory', 'mandatory');
276-
$controller = array(new NullableController(), 'action');
277-
$this->assertEquals(array(null, null, 'value', 'mandatory'), $resolver->getArguments($request, $controller));
278-
}
279-
280145
protected function createControllerResolver(LoggerInterface $logger = null)
281146
{
282147
return new ControllerResolver($logger);
@@ -290,21 +155,9 @@ public function controllerMethod1($foo)
290155
{
291156
}
292157

293-
protected function controllerMethod2($foo, $bar = null)
294-
{
295-
}
296-
297-
protected function controllerMethod3($foo, $bar, $foobar)
298-
{
299-
}
300-
301158
protected static function controllerMethod4()
302159
{
303160
}
304-
305-
protected function controllerMethod5(Request $request)
306-
{
307-
}
308161
}
309162

310163
function some_controller_function($foo, $foobar)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.