Skip to content

Commit 3248d3a

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: [DependencyInjection] Complete examples with TaggedIterator and TaggedLocator attributes [DependencyInjection] Autowire union and intersection types [Monolog] List available built-in formatters
2 parents 0c0bf5d + b89edc0 commit 3248d3a

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

logging/formatter.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ configure your handler to use it:
5555
->formatter('monolog.formatter.json')
5656
;
5757
};
58+
59+
Many built-in formatters are available in Monolog. A lot of them are declared as services
60+
and can be used in the ``formatter`` option:
61+
62+
* ``monolog.formatter.chrome_php``: formats a record according to the ChromePHP array format
63+
* ``monolog.formatter.gelf_message``: serializes a format to GELF format
64+
* ``monolog.formatter.html``: formats a record into an HTML table
65+
* ``monolog.formatter.json``: serializes a record into a JSON object
66+
* ``monolog.formatter.line``: formats a record into a one-line string
67+
* ``monolog.formatter.loggly``: formats a record information into JSON in a format compatible with Loggly
68+
* ``monolog.formatter.logstash``: serializes a record to Logstash Event Format
69+
* ``monolog.formatter.normalizer``: normalizes a record to remove objects/resources so it's easier to dump to various targets
70+
* ``monolog.formatter.scalar``: formats a record into an associative array of scalar (+ null) values (objects and arrays will be JSON encoded)
71+
* ``monolog.formatter.wildfire``: serializes a record according to Wildfire's header requirements

service_container/autowiring.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,30 @@ dealing with the ``TransformerInterface``.
372372
discovered that implements an interface, configuring the alias is not mandatory
373373
and Symfony will automatically create one.
374374

375+
.. tip::
376+
377+
Autowiring is powerful enough to guess which service to inject even when using
378+
union and intersection types. This means you're able to type-hint argument with
379+
complex types like this::
380+
381+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
382+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
383+
use Symfony\Component\Serializer\SerializerInterface;
384+
385+
class DataFormatter
386+
{
387+
public function __construct((NormalizerInterface&DenormalizerInterface)|SerializerInterface $transformer)
388+
{
389+
// ...
390+
}
391+
392+
// ...
393+
}
394+
395+
.. versionadded:: 5.4
396+
397+
The support of union and intersection types was introduced in Symfony 5.4.
398+
375399
Dealing with Multiple Implementations of the Same Type
376400
------------------------------------------------------
377401

service_container/service_subscribers_locators.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,23 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option):
563563

564564
.. configuration-block::
565565

566+
.. code-block:: php-attributes
567+
568+
// src/CommandBus.php
569+
namespace App;
570+
571+
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
572+
use Symfony\Component\DependencyInjection\ServiceLocator;
573+
574+
class CommandBus
575+
{
576+
public function __construct(
577+
#[TaggedLocator('app.handler', indexAttribute: 'key')]
578+
ServiceLocator $locator
579+
) {
580+
}
581+
}
582+
566583
.. code-block:: yaml
567584
568585
# config/services.yaml
@@ -666,6 +683,23 @@ attribute to the locator service defining the name of this custom method:
666683

667684
.. configuration-block::
668685

686+
.. code-block:: php-attributes
687+
688+
// src/CommandBus.php
689+
namespace App;
690+
691+
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
692+
use Symfony\Component\DependencyInjection\ServiceLocator;
693+
694+
class CommandBus
695+
{
696+
public function __construct(
697+
#[TaggedLocator('app.handler', 'key', defaultIndexMethod: 'myOwnMethodName')]
698+
ServiceLocator $locator
699+
) {
700+
}
701+
}
702+
669703
.. code-block:: yaml
670704
671705
# config/services.yaml

service_container/tags.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@ you can define it in the configuration of the collecting service:
794794

795795
.. configuration-block::
796796

797+
.. code-block:: php-attributes
798+
799+
// src/HandlerCollection.php
800+
namespace App;
801+
802+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
803+
804+
class HandlerCollection
805+
{
806+
public function __construct(
807+
#[TaggedIterator('app.handler', defaultPriorityMethod: 'getPriority')]
808+
iterable $handlers
809+
) {
810+
}
811+
}
812+
797813
.. code-block:: yaml
798814
799815
# config/services.yaml
@@ -849,6 +865,22 @@ indexed by the ``key`` attribute:
849865

850866
.. configuration-block::
851867

868+
.. code-block:: php-attributes
869+
870+
// src/HandlerCollection.php
871+
namespace App;
872+
873+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
874+
875+
class HandlerCollection
876+
{
877+
public function __construct(
878+
#[TaggedIterator('app.handler', indexAttribute: 'key')]
879+
iterable $handlers
880+
) {
881+
}
882+
}
883+
852884
.. code-block:: yaml
853885
854886
# config/services.yaml
@@ -955,6 +987,22 @@ array element. For example, to retrieve the ``handler_two`` handler::
955987

956988
.. configuration-block::
957989

990+
.. code-block:: php-attributes
991+
992+
// src/HandlerCollection.php
993+
namespace App;
994+
995+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
996+
997+
class HandlerCollection
998+
{
999+
public function __construct(
1000+
#[TaggedIterator('app.handler', defaultIndexMethod: 'getIndex')]
1001+
iterable $handlers
1002+
) {
1003+
}
1004+
}
1005+
9581006
.. code-block:: yaml
9591007
9601008
# config/services.yaml

0 commit comments

Comments
 (0)