-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Changes from 1 commit
110f18c
f6d6312
a296fd9
8b2069e
5701471
178270d
067a0d8
719f953
4f8e381
b5f10f8
26cad79
5221135
677e2ab
ea4dcdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I normalized all deprecation messages |
||
*/ | ||
class ControllerNameParser | ||
{ | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not put the trigger on top of the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (0 === preg_match('#^(.*?\\\\Controller\\\\(.+)Controller)::(.+)Action$#', $controller, $match)) { | ||
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "class::method" string.', $controller)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, ':')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use an There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
|
||
$route->setDefault('_controller', $controller); | ||
|
There was a problem hiding this comment.
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.