Skip to content

Commit

Permalink
feature #36257 [HttpKernel] Deprecate single-colon notation for contr…
Browse files Browse the repository at this point in the history
…ollers (chalasr)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[HttpKernel] Deprecate single-colon notation for controllers

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | -
| License       | MIT
| Doc PR        | todo

Commits
-------

e88cec6 [HttpKernel] Deprecate single-colon notation for controllers
  • Loading branch information
nicolas-grekas committed Mar 31, 2020
2 parents c8f4d16 + e88cec6 commit 9381dd6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions UPGRADE-5.1.md
Expand Up @@ -46,6 +46,11 @@ HttpFoundation
`__construct()` instead)
* Made the Mime component an optional dependency

HttpKernel
----------

* Deprecated support for `service:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead.

Mailer
------

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-6.0.md
Expand Up @@ -43,6 +43,11 @@ HttpFoundation
`RedirectResponse::create()`, and `StreamedResponse::create()` methods (use
`__construct()` instead)

HttpKernel
----------

* Removed support for `service:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead.

Messenger
---------

Expand Down
Expand Up @@ -71,7 +71,7 @@ public function testPanelActionWithLatestToken()
$client->request('GET', '/');
$client->request('GET', '/_profiler/latest');

$this->assertStringContainsString('kernel:homepageController', $client->getResponse()->getContent());
$this->assertStringContainsString('kernel::homepageController', $client->getResponse()->getContent());
}

public function testPanelActionWithoutValidToken()
Expand Down
Expand Up @@ -34,7 +34,7 @@ protected function configureRoutes(RoutingConfigurator $routes)
{
$routes->import(__DIR__.'/../../Resources/config/routing/profiler.xml')->prefix('/_profiler');
$routes->import(__DIR__.'/../../Resources/config/routing/wdt.xml')->prefix('/_wdt');
$routes->add('_', '/')->controller('kernel:homepageController');
$routes->add('_', '/')->controller('kernel::homepageController');
}

protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader)
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.1.0
-----

* deprecated support for `service:action` syntax to reference controllers, use `serviceOrFqcn::method` instead
* allowed using public aliases to reference controllers
* added session usage reporting when the `_stateless` attribute of the request is set to `true`
* added `AbstractSessionListener::onSessionUsage()` to report when the session is used while a request is stateless
Expand All @@ -12,8 +13,8 @@ CHANGELOG
-----

* removed support for getting the container from a non-booted kernel
* removed the first and second constructor argument of `ConfigDataCollector`
* removed `ConfigDataCollector::getApplicationName()`
* removed the first and second constructor argument of `ConfigDataCollector`
* removed `ConfigDataCollector::getApplicationName()`
* removed `ConfigDataCollector::getApplicationVersion()`
* removed support for `Symfony\Component\Templating\EngineInterface` in `HIncludeFragmentRenderer`, use a `Twig\Environment` only
* removed `TranslatorListener` in favor of `LocaleAwareListener`
Expand All @@ -25,7 +26,7 @@ CHANGELOG
* removed `GetResponseForControllerResultEvent`, use `ViewEvent` instead
* removed `GetResponseForExceptionEvent`, use `ExceptionEvent` instead
* removed `PostResponseEvent`, use `TerminateEvent` instead
* removed `SaveSessionListener` in favor of `AbstractSessionListener`
* removed `SaveSessionListener` in favor of `AbstractSessionListener`
* removed `Client`, use `HttpKernelBrowser` instead
* added method `getProjectDir()` to `KernelInterface`
* removed methods `serialize` and `unserialize` from `DataCollector`, store the serialized state in the data property instead
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\DependencyInjection\Container;

/**
* A controller resolver searching for a controller in a psr-11 container when using the "service:method" notation.
* A controller resolver searching for a controller in a psr-11 container when using the "service::method" notation.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
Expand All @@ -36,7 +36,7 @@ protected function createController(string $controller)
{
if (1 === substr_count($controller, ':')) {
$controller = str_replace(':', '::', $controller);
// TODO deprecate this in 5.1
trigger_deprecation('symfony/http-kernel', '5.1', 'Referencing controllers with a single colon is deprecated. Use "%s" instead.', $controller);
}

return parent::createController($controller);
Expand Down
Expand Up @@ -19,6 +19,10 @@

class ContainerControllerResolverTest extends ControllerResolverTest
{
/**
* @group legacy
* @expectedDeprecation Since symfony/http-kernel 5.1: Referencing controllers with a single colon is deprecated. Use "foo::action" instead.
*/
public function testGetControllerServiceWithSingleColon()
{
$service = new ControllerTestService('foo');
Expand Down Expand Up @@ -145,7 +149,6 @@ public function getControllers()
{
return [
['\\'.ControllerTestService::class.'::action'],
['\\'.ControllerTestService::class.':action'],
];
}

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/composer.json
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": "^7.2.5",
"symfony/deprecation-contracts": "^2.1",
"symfony/error-handler": "^4.4|^5.0",
"symfony/event-dispatcher": "^5.0",
"symfony/http-foundation": "^4.4|^5.0",
Expand Down

0 comments on commit 9381dd6

Please sign in to comment.