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 cfb1ffb

Browse filesBrowse files
committed
bug #27566 [FrameworkBundle] fix for allowing single colon controller notation (dmaicher)
This PR was merged into the 4.1 branch. Discussion ---------- [FrameworkBundle] fix for allowing single colon controller notation | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27522 | License | MIT | Doc PR | - This fixes a BC break introduced in #26085 (review). ping @Tobion Commits ------- 1680674 [FrameworkBundle] fix for allowing single colon controller notation
2 parents 8bbda2c + 1680674 commit cfb1ffb
Copy full SHA for cfb1ffb

File tree

Expand file treeCollapse file tree

2 files changed

+50
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+50
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public function load($resource, $type = null)
9494
}
9595

9696
if (1 === substr_count($controller, ':')) {
97-
$controller = str_replace(':', '::', $controller);
98-
@trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $controller), E_USER_DEPRECATED);
97+
$nonDeprecatedNotation = str_replace(':', '::', $controller);
98+
@trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $nonDeprecatedNotation), E_USER_DEPRECATED);
9999
}
100100

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

‎src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
use PHPUnit\Framework\TestCase;
66
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
77
use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
8+
use Symfony\Component\Config\Loader\LoaderInterface;
89
use Symfony\Component\Config\Loader\LoaderResolver;
10+
use Symfony\Component\Config\Loader\LoaderResolverInterface;
11+
use Symfony\Component\Routing\Route;
12+
use Symfony\Component\Routing\RouteCollection;
913

1014
class DelegatingLoaderTest extends TestCase
1115
{
@@ -17,4 +21,48 @@ public function testConstructorApi()
1721
new DelegatingLoader($controllerNameParser, new LoaderResolver());
1822
$this->assertTrue(true, '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument.');
1923
}
24+
25+
/**
26+
* @group legacy
27+
* @expectedDeprecation Referencing controllers with foo:bar:baz is deprecated since Symfony 4.1. Use some_parsed::controller instead.
28+
* @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::baz instead.
29+
*/
30+
public function testLoad()
31+
{
32+
$controllerNameParser = $this->getMockBuilder(ControllerNameParser::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$controllerNameParser->expects($this->once())
37+
->method('parse')
38+
->with('foo:bar:baz')
39+
->willReturn('some_parsed::controller');
40+
41+
$loaderResolver = $this->getMockBuilder(LoaderResolverInterface::class)
42+
->disableOriginalConstructor()
43+
->getMock();
44+
45+
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
46+
47+
$loaderResolver->expects($this->once())
48+
->method('resolve')
49+
->willReturn($loader);
50+
51+
$routeCollection = new RouteCollection();
52+
$routeCollection->add('foo', new Route('/', array('_controller' => 'foo:bar:baz')));
53+
$routeCollection->add('bar', new Route('/', array('_controller' => 'foo::baz')));
54+
$routeCollection->add('baz', new Route('/', array('_controller' => 'foo:baz')));
55+
56+
$loader->expects($this->once())
57+
->method('load')
58+
->willReturn($routeCollection);
59+
60+
$delegatingLoader = new DelegatingLoader($controllerNameParser, $loaderResolver);
61+
62+
$loadedRouteCollection = $delegatingLoader->load('foo');
63+
$this->assertCount(3, $loadedRouteCollection);
64+
$this->assertSame('some_parsed::controller', $routeCollection->get('foo')->getDefault('_controller'));
65+
$this->assertSame('foo::baz', $routeCollection->get('bar')->getDefault('_controller'));
66+
$this->assertSame('foo:baz', $routeCollection->get('baz')->getDefault('_controller'));
67+
}
2068
}

0 commit comments

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