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

Commit a7d6d0a

Browse filesBrowse files
committed
deprecate ControllerNameParser
1 parent 0632c6b commit a7d6d0a
Copy full SHA for a7d6d0a

File tree

4 files changed

+38
-5
lines changed
Filter options

4 files changed

+38
-5
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* (Bundle\BlogBundle\Controller\PostController::indexAction).
2020
*
2121
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @deprecated since version 4.1, will be removed in 5.0.
2224
*/
2325
class ControllerNameParser
2426
{
@@ -41,6 +43,8 @@ public function __construct(KernelInterface $kernel)
4143
*/
4244
public function parse($controller)
4345
{
46+
@trigger_error(sprintf('The %s class is deprecated since version 4.1 and will be removed in 5.0.', __CLASS__), E_USER_DEPRECATED);
47+
4448
$parts = explode(':', $controller);
4549
if (3 !== count($parts) || in_array('', $parts, true)) {
4650
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)
8690
*/
8791
public function build($controller)
8892
{
93+
@trigger_error(sprintf('The %s class is deprecated since version 4.1 and will be removed in 5.0.', __CLASS__), E_USER_DEPRECATED);
94+
8995
if (0 === preg_match('#^(.*?\\\\Controller\\\\(.+)Controller)::(.+)Action$#', $controller, $match)) {
9096
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "class::method" string.', $controller));
9197
}

‎src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* Guarantees that the _controller key is parsed into its final format.
2121
*
2222
* @author Ryan Weaver <ryan@knpuniversity.com>
23+
*
24+
* @deprecated since version 4.1, will be removed in 5.0.
2325
*/
2426
class ResolveControllerNameSubscriber implements EventSubscriberInterface
2527
{

‎src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
+27-5Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,36 @@ public function load($resource, $type = null)
7373
}
7474

7575
foreach ($collection->all() as $route) {
76-
if (!is_string($controller = $route->getDefault('_controller')) || !$controller) {
76+
if (!is_string($controller = $route->getDefault('_controller'))) {
7777
continue;
7878
}
7979

80-
try {
81-
$controller = $this->parser->parse($controller);
82-
} catch (\InvalidArgumentException $e) {
83-
// unable to optimize unknown notation
80+
if (false !== strpos($controller, '::')) {
81+
continue;
82+
}
83+
84+
if (2 === substr_count($controller, ':')) {
85+
$deprecatedNotation = $controller;
86+
87+
try {
88+
$controller = $this->parser->parse($controller);
89+
90+
@trigger_error(sprintf(
91+
'Referencing controllers with %s is deprecated since version 4.1 and will be removed in 5.0. Use %s instead.',
92+
$deprecatedNotation,
93+
$controller
94+
), E_USER_DEPRECATED);
95+
} catch (\InvalidArgumentException $e) {
96+
// unable to optimize unknown notation
97+
}
98+
}
99+
100+
if (1 === substr_count($controller, ':')) {
101+
$controller = str_replace(':', '::', $controller);
102+
@trigger_error(sprintf(
103+
'Referencing controllers with a single colon is deprecated since version 4.1 and will be removed in 5.0. Use %s instead.',
104+
$controller
105+
), E_USER_DEPRECATED);
84106
}
85107

86108
$route->setDefault('_controller', $controller);

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1717
use Symfony\Component\HttpKernel\Kernel;
1818

19+
/**
20+
* @group legacy
21+
*/
1922
class ControllerNameParserTest extends TestCase
2023
{
2124
protected $loader;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.