Skip to content

Commit 4ce7f81

Browse files
committed
feature #8579 Migrating Best Practices topics to Symfony Flex structure (yceruto)
This PR was merged into the master branch. Discussion ---------- Migrating Best Practices topics to Symfony Flex structure Pending files for other PR: * configuration.rst * creating-the-project.rst * i18n.rst * templates.rst Commits ------- 176bbdf [Best Practices] More changes of Symfony Flex structure
2 parents 372abfc + 176bbdf commit 4ce7f81

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

best_practices/controllers.rst

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,30 @@ configuration to the main routing configuration file:
4141

4242
.. code-block:: yaml
4343
44-
# app/config/routing.yml
45-
app:
46-
resource: '@AppBundle/Controller/'
44+
# config/routes.yaml
45+
controllers:
46+
resource: '../src/Controller/'
4747
type: annotation
4848
4949
This configuration will load annotations from any controller stored inside the
50-
``src/AppBundle/Controller/`` directory and even from its subdirectories.
51-
So if your application defines lots of controllers, it's perfectly ok to
52-
reorganize them into subdirectories:
50+
``src/Controller/`` directory and even from its subdirectories. So if your application
51+
defines lots of controllers, it's perfectly ok to reorganize them into subdirectories:
5352

5453
.. code-block:: text
5554
5655
<your-project>/
5756
├─ ...
5857
└─ src/
59-
└─ AppBundle/
58+
├─ ...
59+
└─ Controller/
60+
├─ DefaultController.php
6061
├─ ...
61-
└─ Controller/
62-
├─ DefaultController.php
62+
├─ Api/
63+
│ ├─ ...
64+
│ └─ ...
65+
└─ Backend/
6366
├─ ...
64-
├─ Api/
65-
│ ├─ ...
66-
│ └─ ...
67-
└─ Backend/
68-
├─ ...
69-
└─ ...
67+
└─ ...
7068
7169
Template Configuration
7270
----------------------
@@ -93,9 +91,9 @@ for the homepage of our app:
9391

9492
.. code-block:: php
9593
96-
namespace AppBundle\Controller;
94+
namespace App\Controller;
9795
98-
use AppBundle\Entity\Post;
96+
use App\Entity\Post;
9997
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10098
use Symfony\Component\Routing\Annotation\Route;
10199
@@ -111,7 +109,7 @@ for the homepage of our app:
111109
->findLatest();
112110
113111
return $this->render('default/index.html.twig', array(
114-
'posts' => $posts
112+
'posts' => $posts,
115113
));
116114
}
117115
}
@@ -149,7 +147,7 @@ For example:
149147

