Skip to content

Commit 752a3ae

Browse files
committed
[Routing] @Route is usable without SensioFrameworkBundle since 3.4
1 parent c3f8980 commit 752a3ae

24 files changed

+59
-56
lines changed

best_practices/controllers.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ for the homepage of our app:
9696
namespace AppBundle\Controller;
9797
9898
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
99-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
99+
use Symfony\Component\Routing\Annotation\Route;
100100
use Doctrine\ORM\EntityManagerInterface;
101101
102102
class DefaultController extends Controller
@@ -149,7 +149,7 @@ For example:
149149
.. code-block:: php
150150
151151
use AppBundle\Entity\Post;
152-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
152+
use Symfony\Component\Routing\Annotation\Route;
153153
154154
/**
155155
* @Route("/{id}", name="admin_post_show")
@@ -202,9 +202,9 @@ flexible:
202202
.. code-block:: php
203203
204204
use AppBundle\Entity\Post;
205-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
206205
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
207206
use Symfony\Component\HttpFoundation\Request;
207+
use Symfony\Component\Routing\Annotation\Route;
208208
209209
/**
210210
* @Route("/comment/{postSlug}/new", name = "comment_new")

best_practices/security.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ Using ``@Security``, this looks like:
109109

110110
.. code-block:: php
111111
112-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
113112
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
113+
use Symfony\Component\Routing\Annotation\Route;
114114
// ...
115115
116116
/**
@@ -135,8 +135,8 @@ method on the ``Post`` object:
135135
.. code-block:: php
136136
137137
use AppBundle\Entity\Post;
138-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
139138
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
139+
use Symfony\Component\Routing\Annotation\Route;
140140
141141
/**
142142
* @Route("/{id}/edit", name="admin_post_edit")
@@ -191,6 +191,7 @@ Now you can reuse this method both in the template and in the security expressio
191191
192192
use AppBundle\Entity\Post;
193193
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
194+
use Symfony\Component\Routing\Annotation\Route;
194195
195196
/**
196197
* @Route("/{id}/edit", name="admin_post_edit")

components/routing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ routes with UTF-8 characters:
368368
namespace AppBundle\Controller;
369369
370370
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
371-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
371+
use Symfony\Component\Routing\Annotation\Route;
372372
373373
class DefaultController extends Controller
374374
{
@@ -442,7 +442,7 @@ You can also include UTF-8 strings as routing requirements:
442442
namespace AppBundle\Controller;
443443
444444
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
445-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
445+
use Symfony\Component\Routing\Annotation\Route;
446446
447447
class DefaultController extends Controller
448448
{
@@ -508,7 +508,7 @@ You can also include UTF-8 strings as routing requirements:
508508
// ...
509509
510510
return $collection;
511-
511+
512512
.. tip::
513513

514514
In addition to UTF-8 characters, the Routing component also supports all

configuration/micro_kernel_trait.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,9 @@ your ``composer.json`` file to load from there:
127127
}
128128
}
129129
130-
Now, suppose you want to use Twig and load routes via annotations. For annotation
131-
routing, you need SensioFrameworkExtraBundle. This comes with a normal Symfony project.
132-
But in this case, you need to download it:
133-
134-
.. code-block:: bash
135-
136-
$ composer require sensio/framework-extra-bundle
137-
138-
Instead of putting *everything* in ``index.php``, create a new ``app/AppKernel.php``
139-
to hold the kernel. Now it looks like this::
130+
Now, suppose you want to use Twig and load routes via annotations. Instead of
131+
putting *everything* in ``index.php``, create a new ``app/AppKernel.php`` to
132+
hold the kernel. Now it looks like this::
140133

141134
// app/AppKernel.php
142135

@@ -161,7 +154,6 @@ to hold the kernel. Now it looks like this::
161154
$bundles = array(
162155
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
163156
new Symfony\Bundle\TwigBundle\TwigBundle(),
164-
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle()
165157
);
166158

167159
if ($this->getEnvironment() == 'dev') {
@@ -209,6 +201,12 @@ to hold the kernel. Now it looks like this::
209201
}
210202
}
211203

204+
205+
.. versionadded:: 3.4
206+
Support for annotation routing without an external bundle was added in
207+
Symfony 3.4. Prior to version 3.4, you needed to install the
208+
SensioFrameworkExtraBundle.
209+
212210
Unlike the previous kernel, this loads an external ``app/config/config.yml`` file,
213211
because the configuration started to get bigger:
214212

@@ -261,7 +259,7 @@ has one file in it::
261259
namespace App\Controller;
262260

263261
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
264-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
262+
use Symfony\Component\Routing\Annotation\Route;
265263

266264
class MicroController extends Controller
267265
{

controller.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ This renders a page that prints a lucky (random) number::
1616
// src/AppBundle/Controller/LuckyController.php
1717
namespace AppBundle\Controller;
1818

19-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
2019
use Symfony\Component\HttpFoundation\Response;
20+
use Symfony\Component\Routing\Annotation\Route;
2121

2222
class LuckyController
2323
{
@@ -59,7 +59,7 @@ class::
5959
namespace AppBundle\Controller;
6060

6161
use Symfony\Component\HttpFoundation\Response;
62-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
62+
use Symfony\Component\Routing\Annotation\Route;
6363

6464
class LuckyController
6565
{
@@ -325,7 +325,7 @@ controller's service config:
325325
326326
// app/config/services.php
327327
use AppBundle\Controller\LuckyController;
328-
328+
329329
$container->register(LuckyController::class)
330330
->setPublic(true)
331331
->addTag('controller.service_arguments', [

controller/service.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ syntax:
3434
.. code-block:: php-annotations
3535
3636
# src/AppBundle/Controller/HelloController.php
37+
38+
// You need to use Sensio's annotation to specify a service id
39+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
3740
// ...
3841
3942
/**

controller/soap_web_service.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ can be retrieved via ``/soap?wsdl``::
6161

6262
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6363
use Symfony\Component\HttpFoundation\Response;
64-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
64+
use Symfony\Component\Routing\Annotation\Route;
6565
use AppBundle\Service\HelloService;
6666

6767
class HelloServiceController extends Controller

controller/upload_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ Finally, you need to update the code of the controller that handles the form::
110110
// src/AppBundle/Controller/ProductController.php
111111
namespace AppBundle\ProductController;
112112

113-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
114113
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
115114
use Symfony\Component\HttpFoundation\Request;
115+
use Symfony\Component\Routing\Annotation\Route;
116116
use AppBundle\Entity\Product;
117117
use AppBundle\Form\ProductType;
118118

doctrine/registration_form.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ into the database::
222222

223223
use AppBundle\Form\UserType;
224224
use AppBundle\Entity\User;
225-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
226225
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
227226
use Symfony\Component\HttpFoundation\Request;
227+
use Symfony\Component\Routing\Annotation\Route;
228228
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
229229
use Doctrine\ORM\EntityManagerInterface;
230230

page_creation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ random) number and prints it. To do that, create a "Controller class" and a
4747
// src/AppBundle/Controller/LuckyController.php
4848
namespace AppBundle\Controller;
4949

50-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
5150
use Symfony\Component\HttpFoundation\Response;
51+
use Symfony\Component\Routing\Annotation\Route;
5252

5353
class LuckyController
5454
{

quick_tour/the_big_picture.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ because that will be explained in the next section)::
5151

5252
namespace AppBundle\Controller;
5353

54-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
5554
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
55+
use Symfony\Component\Routing\Annotation\Route;
5656

5757
class DefaultController extends Controller
5858
{
@@ -95,8 +95,8 @@ at the three lines of code above the ``indexAction()`` method::
9595
// src/AppBundle/Controller/DefaultController.php
9696
namespace AppBundle\Controller;
9797

98-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9998
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
99+
use Symfony\Component\Routing\Annotation\Route;
100100

101101
class DefaultController extends Controller
102102
{

quick_tour/the_controller.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ text content::
2222
// src/AppBundle/Controller/DefaultController.php
2323
namespace AppBundle\Controller;
2424

25-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
2625
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2726
use Symfony\Component\HttpFoundation\Response;
27+
use Symfony\Component\Routing\Annotation\Route;
2828

2929
class DefaultController extends Controller
3030
{
@@ -57,8 +57,8 @@ a new method called ``helloAction()`` with the following content::
5757
// src/AppBundle/Controller/DefaultController.php
5858
namespace AppBundle\Controller;
5959

60-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6160
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
61+
use Symfony\Component\Routing\Annotation\Route;
6262

6363
class DefaultController extends Controller
6464
{
@@ -114,7 +114,7 @@ Tweak the ``hello`` route by adding a new ``_format`` variable with ``html``
114114
as its default value::
115115

116116
// src/AppBundle/Controller/DefaultController.php
117-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
117+
use Symfony\Component\Routing\Annotation\Route;
118118

119119
// ...
120120

@@ -152,8 +152,8 @@ To restrict the formats supported by a given action, use the ``requirements``
152152
option of the ``@Route()`` annotation::
153153

154154
// src/AppBundle/Controller/DefaultController.php
155-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
156155
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
156+
use Symfony\Component\Routing\Annotation\Route;
157157

158158
// ...
159159

@@ -253,9 +253,9 @@ forget to add the new ``use`` statement that imports this ``Request`` class)::
253253
// src/AppBundle/Controller/DefaultController.php
254254
namespace AppBundle\Controller;
255255

256-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
257256
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
258257
use Symfony\Component\HttpFoundation\Request;
258+
use Symfony\Component\Routing\Annotation\Route;
259259

260260
class DefaultController extends Controller
261261
{
@@ -335,7 +335,7 @@ And you can display the flash message in the template like this:
335335
{% endfor %}
336336

337337
.. versionadded:: 3.3
338-
The ``app.flashes()`` Twig function was introduced in Symfony 3.3. Prior,
338+
The ``app.flashes()`` Twig function was introduced in Symfony 3.3. Prior,
339339
you had to use ``app.session.flashBag()``.
340340

341341
Final Thoughts

routing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The route is simple:
4040
namespace AppBundle\Controller;
4141
4242
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
43-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
43+
use Symfony\Component\Routing\Annotation\Route;
4444
4545
class BlogController extends Controller
4646
{
@@ -174,7 +174,7 @@ To fix this, add a *requirement* that the ``{page}`` wildcard can *only* match n
174174
namespace AppBundle\Controller;
175175
176176
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
177-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
177+
use Symfony\Component\Routing\Annotation\Route;
178178
179179
class BlogController extends Controller
180180
{
@@ -272,7 +272,7 @@ So how can you make ``blog_list`` once again match when the user visits
272272
namespace AppBundle\Controller;
273273
274274
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
275-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
275+
use Symfony\Component\Routing\Annotation\Route;
276276
277277
class BlogController extends Controller
278278
{

routing/hostname_pattern.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can also match on the HTTP *host* of the incoming request.
1414
namespace AppBundle\Controller;
1515
1616
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
17-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
17+
use Symfony\Component\Routing\Annotation\Route;
1818
1919
class MainController extends Controller
2020
{
@@ -96,7 +96,7 @@ you can use placeholders in your hostname:
9696
namespace AppBundle\Controller;
9797
9898
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
99-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
99+
use Symfony\Component\Routing\Annotation\Route;
100100
101101
class MainController extends Controller
102102
{
@@ -173,7 +173,7 @@ instance, if you want to match both ``m.example.com`` and
173173
namespace AppBundle\Controller;
174174
175175
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
176-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
176+
use Symfony\Component\Routing\Annotation\Route;
177177
178178
class MainController extends Controller
179179
{
@@ -266,7 +266,7 @@ instance, if you want to match both ``m.example.com`` and
266266
namespace AppBundle\Controller;
267267
268268
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
269-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
269+
use Symfony\Component\Routing\Annotation\Route;
270270
271271
class MainController extends Controller
272272
{
@@ -367,7 +367,7 @@ You can also set the host option on imported routes:
367367
namespace AppBundle\Controller;
368368
369369
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
370-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
370+
use Symfony\Component\Routing\Annotation\Route;
371371
372372
/**
373373
* @Route(host="hello.example.com")

routing/redirect_trailing_slash.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ system, as explained below:
4242
// src/AppBundle/Controller/RedirectingController.php
4343
namespace AppBundle\Controller;
4444
45-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
4645
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
4746
use Symfony\Component\HttpFoundation\Request;
47+
use Symfony\Component\Routing\Annotation\Route;
4848
4949
class RedirectingController extends Controller
5050
{

routing/requirements.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ a routing ``{wildcard}`` to only match some regular expression:
1616
namespace AppBundle\Controller;
1717
1818
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
19-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
19+
use Symfony\Component\Routing\Annotation\Route;
2020
2121
class BlogController extends Controller
2222
{

routing/slash_in_parameter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ a more permissive regex path.
2626

2727
.. code-block:: php-annotations
2828
29-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
29+
use Symfony\Component\Routing\Annotation\Route;
3030
3131
class DemoController
3232
{

0 commit comments

Comments
 (0)