8000 [HttpKernel] allow using public aliases to reference controllers by nicolas-grekas · Pull Request #35560 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] allow using public aliases to reference controllers #35560

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

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
[HttpKernel] allow using public aliases to reference controllers
  • Loading branch information
nicolas-grekas committed Feb 2, 2020
commit 94bc1f7d3b5aa0f93887102da608bc6e6aed6002
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
AbstractConfigurator::$valuePreProcessor = $valuePreProcessor;
}

$container->setAlias(static::class, 'kernel');
$container->setAlias(static::class, 'kernel')->setPublic(true);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.1.0
-----

* allowed using public aliases to reference controllers

5.0.0
-----

Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public function process(ContainerBuilder $container)
$parameterBag = $container->getParameterBag();
$controllers = [];

$publicAliases = [];
foreach ($container->getAliases() as $id => $alias) {
if ($alias->isPublic()) {
$publicAliases[(string) $alias][] = $id;
}
}

foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
$def = $container->getDefinition($id);
$def->setPublic(true);
Expand Down Expand Up @@ -182,6 +189,10 @@ public function process(ContainerBuilder $container)
// register the maps as a per-method service-locators
if ($args) {
$controllers[$id.'::'.$r->name] = ServiceLocatorTagPass::register($container, $args);

foreach ($publicAliases[$id] ?? [] as $alias) {
$controllers[$alias.'::'.$r->name] = clone $controllers[$id.'::'.$r->name];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function process(ContainerBuilder $container)
// any methods listed for call-at-instantiation cannot be actions
$reason = false;
list($id, $action) = explode('::', $controller);

if ($container->hasAlias($id)) {
continue;
}

$controllerDef = $container->getDefinition($id);
foreach ($controllerDef->getMethodCalls() as list($method)) {
if (0 === strcasecmp($action, $method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,23 @@ public function testNotTaggedControllerServiceReceivesLocatorArgument()

$this->assertInstanceOf(Reference::class, $locatorArgument);
}

public function testAlias()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument([]);

$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments');

$container->setAlias(RegisterTestController::class, 'foo')->setPublic(true);

$pass = new RegisterControllerArgumentLocatorsPass();
$pass->process($container);

$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator));
}
}

class RegisterTestController
Expand Down
0