Skip to content

Commit 5569400

Browse files
committed
Document Updated make:entity command
1 parent b6756ea commit 5569400

File tree

305 files changed

+4421
-2419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+4421
-2419
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
3+
If your pull request fixes a BUG, use the oldest maintained branch that contains
4+
the bug (see https://symfony.com/roadmap for the list of maintained branches).
5+
6+
If your pull request documents a NEW FEATURE, use the same Symfony branch where
7+
the feature was introduced (and `master` for features of unreleased versions).
8+
9+
-->

_build/_theme/_templates/layout.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{% extends '!layout.html' %}
22

3-
{% set css_files = ['https://symfony.com/css/compiled/v5/all.css?v=4'] %}
3+
{% set css_files = ['./assets/css/app.css', './assets/css/doc.css'] %}
44
{# make sure the Sphinx stylesheet isn't loaded #}
55
{% set style = '' %}
66
{% set isIndex = pagename is index %}
77

88
{% block extrahead %}
99
{# add JS to support tabs #}
10-
<script src="https://symfony.com/js/v5/all.js?v=4"></script>
10+
<script src="./assets/js/manifest.js"></script>
11+
<script src="./assets/js/app.js"></script>
12+
<script src="./assets/js/doc.js"></script>
1113

1214
{# pygment's styles are still loaded, undo some unwanted styles #}
1315
<style>

_build/_theme/assets/css/app.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_build/_theme/assets/css/doc.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_build/_theme/assets/js/app.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_build/_theme/assets/js/doc.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_build/_theme/assets/js/manifest.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-123 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

_images/components/http_kernel/http-workflow-exception.svg

Lines changed: 1 addition & 0 deletions
Loading

_images/components/http_kernel/http-workflow-subrequest.svg

Lines changed: 1 addition & 0 deletions
Loading

_images/components/http_kernel/http-workflow.svg

Lines changed: 1 addition & 0 deletions
Loading
Binary file not shown.
-125 KB
Binary file not shown.
-62.8 KB
Binary file not shown.

_images/security/authentication-guard-methods.svg

Lines changed: 1 addition & 0 deletions
Loading
3.7 KB
Binary file not shown.
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. note::
2+
3+
In order to use the annotation loader, you should have installed the
4+
``doctrine/annotations`` and ``doctrine/cache`` packages with Composer.
5+
6+
.. tip::
7+
8+
Annotation classes aren't loaded automatically, so you must load them
9+
using a class loader like this::
10+
11+
      use Composer\Autoload\ClassLoader;
12+
use Doctrine\Common\Annotations\AnnotationRegistry;
13+
14+
/** @var ClassLoader $loader */
15+
$loader = require __DIR__.'/../vendor/autoload.php';
16+
17+
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
18+
19+
return $loader;

best_practices/business-logic.rst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ Services: Naming and Configuration
3838
by Symfony's Service Container to manage services with minimal configuration. It
3939
reads the type-hints on your constructor (or other methods) and automatically
4040
passes the correct services to each method. It can also add
41-
:doc:`service tags </service_container/tags>` to the services needed them, such
41+
:doc:`service tags </service_container/tags>` to the services needing them, such
4242
as Twig extensions, event subscribers, etc.
4343

4444
The blog application needs a utility that can transform a post title (e.g.
4545
"Hello World") into a slug (e.g. "hello-world") to include it as part of the
46-
post URL. Let's create a new ``Slugger`` class inside ``src/Utils/``:
47-
48-
.. code-block:: php
46+
post URL. Let's create a new ``Slugger`` class inside ``src/Utils/``::
4947

5048
// src/Utils/Slugger.php
5149
namespace App\Utils;
@@ -69,9 +67,7 @@ simply ``Slugger::class`` if the class is already imported in your code).
6967
case, use a snake case id).
7068

7169
Now you can use the custom slugger in any other service or controller class,
72-
such as the ``AdminController``:
73-
74-
.. code-block:: php
70+
such as the ``AdminController``::
7571

7672
use App\Utils\Slugger;
7773

@@ -152,9 +148,7 @@ PHP and annotations.
152148
Use annotations to define the mapping information of the Doctrine entities.
153149

154150
Annotations are by far the most convenient and agile way of setting up and
155-
looking for mapping information:
156-
157-
.. code-block:: php
151+
looking for mapping information::
158152

159153
namespace App\Entity;
160154

@@ -166,7 +160,7 @@ looking for mapping information:
166160
*/
167161
class Post
168162
{
169-
const NUM_ITEMS = 10;
163+
const NUMBER_OF_ITEMS = 10;
170164

171165
/**
172166
* @ORM\Id
@@ -233,9 +227,7 @@ the following command to install the Doctrine fixtures bundle:
233227
$ composer require "doctrine/doctrine-fixtures-bundle"
234228
235229
Then, this bundle is enabled automatically, but only for the ``dev`` and
236-
``test`` environments:
237-
238-
.. code-block:: php
230+
``test`` environments::
239231

240232
// config/bundles.php
241233

@@ -275,6 +267,6 @@ Next: :doc:`/best_practices/controllers`
275267
.. _`full definition`: https://en.wikipedia.org/wiki/Business_logic
276268
.. _`Doctrine project`: http://www.doctrine-project.org/
277269
.. _`fixture class`: https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#writing-simple-fixtures
278-
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/
279-
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/
270+
.. _`PSR-1`: https://www.php-fig.org/psr/psr-1/
271+
.. _`PSR-2`: https://www.php-fig.org/psr/psr-2/
280272
.. _`PHP-CS-Fixer`: https://github.com/FriendsOfPHP/PHP-CS-Fixer

best_practices/configuration.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ they have nothing to do with the application's behavior. In other words, your
4242
application doesn't care about the location of your database or the credentials
4343
to access to it, as long as the database is correctly configured.
4444

45+
.. caution::
46+
47+
Beware that dumping the contents of the ``$_SERVER`` and ``$_ENV`` variables
48+
or outputting the ``phpinfo()`` contents will display the values of the
49+
environment variables, exposing sensitive information such as the database
50+
credentials.
51+
4552
.. _best-practices-canonical-parameters:
4653

4754
Canonical Parameters
@@ -96,20 +103,20 @@ to control the number of posts to display on the blog homepage:
96103
97104
# config/services.yaml
98105
parameters:
99-
homepage.num_items: 10
106+
homepage.number_of_items: 10
100107
101108
If you've done something like this in the past, it's likely that you've in fact
102109
*never* actually needed to change that value. Creating a configuration
103110
option for a value that you are never going to configure just isn't necessary.
104111
Our recommendation is to define these values as constants in your application.
105-
You could, for example, define a ``NUM_ITEMS`` constant in the ``Post`` entity::
112+
You could, for example, define a ``NUMBER_OF_ITEMS`` constant in the ``Post`` entity::
106113

107114
// src/Entity/Post.php
108115
namespace App\Entity;
109116

110117
class Post
111118
{
112-
const NUM_ITEMS = 10;
119+
const NUMBER_OF_ITEMS = 10;
113120

114121
// ...
115122
}
@@ -124,13 +131,11 @@ Constants can be used for example in your Twig templates thanks to the
124131
.. code-block:: html+twig
125132

126133
<p>
127-
Displaying the {{ constant('NUM_ITEMS', post) }} most recent results.
134+
Displaying the {{ constant('NUMBER_OF_ITEMS', post) }} most recent results.
128135
</p>
129136

130137
And Doctrine entities and repositories can now easily access these values,
131-
whereas they cannot access the container parameters:
132-
133-
.. code-block:: php
138+
whereas they cannot access the container parameters::
134139

135140
namespace App\Repository;
136141

@@ -139,7 +144,7 @@ whereas they cannot access the container parameters:
139144

140145
class PostRepository extends EntityRepository
141146
{
142-
public function findLatest($limit = Post::NUM_ITEMS)
147+
public function findLatest($limit = Post::NUMBER_OF_ITEMS)
143148
{
144149
// ...
145150
}

best_practices/controllers.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ What does the Controller look like
9898
----------------------------------
9999

100100
Considering all this, here is an example of what the controller should look like
101-
for the homepage of our app:
102-
103-
.. code-block:: php
101+
for the homepage of our app::
104102

105103
namespace App\Controller;
106104

@@ -154,9 +152,7 @@ to automatically query for an entity and pass it as an argument to your controll
154152
Use the ParamConverter trick to automatically query for Doctrine entities
155153
when it's simple and convenient.
156154

157-
For example:
158-
159-
.. code-block:: php
155+
For example::
160156

161157
use App\Entity\Post;
162158
use Symfony\Component\Routing\Annotation\Route;
@@ -187,9 +183,7 @@ The above example works without any configuration because the wildcard name
187183
``{id}`` matches the name of the property on the entity. If this isn't true, or
188184
if you have even more complex logic, the easiest thing to do is just query for
189185
the entity manually. In our application, we have this situation in
190-
``CommentController``:
191-
192-
.. code-block:: php
186+
``CommentController``::
193187

194188
/**
195189
* @Route("/comment/{postSlug}/new", name="comment_new")
@@ -208,9 +202,7 @@ the entity manually. In our application, we have this situation in
208202
}
209203

210204
You can also use the ``@ParamConverter`` configuration, which is infinitely
211-
flexible:
212-
213-
.. code-block:: php
205+
flexible::
214206

215207
use App\Entity\Post;
216208
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

best_practices/forms.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ makes them easier to re-use later.
8080
The Symfony Form component allows you to add buttons as fields on your form.
8181
This is a nice way to simplify the template that renders your form. But if you
8282
add the buttons directly in your form class, this would effectively limit the
83-
scope of that form:
84-
85-
.. code-block:: php
83+
scope of that form::
8684

8785
class PostType extends AbstractType
8886
{
@@ -164,9 +162,7 @@ can control *how* the form renders at a global level using form theming.
164162
Handling Form Submits
165163
---------------------
166164

167-
Handling a form submit usually follows a similar template:
168-
169-
.. code-block:: php
165+
Handling a form submit usually follows a similar template::
170166

171167
public function new(Request $request)
172168
{
@@ -175,9 +171,9 @@ Handling a form submit usually follows a similar template:
175171
$form->handleRequest($request);
176172

177173
if ($form->isSubmitted() && $form->isValid()) {
178-
$em = $this->getDoctrine()->getManager();
179-
$em->persist($post);
180-
$em->flush();
174+
$entityManager = $this->getDoctrine()->getManager();
175+
$entityManager->persist($post);
176+
$entityManager->flush();
181177

182178
return $this->redirectToRoute('admin_post_show', [
183179
'id' => $post->getId()

0 commit comments

Comments
 (0)