Skip to content

Commit ccd76b1

Browse files
committed
Merge remote-tracking branch 'upstream/6.2' into 6.2
* upstream/6.2: Add the versionadded directive Minor tweak [Kernel] Mention extra interfaces in `MicroKernel` section Minor typo Minor tweaks Minor rewords [Messenger] Add new `messenger:stats` command that return a list of transports with their "to be processed" message count. Minor tweaks [Console] Update console.rst [Uuid] 17258 Add documentation for Uuid 7 and 8 Mailer: remove port 99 for requestbin.com [Testing] Add a section to mock service dependencies document default context for the serializer
2 parents 539c992 + 36dc4e3 commit ccd76b1

File tree

10 files changed

+200
-9
lines changed

10 files changed

+200
-9
lines changed

components/uid.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ to create each type of UUID::
6363
// It's defined in http://gh.peabody.io/uuidv6/
6464
$uuid = Uuid::v6(); // $uuid is an instance of Symfony\Component\Uid\UuidV6
6565

66+
// UUID version 7 features a time-ordered value field derived from the well known
67+
// Unix Epoch timestamp source: the number of seconds since midnight 1 Jan 1970 UTC, leap seconds excluded.
68+
// As well as improved entropy characteristics over versions 1 or 6.
69+
$uuid = Uuid::v7();
70+
71+
// UUID version 8 provides an RFC-compatible format for experimental or vendor-specific use cases.
72+
// The only requirement is that the variant and version bits MUST be set as defined in Section 4:
73+
// https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#variant_and_version_fields
74+
// UUIDv8 uniqueness will be implementation-specific and SHOULD NOT be assumed.
75+
$uuid = Uuid::v8();
76+
77+
.. versionadded:: 6.2
78+
79+
UUID versions 7 and 8 were introduced in Symfony 6.2.
80+
6681
If your UUID value is already generated in another format, use any of the
6782
following methods to create a ``Uuid`` object from it::
6883

configuration/micro_kernel_trait.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@ that define your bundles, your services and your routes:
9999
``RoutingConfigurator`` has methods that make adding routes in PHP more
100100
fun. You can also load external routing files (shown below).
101101

102+
Adding Interfaces to "Micro" Kernel
103+
-----------------------------------
104+
105+
When using the ``MicroKernelTrait``, you can also implement the
106+
``CompilerPassInterface`` to automatically register the kernel itself as a
107+
compiler pass as explained in the dedicated
108+
:ref:`compiler pass section <kernel-as-compiler-pass>`.
109+
110+
It is also possible to implement the ``EventSubscriberInterface`` to handle
111+
events directly from the kernel, again it will be registered automatically::
112+
113+
// ...
114+
use App\Exception\Danger;
115+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
116+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
117+
use Symfony\Component\HttpKernel\KernelEvents;
118+
119+
class Kernel extends BaseKernel implements EventSubscriberInterface
120+
{
121+
use MicroKernelTrait;
122+
123+
// ...
124+
125+
public function onKernelException(ExceptionEvent $event): void
126+
{
127+
if ($event->getException() instanceof Danger) {
128+
$event->setResponse(new Response('It\'s dangerous to go alone. Take this ⚔'));
129+
}
130+
}
131+
132+
public static function getSubscribedEvents(): array
133+
{
134+
return [
135+
KernelEvents::EXCEPTION => 'onKernelException',
136+
];
137+
}
138+
}
139+
102140
Advanced Example: Twig, Annotations and the Web Debug Toolbar
103141
-------------------------------------------------------------
104142

console.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ method, which returns an instance of
334334
$section1->clear(2);
335335
// Output is now completely empty!
336336

337+
// setting the max height of a section will make new lines replace the old ones
338+
$section1->setMaxHeight(2);
339+
$section1->writeln('Line1');
340+
$section1->writeln('Line2');
341+
$section1->writeln('Line3');
342+
337343
return Command::SUCCESS;
338344
}
339345
}
@@ -342,6 +348,10 @@ method, which returns an instance of
342348

343349
A new line is appended automatically when displaying information in a section.
344350

351+
.. versionadded:: 6.2
352+
353+
The feature to limit the height of a console section was introduced in Symfony 6.2.
354+
345355
Output sections let you manipulate the Console output in advanced ways, such as
346356
:ref:`displaying multiple progress bars <console-multiple-progress-bars>` which
347357
are updated independently and :ref:`appending rows to tables <console-modify-rendered-tables>`

