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

Deprecate bundle:controller:action and service:method notation #26085

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
deprecate ControllerNameParser
  • Loading branch information
Tobion committed Feb 19, 2018
commit b5f10f839edfe7030c952a719126a3b100c7e8b4
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CHANGELOG
* The `RedirectController` class allows for 307/308 HTTP status codes
* Deprecated `bundle:controller:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead where `serviceOrFqcn`
is either the service ID or the FQCN of the controller.
* Deprecated `Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser`
Copy link
Member

Choose a reason for hiding this comment

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

This means that the UPGRADE-5.0 file is missing some information.


4.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* (Bundle\BlogBundle\Controller\PostController::indexAction).
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since version 4.1, will be removed in 5.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

, to be removed in Symfony 5.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I normalized all deprecation messages

*/
class ControllerNameParser
{
Expand All @@ -41,6 +43,8 @@ public function __construct(KernelInterface $kernel)
*/
public function parse($controller)
{
@trigger_error(sprintf('The %s class is deprecated since version 4.1 and will be removed in 5.0.', __CLASS__), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not put the trigger on top of the file?

Copy link
Contributor Author

@Tobion Tobion Feb 12, 2018

Choose a reason for hiding this comment

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

because we still use the class and service internally. but we only want to trigger when it gets executed


$parts = explode(':', $controller);
if (3 !== count($parts) || in_array('', $parts, true)) {
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller));
Expand Down Expand Up @@ -86,6 +90,8 @@ public function parse($controller)
*/
public function build($controller)
{
@trigger_error(sprintf('The %s class is deprecated since version 4.1 and will be removed in 5.0.', __CLASS__), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

"%s" quoted + Symfony 5.0


if (0 === preg_match('#^(.*?\\\\Controller\\\\(.+)Controller)::(.+)Action$#', $controller, $match)) {
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "class::method" string.', $controller));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Guarantees that the _controller key is parsed into its final format.
*
* @author Ryan Weaver <ryan@knpuniversity.com>
*
* @deprecated since version 4.1, will be removed in 5.0.
*/
class ResolveControllerNameSubscriber implements EventSubscriberInterface
{
Expand Down
32 changes: 27 additions & 5 deletions 32 src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,36 @@ public function load($resource, $type = null)
}

foreach ($collection->all() as $route) {
if (!is_string($controller = $route->getDefault('_controller')) || !$controller) {
if (!is_string($controller = $route->getDefault('_controller'))) {
continue;
}

try {
$controller = $this->parser->parse($controller);
} catch (\InvalidArgumentException $e) {
// unable to optimize unknown notation
if (false !== strpos($controller, '::')) {
continue;
}

if (2 === substr_count($controller, ':')) {
$deprecatedNotation = $controller;

try {
$controller = $this->parser->parse($controller);

@trigger_error(sprintf(
'Referencing controllers with %s is deprecated since version 4.1 and will be removed in 5.0. Use %s instead.',
$deprecatedNotation,
$controller
), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

On one line as well.

} catch (\InvalidArgumentException $e) {
// unable to optimize unknown notation
}
}

if (1 === substr_count($controller, ':')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use an elseif here if the condition is mutually exclusive with the one above. It would prevent evaluating this one when the first is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends if someone used an extended name parser that returned something else. I would leave it like this for simplicitly.

$controller = str_replace(':', '::', $controller);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately this change is a BC break and breaks custom code relying on single colon notation. (Simply commenting this out fixes the BC break.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Removing this is an option. Do you want to create a PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to create a PR?

Not necessarily, I don't have knowledge of Symfony test suite so I'd be happy if you do that, unless you are busy. 👍

Btw already reported in #27522.

@trigger_error(sprintf(
'Referencing controllers with a single colon is deprecated since version 4.1 and will be removed in 5.0. Use %s instead.',
$controller
), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

Same here

}

$route->setDefault('_controller', $controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\HttpKernel\Kernel;

/**
* @group legacy
*/
class ControllerNameParserTest extends TestCase
{
protected $loader;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.