@@ -5,20 +5,20 @@ Using Symfony Flex to Manage Symfony Applications
5
5
6
6
`Symfony Flex `_ is the new way to install and manage Symfony applications. Flex
7
7
is not a new Symfony version, but a tool that replaces and improves the
8
- `Symfony Installer `_.
8
+ `Symfony Installer `_ and the ` Symfony Standard Edition `_ .
9
9
10
10
Symfony Flex **automates the most common tasks of Symfony applications **, such
11
- as installing and removing bundles and other dependencies. Symfony Flex works
12
- for Symfony 3.3 and newer versions. Starting from Symfony 4.0, Flex will be used
13
- by default, but it will still be optional to use .
11
+ as installing and removing bundles and other Composer dependencies. Symfony
12
+ Flex works for Symfony 3.3 and newer versions. Starting from Symfony 4.0, Flex
13
+ should be used by default, but it is still optional.
14
14
15
15
How Does Flex Work
16
16
------------------
17
17
18
18
Internally, Symfony Flex is a Composer plugin that modifies the behavior of the
19
- ``require `` and ``update `` commands. When installing or updating dependencies
20
- in a Flex-enabled application, Symfony can perform tasks before and after the
21
- execution of Composer tasks.
19
+ ``require ``, `` update ``, and ``remove `` commands. When installing or removing
20
+ dependencies in a Flex-enabled application, Symfony can perform tasks before
21
+ and after the execution of Composer tasks.
22
22
23
23
Consider the following example:
24
24
@@ -33,25 +33,30 @@ name. However, if the application has Symfony Flex installed, that command ends
33
33
up installing and enabling the SwiftmailerBundle, which is the best way to
34
34
integrate Swiftmailer, the official mailer for Symfony applications.
35
35
36
- When Symfony Flex is installed in the application and you execute ``composer require ``,
37
- the application makes a request to Symfony Flex servers before trying to install
38
- the package with Composer:
36
+ When Symfony Flex is installed in the application and you execute ``composer
37
+ require ``, the application makes a request to Symfony Flex servers before
38
+ trying to install the package with Composer:
39
39
40
40
* If there's no information about that package, Flex server returns nothing and
41
41
the package installation follows the usual procedure based on Composer;
42
+
42
43
* If there's special information about that package, Flex returns it in a file
43
- called "recipe" and the application uses it to decide which package to install
44
- and which automated tasks to run after the installation.
44
+ called "recipe" and the application uses it to decide which package to
45
+ install and which automated tasks to run after the installation.
45
46
46
47
In the above example, Symfony Flex asks about the ``mailer `` package and the
47
- Symfony Flex server detects that ``mailer `` is in fact an alias for SwiftmailerBundle
48
- and returns the "recipe" for it.
48
+ Symfony Flex server detects that ``mailer `` is in fact an alias for
49
+ SwiftmailerBundle and returns the "recipe" for it.
50
+
51
+ Flex keeps tracks of the recipes it installed in a ``symfony.lock `` file, which
52
+ must be committed to your code repository.
49
53
50
54
Symfony Flex Recipes
51
55
~~~~~~~~~~~~~~~~~~~~
52
56
53
57
Recipes are defined in a ``manifest.json `` file and can contain any number of
54
- other files and directories. For example, this is the ``manifest.json `` for SwiftmailerBundle:
58
+ other files and directories. For example, this is the ``manifest.json `` for
59
+ SwiftmailerBundle:
55
60
56
61
.. code-block :: javascript
57
62
@@ -69,27 +74,29 @@ other files and directories. For example, this is the ``manifest.json`` for Swif
69
74
}
70
75
71
76
The ``aliases `` option allows Flex to install packages using short and easy to
72
- remember names (``composer require mailer `` vs ``composer require symfony/swiftmailer-bundle ``).
73
- The ``bundles `` option tells Flex in which environments should this bundle be
74
- enabled automatically (``all `` in this case). The ``env `` option makes Flex to
75
- add new environment variables to the application. Finally, the ``copy-from-recipe ``
76
- option allows the recipe to copy files and directories into your application.
77
-
78
- The instructions defined in this ``manifest.json `` file are also used by Symfony
79
- Flex when uninstalling dependencies (e.g. ``composer remove mailer ``) to undo
80
- all changes. This means that Flex can remove the SwiftmailerBundle from the
81
- application, delete the ``MAILER_URL `` environment variable and any other file
82
- and directory created by this recipe.
77
+ remember names (``composer require mailer `` vs ``composer require
78
+ symfony/swiftmailer-bundle ``). The ``bundles `` option tells Flex in which
79
+ environments this bundle should be enabled automatically (``all `` in this
80
+ case). The ``env `` option makes Flex to add new environment variables to the
81
+ application. Finally, the ``copy-from-recipe `` option allows the recipe to copy
82
+ files and directories into your application.
83
+
84
+ The instructions defined in this ``manifest.json `` file are also used by
85
+ Symfony Flex when uninstalling dependencies (e.g. ``composer remove mailer ``)
86
+ to undo all changes. This means that Flex can remove the SwiftmailerBundle from
87
+ the application, delete the ``MAILER_URL `` environment variable and any other
88
+ file and directory created by this recipe.
83
89
84
90
Symfony Flex recipes are contributed by the community and they are stored in
85
91
two public repositories:
86
92
87
93
* `Main recipe repository `_, is a curated list of recipes for high quality and
88
94
maintained packages. Symfony Flex only looks in this repository by default.
89
- * `Contrib recipe repository `_, contains all the recipes created by the community.
90
- All of them are guaranteed to work, but their associated packages could be
91
- unmaintained. Symfony Flex ignores these recipes by default, but you can execute
92
- this command to start using them in your project:
95
+
96
+ * `Contrib recipe repository `_, contains all the recipes created by the
97
+ community. All of them are guaranteed to work, but their associated packages
98
+ could be unmaintained. Symfony Flex ignores these recipes by default, but you
99
+ can execute this command to start using them in your project:
93
100
94
101
.. code-block :: terminal
95
102
@@ -103,9 +110,9 @@ Using Symfony Flex in New Applications
103
110
--------------------------------------
104
111
105
112
Symfony has published a new "skeleton" project, which is a minimal Symfony
106
- project recommended to create new applications. This "skeleton" already includes
107
- Symfony Flex as a dependency, so you can create a new Flex-enabled Symfony
108
- application executing the following command:
113
+ project recommended to create new applications. This "skeleton" already
114
+ includes Symfony Flex as a dependency. This means you can create a new Flex-enabled
115
+ Symfony application by executing the following command:
109
116
110
117
.. code-block :: terminal
111
118
@@ -114,7 +121,8 @@ application executing the following command:
114
121
.. note ::
115
122
116
123
The use of the Symfony Installer to create new applications is no longer
117
- recommended since Symfony 3.3. Use Composer ``create-project `` command instead.
124
+ recommended since Symfony 3.3. Use Composer ``create-project `` command
125
+ instead.
118
126
119
127
Upgrading Existing Applications to Flex
120
128
---------------------------------------
@@ -144,29 +152,42 @@ following directory structure, which is the same used by default in Symfony 4:
144
152
145
153
This means that installing the ``symfony/flex `` dependency in your application
146
154
is not enough. You must also upgrade the directory structure to the one showed
147
- above. Sadly, there's no automatic tool to make this upgrade, so you must follow
148
- these manual steps:
149
-
150
- #. Create a new empty Symfony application (``composer create-project symfony/skeleton my-project-flex ``)
151
- #. Copy the ``require `` and ``require-dev `` dependencies defined in your original
152
- project's ``composer.json `` file to the ``composer.json `` file of the new project.
153
- #. Install the dependencies in the new project executing ``composer install ``. This
154
- will make Symfony Flex generate all the configuration files in ``config/packages/ ``
155
+ above. There's no automatic tool to make this upgrade, so you must follow these
156
+ manual steps:
157
+
158
+ #. Create a new empty Symfony application (``composer create-project
159
+ symfony/skeleton my-project-flex ``)
160
+
161
+ #. Merge the ``require `` and ``require-dev `` dependencies defined in your
162
+ original project's ``composer.json `` file to the ``composer.json `` file of the
163
+ new project (don't copy the ``symfony/symfony `` dependency, but add the
164
+ relevant components you are effectively using in your project).
165
+
166
+ #. Install the dependencies in the new project executing ``composer install ``.
167
+ This will make Symfony Flex generate all the configuration files in
168
+ ``config/packages/ ``
169
+
155
170
#. Review the generated ``config/packages/*.yaml `` files and make any needed
156
- changes according to the configuration defined in the ``app/config/config_*.yml ``
157
- file of your original project. Beware that this is the most time-consuming
158
- and error-prone step of the upgrade process.
159
- #. Move the original parameters defined in ``app/config/parameters.*.yml `` to the
160
- new ``config/services.yaml `` and ``.env `` files depending on your needs.
171
+ changes according to the configuration defined in the
172
+ ``app/config/config_*.yml `` file of your original project. Beware that this is
173
+ the most time-consuming and error-prone step of the upgrade process.
174
+
175
+ #. Move the original parameters defined in ``app/config/parameters.*.yml `` to
176
+ the new ``config/services.yaml `` and ``.env `` files depending on your needs.
177
+
161
178
#. Move the original source code from ``src/{App,...}Bundle/ `` to ``src/ `` and
162
- update the namespaces of every PHP file (advanced IDEs can do this automatically).
163
- #. Move the original templates from ``templates/ `` to ``templates/ ``
164
- #. Make any other change needed by your application. For example, if your original
165
- ``public/app_*.php `` front controllers were customized, add those changes to the
166
- new ``public/index.php `` controller.
179
+ update the namespaces of every PHP file (advanced IDEs can do this
180
+ automatically).
181
+
182
+ #. Move the original templates from ``app/Resources/views/ `` to ``templates/ ``
183
+
184
+ #. Make any other change needed by your application. For example, if your
185
+ original ``web/app_*.php `` front controllers were customized, add those changes
186
+ to the new ``public/index.php `` controller.
167
187
168
188
.. _`Symfony Flex` : https://github.com/symfony/flex
169
189
.. _`Symfony Installer` : https://github.com/symfony/symfony-installer
190
+ .. _`Symfony Standard Edition` : https://github.com/symfony/symfony-standard
170
191
.. _`Main recipe repository` : https://github.com/symfony/recipes
171
192
.. _`Contrib recipe repository` : https://github.com/symfony/recipes-contrib
172
193
.. _`Symfony Recipes documentation` : https://github.com/symfony/recipes/blob/master/README.rst
0 commit comments