8000 update controller.service_arguments logic for double colon controller… · symfony/symfony@1a649df · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 1a649df

Browse files
committed
update controller.service_arguments logic for double colon controller syntax
1 parent ff7bac2 commit 1a649df

File tree

4 files changed

+62
lines changed

4 files changed

+22
-62
lines changed

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function process(ContainerBuilder $container)
163163
}
164164
// register the maps as a per-method service-locators
165165
if ($args) {
166-
$controllers[$id.':'.$r->name] = ServiceLocatorTagPass::register($container, $args);
166+
$controllers[$id.'::'.$r->name] = ServiceLocatorTagPass::register($container, $args);
167167
}
168168
}
169169
}

src/Symfony/Component/HttpKernel/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public function process(ContainerBuilder $container)
4747
} else {
4848
// any methods listed for call-at-instantiation cannot be actions
4949
$reason = false;
50-
$action = substr(strrchr($controller, ':'), 1);
51-
$id = substr($controller, 0, -1 - strlen($action));
50+
list($id, $action) = explode('::', $controller);
52< 8000 code>51
$controllerDef = $container->getDefinition($id);
5352
foreach ($controllerDef->getMethodCalls() as list($method)) {
5453
if (0 === strcasecmp($action, $method)) {
@@ -57,9 +56,9 @@ public function process(ContainerBuilder $container)
5756
}
5857
}
5958
if (!$reason) {
60-
if ($controllerDef->getClass() === $id) {
61-
$controllers[$id.'::'.$action] = $argumentRef;
62-
}
59+
// deprecated since version 4.1 and will be removed in 5.0. See Symfony\Component\HttpKernel\Controller\ContainerControllerResolver
60+
$controllers[$id.':'.$action] = $argumentRef;
61+
6362
if ('__invoke' === $action) {
6463
$controllers[$id] = $argumentRef;
6564
}

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ public function testAllActions()
140140

141141
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
142142

143-
$this->assertEquals(array('foo:fooAction'), array_keys($locator));
144-
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo:fooAction']);
143+
$this->assertEquals(array('foo::fooAction'), array_keys($locator));
144+
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo::fooAction']);
145145

146-
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
146+
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
147147

148148
$this->assertSame(ServiceLocator::class, $locator->getClass());
149149
$this->assertFalse($locator->isPublic());
@@ -166,7 +166,7 @@ public function testExplicitArgument()
166166
$pass->process($container);
167167

168168
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
169-
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
169+
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
170170

171171
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class)));
172172
$this->assertEquals($expected, $locator->getArgument(0));
@@ -185,7 +185,7 @@ public function testOptionalArgument()
185185
$pass->process($container);
186186

187187
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
188-
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
188+
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
189189

190190
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
191191
$this->assertEquals($expected, $locator->getArgument(0));
@@ -203,7 +203,7 @@ public function testSkipSetContainer()
203203
$pass->process($container);
204204

205205
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
206-
$this->assertSame(array('foo:fooAction'), array_keys($locator));
206+
$this->assertSame(array('foo::fooAction'), array_keys($locator));
207207
}
208208

209209
/**
@@ -250,7 +250,7 @@ public function testNoExceptionOnNonExistentTypeHintOptionalArg()
250250
$pass->process($container);
251251

252252
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
253-
$this->assertSame(array('foo:barAction', 'foo:fooAction'), array_keys($locator));
253+
$this->assertSame(array('foo::barAction', 'foo::fooAction'), array_keys($locator));
254254
}
255255

256256
public function testArgumentWithNoTypeHintIsOk()
@@ -300,7 +300,7 @@ public function testBindings($bindingName)
300300

301301
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
302302

303-
$locator = $container->getDefinition((string) $locator['foo:fooAction']->getValues()[0]);
303+
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
304304

305305
$expected = array('bar' => new ServiceClosureArgument(new Reference('foo')));
306306
$this->assertEquals($expected, $locator->getArgument(0));

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPassTest.php

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,30 @@ public function testProcess()
3636

3737
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
3838

39-
$this->assertCount(2, $container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0));
40-
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
41-
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
39+
$this->assertCount(2, $container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0));
40+
$this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
41+
$this->assertCount(1, $container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));
4242

4343
(new ResolveInvalidReferencesPass())->process($container);
4444

45-
$this->assertCount(1, $container->getDefinition((string) $controllers['c2:setTestCase']->getValues()[0])->getArgument(0));
46-
$this->assertSame(array(), $container->getDefinition((string) $controllers['c2:fooAction']->getValues()[0])->getArgument(0));
45+
$this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
46+
$this->assertSame(array(), $container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));
4747

4848
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
4949

5050
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
5151

52-
$this->assertSame(array('c1:fooAction'), array_keys($controllers));
53-
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1:fooAction']->getValues()[0])->getArgument(0)));
52+
$this->assertSame(array('c1::fooAction', 'c1:fooAction'), array_keys($controllers));
53+
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0)));
5454

5555
$expectedLog = array(
56-
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing service-argument resolver for controller "c2:fooAction": no corresponding services exist for the referenced types.',
56+
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing service-argument resolver for controller "c2::fooAction": no corresponding services exist for the referenced types.',
5757
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing method "setTestCase" of service "c2" from controller candidates: the method is called at instantiation, thus cannot be an action.',
5858
);
5959

6060
$this->assertSame($expectedLog, $container->getCompiler()->getLog());
6161
}
6262

63-
public function testSameIdClass()
64-
{
65-
$container = new ContainerBuilder();
66-
$resolver = $container->register('argument_resolver.service')->addArgument(array());
67-
68-
$container->register(RegisterTestController::class, RegisterTestController::class)
69-
->addTag('controller.service_arguments')
70-
;
71-
72-
(new RegisterControllerArgumentLocatorsPass())->process($container);
73-
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
74-
75-
$expected = array(
76-
RegisterTestController::class.':fooAction',
77-
RegisterTestController::class.'::fooAction',
78-
);
79-
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
80-
}
81-
8263
public function testInvoke()
8364
{
8465
$container = new ContainerBuilder();
@@ -92,30 +73,10 @@ public function testInvoke()
9273
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
9374

9475
$this->assertEquals(
95-
array('invokable:__invoke', 'invokable'),
76+
array('invokable::__invoke', 'invokable:__invoke', 'invokable'),
9677
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
9778
);
9879
}
99-
100-
public function testInvokeSameIdClass()
101-
{
102-
$container = new ContainerBuilder();
103-
$resolver = $container->register('argument_resolver.service')->addArgument(array());
104-
105-
$container->register(InvokableRegisterTestController::class, InvokableRegisterTestController::class)
106-
->addTag('controller.service_arguments')
107-
;
108-
109-
(new RegisterControllerArgumentLocatorsPass())->process($container);
110-
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
111-
112-
$expected = array(
113-
InvokableRegisterTestController::class.':__invoke',
114-
InvokableRegisterTestController::class.'::__invoke',
115-
InvokableRegisterTestController::class,
116-
);
117-
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
118-
}
11980
}
12081

12182
class RemoveTestController1

0 commit comments

Comments
 (0)
0