Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Add ControllerHelper; the helpers from AbstractController as a standalone service #60857

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.4
---

* Add `ControllerHelper`; the helpers from AbstractController as a standalone service
* Deprecate `Symfony\Bundle\FrameworkBundle\Console\Application::add()` in favor of `Symfony\Bundle\FrameworkBundle\Console\Application::addCommand()`
* Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`

Expand Down
Copy link

@phcorp phcorp Jun 21, 2025

Choose a reason for hiding this comment

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

question: now that it exists, why don't you use and subscribe to the service controller.helper in the AbstractController? or maybe the AbstractController will be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but there are some challenges, like would we preserve the public API of AbstractController while using the implementation of ControllerHelper? setContainer() could create a ControllerHelper? Possibly, but in the end, what for? The code duplication is totally free, and kept safe by the test suite, so things are simpler with any code reuse IMHO.

Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ public function setContainer(ContainerInterface $container): ?ContainerInterface
return $previous;
}

/**
* Gets a container parameter by its name.
*/
protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
{
if (!$this->container->has('parameter_bag')) {
throw new ServiceNotFoundException('parameter_bag.', null, null, [], \sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));
}

return $this->container->get('parameter_bag')->get($name);
}

public static function getSubscribedServices(): array
{
return [
Expand All @@ -96,6 +84,18 @@ public static function getSubscribedServices(): array
];
}

/**
* Gets a container parameter by its name.
*/
protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
{
if (!$this->container->has('parameter_bag')) {
throw new ServiceNotFoundException('parameter_bag.', null, null, [], \sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));
}

return $this->container->get('parameter_bag')->get($name);
}

/**
* Generates a URL from the given parameters.
*
Expand Down
Loading
Loading