mailer.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ Infobip infobip+smtp://KEY@default n/a
202202
203203
# .env
204204
MAILER_DSN=mailgun+https://KEY:DOMAIN@requestbin.com
205-
MAILER_DSN=mailgun+https://KEY:DOMAIN@requestbin.com:99
206205
207206
Note that the protocol is *always* HTTPs and cannot be changed.
208207

messenger.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,35 @@ You can limit the worker to only process messages from specific queue(s):
640640
# you can pass the --queues option more than once to process multiple queues
641641
$ php bin/console messenger:consume my_transport --queues=fasttrack1 --queues=fasttrack2
642642
643-
To allow using the ``queues`` option, the receiver must implement the
644-
:class:`Symfony\\Component\\Messenger\\Transport\\Receiver\\QueueReceiverInterface`.
643+
.. note::
644+
645+
To allow using the ``queues`` option, the receiver must implement the
646+
:class:`Symfony\\Component\\Messenger\\Transport\\Receiver\\QueueReceiverInterface`.
647+
648+
.. _messenger-message-count:
649+
650+
Checking the Number of Queued Messages Per Transport
651+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
652+
653+
Run the ``messenger:stats`` command to know how many messages are in the "queues"
654+
of some or all transports:
655+
656+
.. code-block:: terminal
657+
658+
# displays the number of queued messages in all transports
659+
$ php bin/console messenger:stats
660+
661+
# shows stats only for some transports
662+
$ php bin/console messenger:stats my_transport_name other_transport_name
663+
664+
.. note::
665+
666+
In order for this command to work, the configured transport's receiver must implement
667+
:class:`Symfony\\Component\\Messenger\\Transport\\Receiver\\MessageCountAwareInterface`.
668+
669+
.. versionadded:: 6.2
670+
671+
The ``messenger:stats`` command was introduced in Symfony 6.2.
645672

646673
.. _messenger-supervisor:
647674

reference/configuration/framework.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,9 @@ A map with default context options that will be used with each ``serialize`` and
27642764
call. This can be used for example to set the json encoding behavior by setting ``json_encode_options``
27652765
to a `json_encode flags bitmask`_.
27662766

2767+
You can inspect the :ref:`serializer context builders <serializer-using-context-builders>`
2768+
to discover the available settings.
2769+
27672770
php_errors
27682771
~~~~~~~~~~
27692772

reference/constraints/Uuid.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,24 @@ will allow alternate input formats like:
112112
``versions``
113113
~~~~~~~~~~~~
114114

115-
**type**: ``int[]`` **default**: ``[1,2,3,4,5,6]``
115+
**type**: ``int[]`` **default**: ``[1,2,3,4,5,6,7,8]``
116116

117-
This option can be used to only allow specific `UUID versions`_. Valid versions are 1 - 6.
118-
The following PHP constants can also be used:
117+
This option can be used to only allow specific `UUID versions`_ (by default, all
118+
of them are allowed). Valid versions are 1 - 8. Instead of using numeric values,
119+
you can also use the following PHP constants to refer to each UUID version:
119120

120121
* ``Uuid::V1_MAC``
121122
* ``Uuid::V2_DCE``
122123
* ``Uuid::V3_MD5``
123124
* ``Uuid::V4_RANDOM``
124125
* ``Uuid::V5_SHA1``
125126
* ``Uuid::V6_SORTABLE``
127+
* ``Uuid::V7_MONOTONIC``
128+
* ``Uuid::V8_CUSTOM``
126129

127-
All six versions are allowed by default.
130+
.. versionadded:: 6.2
131+
132+
UUID versions 7 and 8 were introduced in Symfony 6.2.
128133

129134
.. _`Universally unique identifier (UUID)`: https://en.wikipedia.org/wiki/Universally_unique_identifier
130135
.. _`RFC 4122`: https://tools.ietf.org/html/rfc4122

serializer.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ configuration:
130130
serializer:
131131
default_context:
132132
enable_max_depth: true
133+
yaml_indentation: 2
133134
134135
.. code-block:: xml
135136
136137
<!-- config/packages/framework.xml -->
137138
<framework:config>
138139
<!-- ... -->
139140
<framework:serializer>
140-
<default-context enable-max-depth="true"/>
141+
<default-context enable-max-depth="true" yaml-indentation="2"/>
141142
</framework:serializer>
142143
</framework:config>
143144
@@ -146,15 +147,21 @@ configuration:
146147
// config/packages/framework.php
147148
use Symfony\Config\FrameworkConfig;
148149
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
150+
use Symfony\Component\Serializer\Encoder\YamlEncoder;
149151
150152
return static function (FrameworkConfig $framework) {
151153
$framework->serializer()
152154
->defaultContext([
153-
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true
155+
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true,
156+
YamlEncoder::YAML_INDENTATION => 2,
154157
])
155158
;
156159
};
157160
161+
.. versionadded:: 6.2
162+
163+
The option to configure YAML indentation was introduced in Symfony 6.2.
164+
158165
.. _serializer-using-context-builders:
159166

160167
Using Context Builders

service_container/compiler_passes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Compiler passes are registered in the ``build()`` method of the application kern
3232
}
3333
}
3434

35+
.. _kernel-as-compiler-pass:
36+
3537
One of the most common use-cases of compiler passes is to work with :doc:`tagged
3638
services </service_container/tags>`. In those cases, instead of creating a
3739
compiler pass, you can make the kernel implement

testing.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,91 @@ It gives you access to both the public services and the non-removed
281281
are not used by any other services), you need to declare those private
282282
services as public in the ``config/services_test.yaml`` file.
283283

284+
Mocking Dependencies
285+
--------------------
286+
287+
Sometimes it can be useful to mock a dependency of a tested service.
288+
From the example in the previous section, let's assume the
289+
``NewsletterGenerator`` has a dependency to a private alias
290+
``NewsRepositoryInterface`` pointing to a private ``NewsRepository`` service
291+
and you'd like to use a mocked ``NewsRepositoryInterface`` instead of the
292+
concrete one::
293+
294+
// ...
295+
use App\Contracts\Repository\NewsRepositoryInterface;
296+
297+
class NewsletterGeneratorTest extends KernelTestCase
298+
{
299+
public function testSomething()
300+
{
301+
// ... same bootstrap as the section above
302+
303+
$newsRepository = $this->createMock(NewsRepositoryInterface::class);
304+
$newsRepository->expects(self::once())
305+
->method('findNewsFromLastMonth')
306+
->willReturn([
307+
new News('some news'),
308+
new News('some other news'),
309+
])
310+
;
311+
312+
// the following line won't work unless the alias is made public
313+
$container->set(NewsRepositoryInterface::class, $newsRepository);
314+
315+
// will be injected the mocked repository
316+
$newsletterGenerator = $container->get(NewsletterGenerator::class);
317+
318+
// ...
319+
}
320+
}
321+
322+
In order to make the alias public, you will need to update configuration for
323+
the ``test`` environment as follows:
324+
325+
.. configuration-block::
326+
327+
.. code-block:: yaml
328+
329+
# config/services_test.yaml
330+
services:
331+
# redefine the alias as it should be while making it public
332+
App\Contracts\Repository\NewsRepositoryInterface:
333+
alias: App\Repository\NewsRepository
334+
public: true
335+
336+
.. code-block:: xml
337+
338+
<!-- config/services_test.xml -->
339+
<?xml version="1.0" encoding="UTF-8" ?>
340+
<container xmlns="http://symfony.com/schema/dic/services"
341+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
342+
xsi:schemaLocation="http://symfony.com/schema/dic/services
343+
https://symfony.com/schema/dic/services/services-1.0.xsd
344+
">
345+
<services>
346+
<!-- redefine the alias as it should be while making it public -->
347+
<service id="App\Contracts\Repository\NewsRepositoryInterface"
348+
alias="App\Repository\NewsRepository"
349+
/>
350+
</services>
351+
</container>
352+
353+
.. code-block:: php
354+
355+
// config/services_test.php
356+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
357+
358+
use App\Contracts\Repository\NewsRepositoryInterface;
359+
use App\Repository\NewsRepository;
360+
361+
return static function (ContainerConfigurator $container) {
362+
$container->services()
363+
// redefine the alias as it should be while making it public
364+
->alias(NewsRepositoryInterface::class, NewsRepository::class)
365+
->public()
366+
;
367+
};
368+
284369
.. _testing-databases:
285370

286371
Configuring a Database for Tests

0 commit comments

Comments
 (0)