Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
feature #562 Deprecate routing annotation of FrameworkExtraBundle in …
Browse files Browse the repository at this point in the history
…favor of Symfony Core (Tobion)

This PR was merged into the 5.1.x-dev branch.

Discussion
----------

Deprecate routing annotation of FrameworkExtraBundle in favor of Symfony Core

Since symfony/symfony#23044 routing annotation is part of Symfony Core.

The only extra features that the routing annotation from SensioFrameworkExtraBundle has are
- service config for `@Route` which we don't need anymore
    - Either you use class-named services, then you don't need the "service" property at all.
    - Or you don't use class-named services. In this case the better solution to me, is for people to create a alias in the container from the controller class to to service id instead of specifying the service id in the routing. Then you're set as well and that is already common practice with autowiring.
- `@Method` does not provide real value as people agree in symfony/symfony#25103

This resolves symfony/symfony#25103

Commits
-------

444683c Deprecate routing annotation of FrameworkExtraBundle in favor of Symfony Core
  • Loading branch information
fabpot committed Feb 24, 2018
2 parents bf49405 + 444683c commit 848ebb1
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 30 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,21 @@
CHANGELOG
=========

5.2
---

* Deprecated routing annotations as this is included in symfony/framework-bundle.
Disable the feature with

```
sensio_framework_extra:
router:
annotations: false
```

Also replace the annotations `Sensio\Bundle\FrameworkExtraBundle\Configuration\Route`
and `Sensio\Bundle\FrameworkExtraBundle\Configuration\Method` with `Symfony\Component\Routing\Annotation\Route`

5.1
---

Expand Down
3 changes: 3 additions & 0 deletions Configuration/Method.php
Expand Up @@ -11,11 +11,14 @@

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;

@trigger_error(sprintf('The "%s" annotation is deprecated since version 5.2. Use "%s" instead.', Method::class, \Symfony\Component\Routing\Annotation\Route::class), E_USER_DEPRECATED);

