Skip to content

Commit 6a9e519

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Correcting reference to `isSuccessful` method for Process Update custom_constraint.rst Minor fix Fixed typo Discourage the use of controllers as services Add constants to BC promise Remove complex DI extension information and link the cookbook article instead Trying to remove some duplication and some extra details
2 parents 113cbbc + 379616a commit 6a9e519

File tree

9 files changed

+111
-170
lines changed

9 files changed

+111
-170
lines changed

book/controller.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,6 @@ that's available to you with or without the use of the base
399399
action is to look in the
400400
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class.
401401

402-
.. seealso::
403-
404-
If you're curious about how a controller would work that did *not*
405-
extend this base ``Controller`` class, check out cookbook article
406-
:doc:`Controllers as Services </cookbook/controller/service>`.
407-
This is optional, but can give you more control over the exact
408-
objects/dependencies that are injected into your controller.
409-
410402
.. index::
411403
single: Controller; Redirecting
412404

book/service_container.rst

Lines changed: 53 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ later how you can configure a service that has multiple instances in the
152152
In this example, the controller extends Symfony's base Controller, which
153153
gives you access to the service container itself. You can then use the
154154
``get`` method to locate and retrieve the ``app.mailer`` service from
155-
the service container. You can also define your :doc:`controllers as services </cookbook/controller/service>`.
156-
This is a bit more advanced and not necessary, but it allows you to inject
157-
only the services you need into your controller.
155+
the service container.
158156

159157
.. _book-service-container-parameters:
160158

@@ -277,10 +275,10 @@ be imported from inside this file in one way or another. This gives you absolute
277275
flexibility over the services in your application.
278276

279277
External service configuration can be imported in two different ways. The first
280-
method, commonly used to import container configuration from the bundles you've
281-
created - is via the ``imports`` directive. The second method, although slightly more
282-
complex offers more flexibility and is commonly used to import third-party bundle
283-
configuration. Read on to learn more about both methods.
278+
method, commonly used to import other resources, is via the ``imports``
279+
directive. The second method, using dependency injection extensions, is used by
280+
third-party bundles to load the configuration. Read on to learn more about both
281+
methods.
284282

285283
.. index::
286284
single: Service Container; Imports
@@ -291,20 +289,16 @@ Importing Configuration with ``imports``
291289
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292290

293291
So far, you've placed your ``app.mailer`` service container definition directly
294-
in the application configuration file (e.g. ``app/config/config.yml``). Of
295-
course, since the ``Mailer`` class itself lives inside the AppBundle, it
296-
makes more sense to put the ``app.mailer`` container definition inside the
297-
bundle as well.
298-
299-
First, move the ``app.mailer`` container definition into a new container resource
300-
file inside AppBundle. If the ``Resources`` or ``Resources/config``
301-
directories don't exist, create them.
292+
in the services configuration file (e.g. ``app/config/services.yml``). If your
293+
application ends up having many services, this file becomes huge and hard to
294+
maintain. To avoid this, you can split your service configuration into multiple
295+
service files:
302296

303297
.. configuration-block::
304298

305299
.. code-block:: yaml
306300
307-
# src/AppBundle/Resources/config/services.yml
301+
# app/config/services/mailer.yml
308302
parameters:
309303
app.mailer.transport: sendmail
310304
@@ -315,7 +309,7 @@ directories don't exist, create them.
315309
316310
.. code-block:: xml
317311
318-
<!-- src/AppBundle/Resources/config/services.xml -->
312+
<!-- app/config/services/mailer.xml -->
319313
<?xml version="1.0" encoding="UTF-8" ?>
320314
<container xmlns="http://symfony.com/schema/dic/services"
321315
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -335,7 +329,7 @@ directories don't exist, create them.
335329
336330
.. code-block:: php
337331
338-
// src/AppBundle/Resources/config/services.php
332+
// app/config/services/mailer.php
339333
use Symfony\Component\DependencyInjection\Definition;
340334
341335
$container->setParameter('app.mailer.transport', 'sendmail');
@@ -345,46 +339,42 @@ directories don't exist, create them.
345339
array('%app.mailer.transport%')
346340
));
347341
348-
The definition itself hasn't changed, only its location. Of course the service
349-
container doesn't know about the new resource file. Fortunately, you can
350-
easily import the resource file using the ``imports`` key in the application
351-
configuration.
342+
The definition itself hasn't changed, only its location. To make the service
343+
container load the definitions in this resource file, use the ``imports`` key
344+
in any already loaded resource (e.g. ``app/config/services.yml`` or
345+
``app/config/config.yml``):
352346

353347
.. configuration-block::
354348

