Skip to content

Commit c7ade79

Browse files
committed
Merge branch '2.1'
2 parents ab0fb08 + e741967 commit c7ade79

File tree

9 files changed

+113
-6
lines changed

9 files changed

+113
-6
lines changed

book/forms.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ controller::
214214
->add('dueDate', 'date')
215215
->getForm();
216216

217-
if ($request->getMethod() == 'POST') {
217+
if ($request->isMethod('POST')) {
218218
$form->bind($request);
219219

220220
if ($form->isValid()) {
@@ -1481,7 +1481,7 @@ an array of the submitted data. This is actually really easy::
14811481
->add('message', 'textarea')
14821482
->getForm();
14831483

1484-
if ($request->getMethod() == 'POST') {
1484+
if ($request->isMethod('POST')) {
14851485
$form->bind($request);
14861486

14871487
// data is an array with "name", "email", and "message" keys

book/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ workflow looks like the following from inside a controller::
225225
$author = new Author();
226226
$form = $this->createForm(new AuthorType(), $author);
227227

228-
if ($request->getMethod() == 'POST') {
228+
if ($request->isMethod('POST')) {
229229
$form->bind($request);
230230

231231
if ($form->isValid()) {

components/config/definition.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ The root node itself is an array node, and has children, like the boolean
9191
node ``auto_connect`` and the scalar node ``default_connection``. In general:
9292
after defining a node, a call to ``end()`` takes you one step up in the hierarchy.
9393

94+
Node type
95+
~~~~~~~~~
96+
97+
It is possible to validate the type of a provided value by using the appropriate
98+
node definition. Node type are available for:
99+
100+
* scalar
101+
* boolean
102+
* array
103+
* variable (no validation)
104+
105+
and are created with ``node($name, $type)`` or their associated shortcut
106+
``xxxxNode($name)`` method.
107+
94108
Array nodes
95109
~~~~~~~~~~~
96110

components/dependency_injection/compilation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ validity, further compiler passes are used to optimize the configuration
2222
before it is cached. For example, private services and abstract services
2323
are removed, and aliases are resolved.
2424

25+
.. _components-dependency-injection-extension:
26+
2527
Managing Configuration with Extensions
2628
--------------------------------------
2729

@@ -238,6 +240,8 @@ but also load a secondary one only if a certain parameter is set::
238240
You should instead use a compiler pass which works with the full container
239241
after the extensions have been processed.
240242

243+
.. _components-dependency-injection-compiler-passes:
244+
241245
Creating a Compiler Pass
242246
------------------------
243247

@@ -307,6 +311,8 @@ For example, to run your custom pass after the default removal passes have been
307311
$container = new ContainerBuilder();
308312
$container->addCompilerPass(new CustomCompilerPass, PassConfig::TYPE_AFTER_REMOVING);
309313

314+
.. _components-dependency-injection-dumping:
315+
310316
Dumping the Configuration for Performance
311317
-----------------------------------------
312318

components/dependency_injection/introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ difficult to reuse the class elsewhere.
194194
You will need to get a service from the container at some point but this
195195
should be as few times as possible at the entry point to your application.
196196

197+
.. _components-dependency-injection-loading-config:
198+
197199
Setting Up the Container with Configuration Files
198200
-------------------------------------------------
199201

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. index::
2+
single: Dependency Injection; Workflow
3+
4+
Container Building Workflow
5+
===========================
6+
7+
In the preceding pages of this section, there has been little to say about
8+
where the various files and classes should be located. This is because this
9+
depends on the application, library or framework in which you want to use
10+
the container. Looking at how the container is configured and built in the
11+
Symfony2 full stack framework will help you see how this all fits together,
12+
whether you are using the full stack framework or looking to use the service
13+
container in another application.
14+
15+
The full stack framework uses the ``HttpKernel`` component to manage the loading
16+
of the service container configuration from the application and bundles and
17+
also handles the compilation and caching. Even if you are not using ``HttpKernel``,
18+
it should give you an idea of one way of organizing configuration in a modular
19+
application.
20+
21+
Working with cached Container
22+
-----------------------------
23+
24+
Before building it, the kernel checks to see if a cached version of the container
25+
exists. The ``HttpKernel`` has a debug setting and if this is false, the
26+
cached version is used if it exists. If debug is true then the kernel
27+
:doc:`checks to see if configuration is fresh<components/config/caching>`
28+
and if it is, the cached version of the container is. If not then the container
29+
is built from the application-level configuration and the bundles's extension
30+
configuration.
31+
32+
Read :ref:`Dumping the Configuration for Performance<components-dependency-injection-dumping>`
33+
for more details.
34+
35+
Application-level Configuration
36+
-------------------------------
37+
38+
Application level config is loaded from the ``app/config`` directory. Multiple
39+
files are loaded which are then merged when the extensions are processed. This
40+
allows for different configuration for different environments e.g. dev, prod.
41+
42+
These files contain parameters and services that are loaded directly into
43+
the container as per :ref:`Setting Up the Container with Configuration Files<components-dependency-injection-loading-config>`.
44+
They also contain configuration that is processed by extensions as per
45+
:ref:`Managing Configuration with Extensions<components-dependency-injection-extension>`.
46+
These are considered to be bundle configuration since each bundle contains
47+
an Extension class.
48+
49+
Bundle-level Configuration with Extensions
50+
------------------------------------------
51+
52+
By convention, each bundle contains an Extension class which is in the bundle's
53+
``DependencyInjection`` directory. These are registered with the ``ContainerBuilder``
54+
when the kernel is booted. When the ``ContainerBuilder`` is :doc:`compiled<components/dependency-injection/compilation>`,
55+
the application-level configuration relevant to the bundle's extension is
56+
passed to the Extension which also usually loads its own config file(s), typically from the bundle's
57+
``Resources/config`` directory. The application-level config is usually processed
58+
with a :doc:`Configuration object<components/config/definition>` also stored
59+
in the bundle's ``DependencyInjection`` directory.
60+
61+
Compiler passes to allow Interaction between Bundles
62+
----------------------------------------------------
63+
64+
:ref:`Compiler passes<components-dependency-injection-compiler-passes>` are
65+
used to allow interaction between different bundles as they cannot affect
66+
each others configuration in the extension classes. One of the main uses is
67+
to process tagged services, allowing bundles to register services to picked
68+
up by other bundles, such as Monolog loggers, Twig extensions and Data Collectors
69+
for the Web Profiler. Compiler passes are usually placed in the bundle's
70+
``DependencyInjection/Compiler`` directory.
71+
72+
Compilation and Caching
73+
-----------------------
74+
75+
After the compilation process has loaded the services from the configuration,
76+
extensions and the compiler passes, it is dumped so that the cache can be used
77+
next time. The dumped version is then used during subsequent request as it
78+
is more efficient.

cookbook/doctrine/file_uploads.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The following controller shows you how to handle the entire process::
151151
->getForm()
152152
;
153153

154-
if ($this->getRequest()->getMethod() === 'POST') {
154+
if ($this->getRequest()->isMethod('POST')) {
155155
$form->bind($this->getRequest());
156156
if ($form->isValid()) {
157157
$em = $this->getDoctrine()->getManager();

cookbook/doctrine/reverse_engineering.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ The generated ``BlogPost.dcm.xml`` metadata file looks as follows:
9292
</entity>
9393
</doctrine-mapping>
9494
95+
.. note::
96+
97+
If you have ``oneToMany`` relationships between your entities,
98+
you will need to edit the generated ``xml`` or ``yml`` files to add
99+
a section on the specific entities for ``oneToMany`` defining the
100+
``inversedBy`` and the ``mappedBy`` pieces.
101+
95102
Once the metadata files are generated, you can ask Doctrine to import the
96103
schema and build related entity classes by executing the following two commands.
97104

cookbook/form/form_collections.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``::
177177
$form = $this->createForm(new TaskType(), $task);
178178

179179
// process the form on POST
180-
if ('POST' === $request->getMethod()) {
180+
if ($request->isMethod('POST')) {
181181
$form->bind($request);
182182
if ($form->isValid()) {
183183
// maybe do some form processing, like saving the Task and Tag objects
@@ -610,7 +610,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
610610
611611
$editForm = $this->createForm(new TaskType(), $task);
612612

613-
if ('POST' === $request->getMethod()) {
613+
if ($request->isMethod('POST')) {
614614
$editForm->bind($this->getRequest());
615615

616616
if ($editForm->isValid()) {

0 commit comments

Comments
 (0)