150148
.. code-block:: php
151149
152-
use AppBundle\Entity\Post;
150+
use App\Entity\Post;
153151
use Symfony\Component\Routing\Annotation\Route;
154152
155153
/**
@@ -160,7 +158,7 @@ For example:
160158
$deleteForm = $this->createDeleteForm($post);
161159
162160
return $this->render('admin/post/show.html.twig', array(
163-
'post' => $post,
161+
'post' => $post,
164162
'delete_form' => $deleteForm->createView(),
165163
));
166164
}
@@ -202,7 +200,7 @@ flexible:
202200

203201
.. code-block:: php
204202
205-
use AppBundle\Entity\Post;
203+
use App\Entity\Post;
206204
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
207205
use Symfony\Component\HttpFoundation\Request;
208206
use Symfony\Component\Routing\Annotation\Route;

best_practices/forms.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ code. This is perfectly fine if you don't need to reuse the form somewhere else.
1717
But for organization and reuse, we recommend that you define each
1818
form in its own PHP class::
1919

20-
namespace AppBundle\Form;
20+
namespace App\Form;
2121

22-
use AppBundle\Entity\Post;
22+
use App\Entity\Post;
2323
use Symfony\Component\Form\AbstractType;
2424
use Symfony\Component\Form\FormBuilderInterface;
2525
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -50,13 +50,13 @@ form in its own PHP class::
5050

5151
.. best-practice::
5252

53-
Put the form type classes in the ``AppBundle\Form`` namespace, unless you
53+
Put the form type classes in the ``App\Form`` namespace, unless you
5454
use other custom form classes like data transformers.
5555

5656
To use the class, use ``createForm()`` and pass the fully qualified class name::
5757

5858
// ...
59-
use AppBundle\Form\PostType;
59+
use App\Form\PostType;
6060

6161
// ...
6262
public function newAction(Request $request)
@@ -109,13 +109,13 @@ This form *may* have been designed for creating posts, but if you wanted
109109
to reuse it for editing posts, the button label would be wrong. Instead,
110110
some developers configure form buttons in the controller::
111111

112-
namespace AppBundle\Controller\Admin;
112+
namespace App\Controller\Admin;
113113

114+
use App\Entity\Post;
115+
use App\Form\PostType;
114116
use Symfony\Component\HttpFoundation\Request;
115117
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
116118
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
117-
use AppBundle\Entity\Post;
118-
use AppBundle\Form\PostType;
119119

120120
class PostController extends Controller
121121
{
@@ -127,7 +127,7 @@ some developers configure form buttons in the controller::
127127
$form = $this->createForm(PostType::class, $post);
128128
$form->add('submit', SubmitType::class, array(
129129
'label' => 'Create',
130-
'attr' => array('class' => 'btn btn-default pull-right')
130+
'attr' => array('class' => 'btn btn-default pull-right'),
131131
));
132132

133133
// ...

best_practices/security.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ want and to load user information from any source. This is a complex topic, but
99
the :doc:`Security guide</security>` has a lot of information about
1010
this.
1111

12-
Regardless of your needs, authentication is configured in ``security.yml``,
12+
Regardless of your needs, authentication is configured in ``security.yaml``,
1313
primarily under the ``firewalls`` key.
1414

1515
.. best-practice::
@@ -43,14 +43,14 @@ which uses a login form to load users from the database:
4343

4444
.. code-block:: yaml
4545
46-
# app/config/security.yml
46+
# config/packages/security.yaml
4747
security:
4848
encoders:
49-
AppBundle\Entity\User: bcrypt
49+
App\Entity\User: bcrypt
5050
5151
providers:
5252
database_users:
53-
entity: { class: AppBundle:User, property: username }
53+
entity: { class: App:User, property: username }
5454
5555
firewalls:
5656
secured_area:
@@ -74,7 +74,7 @@ Authorization (i.e. Denying Access)
7474
-----------------------------------
7575

7676
Symfony gives you several ways to enforce authorization, including the ``access_control``
77-
configuration in :doc:`security.yml </reference/configuration/security>`, the
77+
configuration in :doc:`security.yaml </reference/configuration/security>`, the
7878
:ref:`@Security annotation <best-practices-security-annotation>` and using
7979
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.authorization_checker``
8080
service directly.
@@ -134,7 +134,7 @@ method on the ``Post`` object:
134134

135135
.. code-block:: php
136136
137-
use AppBundle\Entity\Post;
137+
use App\Entity\Post;
138138
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
139139
use Symfony\Component\Routing\Annotation\Route;
140140
@@ -167,7 +167,7 @@ to the ``Post`` entity that checks if a given user is its author:
167167

168168
.. code-block:: php
169169
170-
// src/AppBundle/Entity/Post.php
170+
// src/Entity/Post.php
171171
// ...
172172
173173
class Post
@@ -189,7 +189,7 @@ Now you can reuse this method both in the template and in the security expressio
189189

190190
.. code-block:: php
191191
192-
use AppBundle\Entity\Post;
192+
use App\Entity\Post;
193193
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
194194
use Symfony\Component\Routing\Annotation\Route;
195195
@@ -263,13 +263,13 @@ the same ``getAuthorEmail()`` logic you used above:
263263

264264
.. code-block:: php
265265
266-
namespace AppBundle\Security;
266+
namespace App\Security;
267267
268+
use App\Entity\Post;
268269
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
269270
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
270271
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
271272
use Symfony\Component\Security\Core\User\UserInterface;
272-
use AppBundle\Entity\Post;
273273
274274
class PostVoter extends Voter
275275
{
@@ -330,7 +330,7 @@ the same ``getAuthorEmail()`` logic you used above:
330330
}
331331
}
332332
333-
If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
333+
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
334334
your application will :ref:`autoconfigure <services-autoconfigure>` your security
335335
voter and inject an ``AccessDecisionManagerInterface`` instance into it thanks to
336336
:doc:`autowiring </service_container/autowiring>`.

best_practices/web-assets.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ stored these assets in the ``Resources/public/`` directory of each bundle.
77

88
.. best-practice::
99

10-
Store your assets in the ``web/`` directory.
10+
Store your assets in the ``public/`` directory.
1111

1212
Scattering your web assets across tens of different bundles makes it more
1313
difficult to manage them. Your designers' lives will be much easier if all
@@ -28,7 +28,7 @@ much more concise:
2828

2929
.. note::
3030

31-
Keep in mind that ``web/`` is a public directory and that anything stored
31+
Keep in mind that ``public/`` is a public directory and that anything stored
3232
here will be publicly accessible, including all the original asset files
3333
(e.g. Sass, LESS and CoffeeScript files).
3434

0 commit comments

Comments
 (0)