355349
.. code-block:: yaml
356350
357-
# app/config/config.yml
351+
# app/config/services.yml
358352
imports:
359-
- { resource: '@AppBundle/Resources/config/services.yml' }
353+
- { resource: services/mailer.yml }
360354
361355
.. code-block:: xml
362356
363-
<!-- app/config/config.xml -->
357+
<!-- app/config/services.xml -->
364358
<?xml version="1.0" encoding="UTF-8" ?>
365359
<container xmlns="http://symfony.com/schema/dic/services"
366360
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
367361
xsi:schemaLocation="http://symfony.com/schema/dic/services
368362
http://symfony.com/schema/dic/services/services-1.0.xsd">
369363
370364
<imports>
371-
<import resource="@AppBundle/Resources/config/services.xml"/>
365+
<import resource="services/mailer.xml"/>
372366
</imports>
373367
</container>
374368
375369
.. code-block:: php
376370
377-
// app/config/config.php
378-
$loader->import('@AppBundle/Resources/config/services.php');
371+
// app/config/services.php
372+
$loader->import('services/mailer.php');
379373
380-
.. include:: /components/dependency_injection/_imports-parameters-note.rst.inc
374+
The ``resource`` location, for files, is either a relative path from the
375+
current file or an absolute path.
381376

382-
The ``imports`` directive allows your application to include service container
383-
configuration resources from any other location (most commonly from bundles).
384-
The ``resource`` location, for files, is the absolute path to the resource
385-
file. The special ``@AppBundle`` syntax resolves the directory path
386-
of the AppBundle bundle. This helps you specify the path to the resource
387-
without worrying later if you move the AppBundle to a different directory.
377+
.. include:: /components/dependency_injection/_imports-parameters-note.rst.inc
388378

389379
.. index::
390380
single: Service Container; Extension configuration
@@ -394,31 +384,14 @@ without worrying later if you move the AppBundle to a different directory.
394384
Importing Configuration via Container Extensions
395385
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
396386

397-
When developing in Symfony, you'll most commonly use the ``imports`` directive
398-
to import container configuration from the bundles you've created specifically
399-
for your application. Third-party bundle container configuration, including
400-
Symfony core services, are usually loaded using another method that's more
401-
flexible and easy to configure in your application.
402-
403-
Here's how it works. Internally, each bundle defines its services very much
404-
like you've seen so far. Namely, a bundle uses one or more configuration
405-
resource files (usually XML) to specify the parameters and services for that
406-
bundle. However, instead of importing each of these resources directly from
407-
your application configuration using the ``imports`` directive, you can simply
408-
invoke a *service container extension* inside the bundle that does the work for
409-
you. A service container extension is a PHP class created by the bundle author
410-
to accomplish two things:
411-
412-
* import all service container resources needed to configure the services for
413-
the bundle;
387+
Third-party bundle container configuration, including Symfony core services,
388+
are usually loaded using another method that's more flexible and easy to
389+
configure in your application.
414390

415-
* provide semantic, straightforward configuration so that the bundle can
416-
be configured without interacting with the flat parameters of the bundle's
417-
service container configuration.
418-
419-
In other words, a service container extension configures the services for
420-
a bundle on your behalf. And as you'll see in a moment, the extension provides
421-
a sensible, high-level interface for configuring the bundle.
391+
Internally, each bundle defines its services like you've seen so far. However,
392+
these files aren't imported using the ``import`` directive. These bundles use a
393+
*dependency injection extension* to load the files. The extension also allows
394+
bundles to provide configuration to dynamically load some services.
422395

