Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[HttpKernel] Allow tagged controllers in ControllerResolver#53985

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:6.4frommarein:allow-tagged-controllers-in-controller-resolver
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 tagged controllers in ControllerResolver
  • Loading branch information
@marein@nicolas-grekas
marein authored andnicolas-grekas committedFeb 26, 2024
commit7d2eb5a0e8c9a7ea99506d62a5bedc128dec808f
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,7 @@ public function process(ContainerBuilder $container)

$parameterBag = $container->getParameterBag();
$controllers = [];
$controllerClasses = [];

$publicAliases = [];
foreach ($container->getAliases() as $id => $alias) {
Expand DownExpand Up@@ -74,6 +75,8 @@ public function process(ContainerBuilder $container)
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}

$controllerClasses[] = $class;

// get regular public methods
$methods = [];
$arguments = [];
Expand DownExpand Up@@ -227,5 +230,10 @@ public function process(ContainerBuilder $container)
}

$container->setAlias('argument_resolver.controller_locator', (string) $controllerLocatorRef);

if ($container->hasDefinition('controller_resolver')) {
$container->getDefinition('controller_resolver')
->addMethodCall('allowControllers', [array_unique($controllerClasses)]);
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -557,6 +557,30 @@ public function testTaggedIteratorAndTaggedLocatorAttributes()
$this->assertTrue($argLocator->has('foo'));
$this->assertSame('bar', $argLocator->get('foo'));
}

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

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

// duplicates should be removed
$container->register('bar', RegisterTestController::class)
->addTag('controller.service_arguments')
;

// services with no tag should be ignored
$container->register('baz', ControllerDummy::class);

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

$this->assertSame([['allowControllers', [[RegisterTestController::class]]]], $controllerResolver->getMethodCalls());
}
}

class RegisterTestController
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp