Skip to content

Commit 64bda4b

Browse files
committed
Merge branch '4.1'
* 4.1: [symfony#10545] minor tweaks for the example Update form.rst [Messenger] Improve the Messenger Handler Example fix directory tree markup Update service_decoration.rst Rename content_type header to content-type Reduce potential confusion in priority explanation Update configuration_organization.rst [standards] Document "phpdoc_types_order"
2 parents a80fced + b9768c7 commit 64bda4b

File tree

9 files changed

+71
-38
lines changed

9 files changed

+71
-38
lines changed

components/event_dispatcher.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,10 @@ The ``addListener()`` method takes up to three arguments:
146146

147147
#. The event name (string) that this listener wants to listen to;
148148
#. A PHP callable that will be executed when the specified event is dispatched;
149-
#. An optional priority integer (higher equals more important and therefore
150-
that the listener will be triggered earlier) that determines when a listener
151-
is triggered versus other listeners (defaults to ``0``). If two listeners
152-
have the same priority, they are executed in the order that they were
153-
added to the dispatcher.
149+
#. An optional priority, defined as a positive or negative integer (defaults to
150+
``0``). The higher the priority, the earlier the listener is called. If two
151+
listeners have the same priority, they are executed in the order that they
152+
were added to the dispatcher.
154153

155154
.. note::
156155

components/form.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ the CSRF generator and validated when binding the form.
155155
$csrfStorage = new NativeSessionTokenStorage();
156156
// ...
157157

158+
You can disable CSRF protection per form using the ``csrf_protection`` option::
159+
160+
use Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType
161+
162+
$form = $formFactory->createBuilder(FormType::class, null, ['csrf_protection' => false])
163+
->getForm();
164+
158165
Twig Templating
159166
~~~~~~~~~~~~~~~
160167

configuration/configuration_organization.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ this structure:
4949
5050
your-project/
5151
├─ config/
52-
─ packages/
53-
├─ dev/
54-
| │ ├─ framework.yaml
55-
│ └─ ...
56-
├─ prod/
57-
│ └─ ...
58-
├─ test/
59-
│ └─ ...
60-
| ├─ framework.yaml
61-
└─ ...
62-
├─ services.yaml
63-
└─ services_dev.yaml
52+
─ packages/
53+
├─ dev/
54+
│ │ │ ├─ framework.yaml
55+
│ └─ ...
56+
├─ prod/
57+
│ └─ ...
58+
├─ test/
59+
│ └─ ...
60+
│ │ ├─ framework.yaml
61+
└─ ...
62+
│ ├─ services.yaml
63+
│ └─ services_dev.yaml
6464
├─ ...
6565
6666
This default structure was chosen for its simplicity — one file per package and

contributing/code/standards.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ Structure
194194

195195
* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor;
196196

197-
* Add a ``use`` statement for every class that is not part of the global namespace.
197+
* Add a ``use`` statement for every class that is not part of the global namespace;
198+
199+
* When PHPDoc tags like ``@param`` or ``@return`` include ``null`` and other
200+
types, always place ``null`` at the end of the list of types.
198201

199202
Naming Conventions
200203
~~~~~~~~~~~~~~~~~~

controller.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ the ``Request`` class::
522522

523523
// retrieves an HTTP request header, with normalized, lowercase keys
524524
$request->headers->get('host');
525-
$request->headers->get('content_type');
525+
$request->headers->get('content-type');
526526
}
527527

528528
The ``Request`` class has several public properties and methods that return any

create_framework/http_foundation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fingertips thanks to a nice and simple API::
192192

193193
// retrieve an HTTP request header, with normalized, lowercase keys
194194
$request->headers->get('host');
195-
$request->headers->get('content_type');
195+
$request->headers->get('content-type');
196196

197197
$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
198198
$request->getLanguages(); // an array of languages the client accepts

introduction/http_fundamentals.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ have all the request information at your fingertips::
231231

232232
// retrieves an HTTP request header, with normalized, lowercase keys
233233
$request->headers->get('host');
234-
$request->headers->get('content_type');
234+
$request->headers->get('content-type');
235235

236236
$request->getMethod(); // e.g. GET, POST, PUT, DELETE or HEAD
237237
$request->getLanguages(); // an array of languages the client accepts

messenger.rst

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ install messenger before using it:
1919
2020
$ composer require messenger
2121
22+
Message
23+
-------
24+
25+
Before you can send a message, you must create it first. There is no specific
26+
requirement for a message, except it should be serializable and unserializable
27+
by a Symfony Serializer instance::
28+
29+
// src/Message/SmsNotification.php
30+
namespace App\Message;
31+
32+
class SmsNotification
33+
{
34+
private $content;
35+
36+
public function __construct(string $content)
37+
{
38+
$this->content = $content;
39+
}
40+
41+
// ...getters
42+
}
43+
2244
Using the Messenger Service
2345
---------------------------
2446

