Skip to content

Commit 7f00345

Browse files
committed
Updated Bundles Best Practices for Symfony 4
1 parent 724e5c4 commit 7f00345

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

bundles/best_practices.rst

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,10 @@
44
Best Practices for Reusable Bundles
55
===================================
66

7-
There are two types of bundles:
8-
9-
* Application-specific bundles: only used to build your application;
10-
* Reusable bundles: meant to be shared across many projects.
11-
127
This article is all about how to structure your **reusable bundles** so that
13-
they're easy to configure and extend. Many of these recommendations do not
14-
apply to application bundles because you'll want to keep those as simple
15-
as possible. For application bundles, just follow the practices shown throughout
16-
the guides.
17-
18-
.. seealso::
19-
20-
The best practices for application-specific bundles are discussed in
21-
:doc:`/best_practices/introduction`.
8+
they're easy to configure and extend. Reusable bundles are those meant to be
9+
shared privately across many company projects or publicly so any Symfony project
10+
can install them.
2211

2312
.. index::
2413
pair: Bundle; Naming conventions
@@ -28,10 +17,10 @@ the guides.
2817
Bundle Name
2918
-----------
3019

31-
A bundle is also a PHP namespace. The namespace must follow the `PSR-0`_ or
32-
`PSR-4`_ interoperability standards for PHP namespaces and class names: it starts
33-
with a vendor segment, followed by zero or more category segments, and it ends
34-
with the namespace short name, which must end with ``Bundle``.
20+
A bundle is also a PHP namespace. The namespace must follow the `PSR-4`_
21+
interoperability standard for PHP namespaces and class names: it starts with a
22+
vendor segment, followed by zero or more category segments, and it ends with the
23+
namespace short name, which must end with ``Bundle``.
3524

3625
A namespace becomes a bundle as soon as you add a bundle class to it. The
3726
bundle class name must follow these simple rules:
@@ -116,21 +105,21 @@ The following classes and files have specific emplacements (some are mandatory
116105
and others are just conventions followed by most developers):
117106

118107
=================================================== ========================================
119-
Type Directory
108+
Type Directory
120109
=================================================== ========================================
121-
Commands ``Command/``
122-
Controllers ``Controller/``
123-
Service Container Extensions ``DependencyInjection/``
110+
Commands ``Command/``
111+
Controllers ``Controller/``
112+
Service Container Extensions ``DependencyInjection/``
124113
Doctrine ORM entities (when not using annotations) ``Entity/``
125114
Doctrine ODM documents (when not using annotations) ``Document/``
126-
Event Listeners ``EventListener/``
127-
Configuration ``Resources/config/``
128-
Web Resources (CSS, JS, images) ``Resources/public/``
129-
Translation files ``Resources/translations/``
115+
Event Listeners ``EventListener/``
116+
Configuration (routes, services, etc.) ``Resources/config/``
117+
Web Assets (CSS, JS, images) ``Resources/public/``
118+
Translation files ``Resources/translations/``
130119
Validation (when not using annotations) ``Resources/config/validation/``
131120
Serialization (when not using annotations) ``Resources/config/serialization/``
132-
Templates ``Resources/views/``
133-
Unit and Functional Tests ``Tests/``
121+
Templates ``Resources/views/``
122+
Unit and Functional Tests ``Tests/``
134123
=================================================== ========================================
135124

136125
Classes
@@ -177,16 +166,23 @@ the ``Tests/`` directory. Tests should follow the following principles:
177166
A test suite must not contain ``AllTests.php`` scripts, but must rely on the
178167
existence of a ``phpunit.xml.dist`` file.
179168

169+
Installation
170+
------------
171+
172+
Bundles must define a `Symfony Flex recipe`_ to automate their integration
173+
in Symfony applications. If some initial configuration is needed to execute
174+
the bundle, including some environment variables, provide them in the recipe.
175+
180176
Documentation
181177
-------------
182178

183179
All classes and functions must come with full PHPDoc.
184180

185-
Extensive documentation should also be provided in the ``Resources/doc/``
181+
Extensive documentation should also be provided in the ``Resources/doc/``
186182
directory.
187-
The index file (for example ``Resources/doc/index.rst`` or
188-
``Resources/doc/index.md``) is the only mandatory file and must be the entry
189-
point for the documentation. The
183+
The index file (for example ``Resources/doc/index.rst`` or
184+
``Resources/doc/index.md``) is the only mandatory file and must be the entry
185+
point for the documentation. The
190186
:doc:`reStructuredText (rST) </contributing/documentation/format>` is the format
191187
used to render the documentation on symfony.com.
192188

@@ -203,8 +199,19 @@ following standardized instructions in your ``README.md`` file.
203199
Installation
204200
============
205201
206-
Step 1: Download the Bundle
207-
---------------------------
202+
Applications that use Symfony Flex
203+
----------------------------------
204+
205+
Open a command console, enter your project directory and execute:
206+
207+
```console
208+
$ composer require <package-name>
209+
```
210+
211+
Applications that don't use Symfony Flex
212+
----------------------------------------
213+
214+
### Step 1: Download the Bundle
208215
209216
Open a command console, enter your project directory and execute the
210217
following command to download the latest stable version of this bundle:
@@ -217,8 +224,7 @@ following standardized instructions in your ``README.md`` file.
217224
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
218225
of the Composer documentation.
219226
220-
Step 2: Enable the Bundle
221-
-------------------------
227+
### Step 2: Enable the Bundle
222228
223229
Then, enable the bundle by adding it to the list of registered bundles
224230
in the `app/AppKernel.php` file of your project:
@@ -249,8 +255,20 @@ following standardized instructions in your ``README.md`` file.
249255
Installation
250256
============
251257
258+
Applications that use Symfony Flex
259+
----------------------------------
260+
261+
Open a command console, enter your project directory and execute:
262+
263+
.. code-block:: terminal
264+
265+
$ composer require <package-name>
266+
267+
Applications that don't use Symfony Flex
268+
----------------------------------------
269+
252270
Step 1: Download the Bundle
253-
---------------------------
271+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
254272
255273
Open a command console, enter your project directory and execute the
256274
following command to download the latest stable version of this bundle:
@@ -263,7 +281,7 @@ following standardized instructions in your ``README.md`` file.
263281
in the `installation chapter`_ of the Composer documentation.
264282
265283
Step 2: Enable the Bundle
266-
-------------------------
284+
~~~~~~~~~~~~~~~~~~~~~~~~~
267285
268286
Then, enable the bundle by adding it to the list of registered bundles
269287
in the ``app/AppKernel.php`` file of your project:
@@ -450,8 +468,8 @@ Learn more
450468
* :doc:`/bundles/extension`
451469
* :doc:`/bundles/configuration`
452470

453-
.. _`PSR-0`: http://www.php-fig.org/psr/psr-0/
454471
.. _`PSR-4`: http://www.php-fig.org/psr/psr-4/
472+
.. _`Symfony Flex recipe`: https://github.com/symfony/recipes
455473
.. _`Semantic Versioning Standard`: http://semver.org/
456474
.. _`Packagist`: https://packagist.org/
457475
.. _`choose any license`: http://choosealicense.com/

0 commit comments

Comments
 (0)