8000 deprecate ControllerNameParser · symfony/symfony@23c999d · GitHub
[go: up one dir, main page]

Skip to content

Commit 23c999d

Browse files
committed
deprecate ControllerNameParser
1 parent 0632c6b commit 23c999d

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Using a `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0.
1212
* Deprecated `bundle:controller:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead where `serviceOrFqcn`
1313
is either the service ID or the FQCN of the controller.
14+
* Deprecated `Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser`
1415

1516
4.0.0
1617
-----

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

Lines 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

Lines 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

Lines 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

Lines 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