/**
* The Method class handles the Method annotation parts.
*
* @author Fabien Potencier <fabien@symfony.com>
* @Annotation
* @deprecated since version 5.2
*/
class Method extends ConfigurationAnnotation
{
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Route.php
Expand Up @@ -13,9 +13,12 @@

use Symfony\Component\Routing\Annotation\Route as BaseRoute;

@trigger_error(sprintf('The "%s" annotation is deprecated since version 5.2. Use "%s" instead.', Route::class, BaseRoute::class), E_USER_DEPRECATED);

/**
* @author Kris Wallsmith <kris@symfony.com>
* @Annotation
* @deprecated since version 5.2
*/
class Route extends BaseRoute
{
Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/SensioFrameworkExtraExtension.php
Expand Up @@ -38,6 +38,8 @@ public function load(array $configs, ContainerBuilder $container)
$definitionsToRemove = [];

if ($config['router']['annotations']) {
@trigger_error(sprintf('Enabling the "sensio_framework_extra.router.annotations" configuration is deprecated since version 5.2. Set it to false and use the "%s" annotation from Symfony itself.', \Symfony\Component\Routing\Annotation\Route::class), E_USER_DEPRECATED);

$annotationsToLoad[] = 'routing.xml';

if (PHP_VERSION_ID < 70000) {
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/routing.xml
Expand Up @@ -8,18 +8,21 @@
<service id="sensio_framework_extra.routing.loader.annot_class" class="Sensio\Bundle\FrameworkExtraBundle\Routing\AnnotatedRouteControllerLoader" public="false">
<tag name="routing.loader" />
<argument type="service" id="annotation_reader" />
<deprecated>The "%service_id%" service is deprecated since version 5.2</deprecated>
</service>

<service id="sensio_framework_extra.routing.loader.annot_dir" class="Symfony\Component\Routing\Loader\AnnotationDirectoryLoader" public="false">
<tag name="routing.loader" />
<argument type="service" id="file_locator" />
<argument type="service" id="sensio_framework_extra.routing.loader.annot_class" />
<deprecated>The "%service_id%" service is deprecated since version 5.2</deprecated>
</service>

<service id="sensio_framework_extra.routing.loader.annot_file" class="Symfony\Component\Routing\Loader\AnnotationFileLoader" public="false">
<tag name="routing.loader" />
<argument type="service" id="file_locator" />
<argument type="service" id="sensio_framework_extra.routing.loader.annot_class" />
<deprecated>The "%service_id%" service is deprecated since version 5.2</deprecated>
</service>
</services>
</container>
4 changes: 4 additions & 0 deletions Routing/AnnotatedRouteControllerLoader.php
Expand Up @@ -16,13 +16,17 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route as FrameworkExtraBundleRoute;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

@trigger_error(sprintf('The "%s" class is deprecated since version 5.2. Use "%s" instead.', AnnotatedRouteControllerLoader::class, \Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader::class), E_USER_DEPRECATED);

/**
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
* that sets the '_controller' default based on the class and method names.
*
* It also parse the @Method annotation.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since version 5.2
*/
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
{
Expand Down
2 changes: 2 additions & 0 deletions Tests/Configuration/RouteTest.php
Expand Up @@ -15,6 +15,8 @@

/**
* @author Iltar van der Berg <ivanderberg@hostnet.nl>
*
* @group legacy
*/
class RouteTest extends \PHPUnit\Framework\TestCase
{
Expand Down
14 changes: 13 additions & 1 deletion Tests/DependencyInjection/SensioFrameworkExtraExtensionTest.php
Expand Up @@ -22,7 +22,13 @@ public function testDefaultExpressionLanguageConfig()
$container = new ContainerBuilder();

$extension = new SensioFrameworkExtraExtension();
$extension->load([], $container);
$config = [
'router' => [
'annotations' => false,
],
];

$extension->load([$config], $container);

$this->assertAlias($container, 'sensio_framework_extra.security.expression_language.default', 'sensio_framework_extra.security.expression_language');
}
Expand All @@ -33,6 +39,9 @@ public function testOverrideExpressionLanguageConfig()

$extension = new SensioFrameworkExtraExtension();
$config = [
'router' => [
'annotations' => false,
],
'security' => [
'expression_language' => 'acme.security.expression_language',
],
Expand All @@ -51,6 +60,9 @@ public function testTemplatingControllerPatterns()

$extension = new SensioFrameworkExtraExtension();
$config = [
'router' => [
'annotations' => false,
],
'templating' => [
'controller_patterns' => $patterns = ['/foo/', '/bar/', '/foobar/'],
],
Expand Down
Expand Up @@ -14,11 +14,11 @@
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/action-arguments", service="test.action_arguments")
* @Route("/action-arguments")
*/
class ActionArgumentsController
{
Expand Down
Expand Up @@ -5,8 +5,8 @@
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/nullable-arguments")
Expand Down
Expand Up @@ -11,11 +11,10 @@

namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(service="test.invokable_class_level.predefined")
* @Template("@Foo/invokable/predefined.html.twig")
*/
class InvokableClassLevelController
Expand Down
Expand Up @@ -11,9 +11,9 @@

namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;

class InvokableContainerController extends Controller
{
Expand Down
5 changes: 1 addition & 4 deletions Tests/Fixtures/FooBundle/Controller/InvokableController.php
Expand Up @@ -11,12 +11,9 @@

namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(service="test.invokable.predefined")
*/
class InvokableController
{
/**
Expand Down
Expand Up @@ -12,10 +12,10 @@
namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class IsGrantedController
{
Expand Down
Expand Up @@ -11,9 +11,9 @@

namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Template("@Foo/invokable/predefined.html.twig")
Expand Down
Expand Up @@ -3,8 +3,8 @@
namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/optional-arguments")
Expand Down
5 changes: 1 addition & 4 deletions Tests/Fixtures/FooBundle/Controller/SimpleController.php
Expand Up @@ -11,13 +11,10 @@

namespace Tests\Fixtures\FooBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(service="test.simple.multiple")
*/
class SimpleController
{
/**
Expand Down
19 changes: 9 additions & 10 deletions Tests/Fixtures/config/config.yml
Expand Up @@ -11,25 +11,24 @@ doctrine:
orm:
auto_mapping: true

sensio_framework_extra:
router:
annotations: false

services:
test.invokable.predefined:
class: Tests\Fixtures\FooBundle\Controller\InvokableController
Tests\Fixtures\FooBundle\Controller\InvokableController:
public: true

test.invokable_class_level.predefined:
class: Tests\Fixtures\FooBundle\Controller\InvokableClassLevelController
Tests\Fixtures\FooBundle\Controller\InvokableClassLevelController:
public: true

test.simple.multiple:
class: Tests\Fixtures\FooBundle\Controller\SimpleController
Tests\Fixtures\FooBundle\Controller\SimpleController:
public: true

test.action_arguments:
class: Tests\Fixtures\ActionArgumentsBundle\Controller\ActionArgumentsController
Tests\Fixtures\ActionArgumentsBundle\Controller\ActionArgumentsController:
public: true

test.is_granted_voter:
class: Tests\Fixtures\FooBundle\Security\IsGrantedVoter
Tests\Fixtures\FooBundle\Security\IsGrantedVoter:
public: false
tags:
- { name: security.voter }
Expand Down
3 changes: 3 additions & 0 deletions Tests/Routing/AnnotatedRouteControllerLoaderTest.php
Expand Up @@ -16,6 +16,9 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Routing\AnnotatedRouteControllerLoader;

/**
* @group legacy
*/
class AnnotatedRouteControllerLoaderTest extends \PHPUnit\Framework\TestCase
{
public function testServiceOptionIsAllowedOnClass()
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"symfony/config": "^3.3|^4.0",
"symfony/framework-bundle": "^3.3|^4.0",
"symfony/framework-bundle": "^3.4|^4.0",
"symfony/dependency-injection": "^3.3|^4.0",
"symfony/http-kernel": "^3.3|^4.0",
"doctrine/common": "^2.2"
Expand Down Expand Up @@ -45,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.1.x-dev"
"dev-master": "5.2.x-dev"
}
},
"minimum-stability": "dev"
Expand Down

0 comments on commit 848ebb1

Please sign in to comment.