@@ -28,15 +50,15 @@ you need it, like in a controller::
2850
// src/Controller/DefaultController.php
2951
namespace App\Controller;
3052

31-
use App\Message\SendNotification;
53+
use App\Message\SmsNotification;
3254
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
3355
use Symfony\Component\Messenger\MessageBusInterface;
3456

3557
class DefaultController extends AbstractController
3658
{
3759
public function index(MessageBusInterface $bus)
3860
{
39-
$bus->dispatch(new SendNotification('A string to be sent...'));
61+
$bus->dispatch(new SmsNotification('A string to be sent...'));
4062
}
4163
}
4264

@@ -46,14 +68,15 @@ Registering Handlers
4668
In order to do something when your message is dispatched, you need to create a
4769
message handler. It's a class with an ``__invoke`` method::
4870

49-
// src/MessageHandler/MyMessageHandler.php
71+
// src/MessageHandler/SmsNotificationHandler.php
5072
namespace App\MessageHandler;
5173

74+
use App\Message\SmsNotification;
5275
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
5376

54-
class MyMessageHandler implements MessageHandlerInterface
77+
class SmsNotificationHandler implements MessageHandlerInterface
5578
{
56-
public function __invoke(MyMessage $message)
79+
public function __invoke(SmsNotification $message)
5780
{
5881
// do something with it.
5982
}
@@ -74,7 +97,7 @@ If you're not using service autoconfiguration, then you need to add this config:
7497
7598
# config/services.yaml
7699
services:
77-
App\MessageHandler\MyMessageHandler:
100+
App\MessageHandler\SmsNotificationHandler:
78101
tags: [messenger.message_handler]
79102
80103
.. code-block:: xml
@@ -87,7 +110,7 @@ If you're not using service autoconfiguration, then you need to add this config:
87110
http://symfony.com/schema/dic/services/services-1.0.xsd">
88111
89112
<services>
90-
<service id="App\MessageHandler\MyMessageHandler">
113+
<service id="App\MessageHandler\SmsNotificationHandler">
91114
<tag name="messenger.message_handler" />
92115
</service>
93116
</services>
@@ -96,9 +119,9 @@ If you're not using service autoconfiguration, then you need to add this config:
96119
.. code-block:: php
97120
98121
// config/services.php
99-
use App\MessageHandler\MyMessageHandler;
122+
use App\MessageHandler\SmsNotificationHandler;
100123
101-
$container->register(MyMessageHandler::class)
124+
$container->register(SmsNotificationHandler::class)
102125
->addTag('messenger.message_handler');
103126
104127
.. note::

service_container/service_decoration.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
How to Decorate Services
55
========================
66

7-
When overriding an existing definition (e.g. when applying the `Decorator pattern`_),
8-
the original service is lost:
7+
When overriding an existing definition, the original service is lost:
98

109
.. configuration-block::
1110

@@ -18,7 +17,7 @@ the original service is lost:
1817
# this replaces the old App\Mailer definition with the new one, the
1918
# old definition is lost
2019
App\Mailer:
21-
class: App\DecoratingMailer
20+
class: App\NewMailer
2221
2322
.. code-block:: xml
2423
@@ -33,25 +32,27 @@ the original service is lost:
3332
3433
<!-- this replaces the old App\Mailer definition with the new
3534
one, the old definition is lost -->
36-
<service id="App\Mailer" class="App\DecoratingMailer" />
35+
<service id="App\Mailer" class="App\NewMailer" />
3736
</services>
3837
</container>
3938
4039
.. code-block:: php
4140
4241
// config/services.php
4342
use App\Mailer;
44-
use App\DecoratingMailer;
43+
use App\NewMailer;
4544
4645
$container->register(Mailer::class);
4746
4847
// this replaces the old App\Mailer definition with the new one, the
4948
// old definition is lost
50-
$container->register(Mailer::class, DecoratingMailer::class);
49+
$container->register(Mailer::class, NewMailer::class);
5150
5251
Most of the time, that's exactly what you want to do. But sometimes,
53-
you might want to decorate the old service instead and keep the old service so
54-
that you can reference it:
52+
you might want to decorate the old one instead (i.e. apply the `Decorator pattern`_).
53+
In this case, the old service should be kept around to be able to reference
54+
it in the new one. This configuration replaces ``App\Mailer`` with a new one,
55+
but keeps a reference of the old one as ``App\DecoratingMailer.inner``:
5556

5657
.. configuration-block::
5758

0 commit comments

Comments
 (0)