Skip to content

Commit d1d9aef

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [DependencyInjection] Complete examples with TaggedIterator and TaggedLocator attributes [DependencyInjection] Autowire union and intersection types [Monolog] List available built-in formatters
2 parents 0ff6007 + 4c3f2cb commit d1d9aef

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
@@ -510,6 +510,23 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option):
510510

511511
.. configuration-block::
512512

513+
.. code-block:: php-attributes
514+
515+
// src/CommandBus.php
516+
namespace App;
517+
518+
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
519+
use Symfony\Component\DependencyInjection\ServiceLocator;
520+
521+
class CommandBus
522+
{
523+
public function __construct(
524+
#[TaggedLocator('app.handler', indexAttribute: 'key')]
525+
ServiceLocator $locator
526+
) {
527+
}
528+
}
529+
513530
.. code-block:: yaml
514531
515532
# config/services.yaml
@@ -613,6 +630,23 @@ attribute to the locator service defining the name of this custom method:
613630

614631
.. configuration-block::
615632

633+
.. code-block:: php-attributes
634+
635+
// src/CommandBus.php
636+
namespace App;
637+
638+
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
639+
use Symfony\Component\DependencyInjection\ServiceLocator;
640+
641+
class CommandBus
642+
{
643+
public function __construct(
644+
#[TaggedLocator('app.handler', 'key', defaultIndexMethod: 'myOwnMethodName')]
645+
ServiceLocator $locator
646+
) {
647+
}
648+
}
649+
616650
.. code-block:: yaml
617651
618652
# config/services.yaml

service_container/tags.rst

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

785785
.. configuration-block::
786786

787+
.. code-block:: php-attributes
788+
789+
// src/HandlerCollection.php
790+
namespace App;
791+
792+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
793+
794+
class HandlerCollection
795+
{
796+
public function __construct(
797+
#[TaggedIterator('app.handler', defaultPriorityMethod: 'getPriority')]
798+
iterable $handlers
799+
) {
800+
}
801+
}
802+
787803
.. code-block:: yaml
788804
789805
# config/services.yaml
@@ -839,6 +855,22 @@ indexed by the ``key`` attribute:
839855

840856
.. configuration-block::
841857

858+
.. code-block:: php-attributes
859+
860+
// src/HandlerCollection.php
861+
namespace App;
862+
863+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
864+
865+
class HandlerCollection
866+
{
867+
public function __construct(
868+
#[TaggedIterator('app.handler', indexAttribute: 'key')]
869+
iterable $handlers
870+
) {
871+
}
872+
}
873+
842874
.. code-block:: yaml
843875
844876
# config/services.yaml
@@ -945,6 +977,22 @@ array element. For example, to retrieve the ``handler_two`` handler::
945977

946978
.. configuration-block::
947979

980+
.. code-block:: php-attributes
981+
982+
// src/HandlerCollection.php
983+
namespace App;
984+
985+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
986+
987+
class HandlerCollection
988+
{
989+
public function __construct(
990+
#[TaggedIterator('app.handler', defaultIndexMethod: 'getIndex')]
991+
iterable $handlers
992+
) {
993+
}
994+
}
995+
948996
.. code-block:: yaml
949997
950998
# config/services.yaml

0 commit comments

Comments
 (0)