423396
Take the FrameworkBundle - the core Symfony Framework bundle - as an
424397
example. The presence of the following code in your application configuration
@@ -430,10 +403,8 @@ invokes the service container extension inside the FrameworkBundle:
430403
431404
# app/config/config.yml
432405
framework:
433-
secret: xxxxxxxxxx
434-
form: true
435-
csrf_protection: true
436-
router: { resource: '%kernel.root_dir%/config/routing.yml' }
406+
secret: xxxxxxxxxx
407+
form: true
437408
# ...
438409
439410
.. code-block:: xml
@@ -443,15 +414,13 @@ invokes the service container extension inside the FrameworkBundle:
443414
<container xmlns="http://symfony.com/schema/dic/services"
444415
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
445416
xmlns:framework="http://symfony.com/schema/dic/symfony"
446-
xsi:schemaLocation="http://symfony.com/schema/dic/services
447-
http://symfony.com/schema/dic/services/services-1.0.xsd
448-
http://symfony.com/schema/dic/symfony
449-
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
417+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
418+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
419+
>
450420
451421
<framework:config secret="xxxxxxxxxx">
452422
<framework:form />
453-
<framework:csrf-protection />
454-
<framework:router resource="%kernel.root_dir%/config/routing.xml" />
423+
455424
<!-- ... -->
456425
</framework>
457426
</container>
@@ -460,51 +429,31 @@ invokes the service container extension inside the FrameworkBundle:
460429
461430
// app/config/config.php
462431
$container->loadFromExtension('framework', array(
463-
'secret' => 'xxxxxxxxxx',
464-
'form' => array(),
465-
'csrf-protection' => array(),
466-
'router' => array(
467-
'resource' => '%kernel.root_dir%/config/routing.php',
468-
),
432+
'secret' => 'xxxxxxxxxx',
433+
'form' => array(),
469434
470435
// ...
471436
));
472437
473-
When the configuration is parsed, the container looks for an extension that
474-
can handle the ``framework`` configuration directive. The extension in question,
475-
which lives in the FrameworkBundle, is invoked and the service configuration
476-
for the FrameworkBundle is loaded. If you remove the ``framework`` key
477-
from your application configuration file entirely, the core Symfony services
478-
won't be loaded. The point is that you're in control: the Symfony Framework
479-
doesn't contain any magic or perform any actions that you don't have control
480-
over.
481-
482-
Of course you can do much more than simply "activate" the service container
483-
extension of the FrameworkBundle. Each extension allows you to easily
484-
customize the bundle, without worrying about how the internal services are
485-
defined.
486-
487-
In this case, the extension allows you to customize the ``error_handler``,
488-
``csrf_protection``, ``router`` configuration and much more. Internally,
489-
the FrameworkBundle uses the options specified here to define and configure
490-
the services specific to it. The bundle takes care of creating all the necessary
491-
``parameters`` and ``services`` for the service container, while still allowing
492-
much of the configuration to be easily customized. As a bonus, most
493-
service container extensions are also smart enough to perform validation -
494-
notifying you of options that are missing or the wrong data type.
438+
When the resources are parsed, the container looks for an extension that
439+
can handle the ``framework`` directive. The extension in question, which lives
440+
in the FrameworkBundle, is invoked and the service configuration for the
441+
FrameworkBundle is loaded.
442+
443+
The settings under the ``framework`` directive (e.g. ``form: true``) indicate
444+
that the extension should load all services related to the Form component. If
445+
form was disabled, these services wouldn't be loaded and Form integration would
446+
not be available.
495447

496448
When installing or configuring a bundle, see the bundle's documentation for
497449
how the services for the bundle should be installed and configured. The options
498450
available for the core bundles can be found inside the :doc:`Reference Guide </reference/index>`.
499451

500-
.. note::
501-
502-
Natively, the service container only recognizes the ``parameters``,
503-
``services``, and ``imports`` directives. Any other directives
504-
are handled by a service container extension.
452+
.. seealso::
505453

506-
If you want to expose user friendly configuration in your own bundles, read the
507-
":doc:`/cookbook/bundles/extension`" cookbook recipe.
454+
If you want to use dependency injection extensions in your own shared
455+
bundles and provide user friendly configuration, take a look at the
456+
":doc:`/cookbook/bundles/extension`" cookbook recipe.
508457

509458
.. index::
510459
single: Service Container; Referencing services

components/console/helpers/debug_formatter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ notify this to the users::
122122
$debugFormatter->stop(
123123
spl_object_hash($process),
124124
'Some command description',
125-
$process->isSuccessfull()
125+
$process->isSuccessful()
126126
)
127127
);
128128

components/http_kernel/introduction.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ will be called after another event - ``kernel.controller`` - is dispatched.
264264
is passed to it. This step is also specific to the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver`
265265
sub-class used by the Symfony Framework.
266266

267-
There are also a few other variations on the above process (e.g. if
268-
you're registering your controllers as services).
269-
270267
.. _component-http-kernel-kernel-controller:
271268

272269
3) The ``kernel.controller`` Event

contributing/code/bc.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ Add type hint to an argument No
165165
Remove type hint of an argument No
166166
Change argument type No
167167
Change return type No
168+
**Constants**
169+
Add constant Yes
170+
Remove constant No
171+
Change value of a constant Yes [1]_ [5]_
168172
============================================== ==============
169173

170174
Changing Classes
@@ -248,6 +252,10 @@ Change return type Yes
248252
**Static Methods**
249253
Turn non static into static No
250254
Turn static into non static No
255+
**Constants**
256+
Add constant Yes
257+
Remove constant No
258+
Change value of a constant Yes [1]_ [5]_
251259
================================================== ==============
252260

253261
.. [1] Should be avoided. When done, this change must be documented in the
@@ -262,6 +270,13 @@ Turn static into non static No
262270
.. [4] When changing the parent class, the original parent class must remain an
263271
ancestor of the class.
264272
273+
.. [5] The value of a constant may only be changed when the constants aren't
274+
used in configuration (e.g. Yaml and XML files), as these do not support
275+
constants and have to hardcode the value. For instance, event name
276+
constants can't change the value without introducing a BC break.
277+
Additionally, if a constant will likely be used in objects that are
278+
serialized, the value of a constant should not be changed.
279+
265280
.. _Semantic Versioning: http://semver.org/
266281
.. _scalar type: http://php.net/manual/en/function.is-scalar.php
267282
.. _boolean values: http://php.net/manual/en/function.boolval.php

0 commit comments

Comments
 (0)