Skip to content

Commit 4c3f2cb

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

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
@@ -699,6 +699,22 @@ you can define it in the configuration of the collecting service:
699699

700700
.. configuration-block::
701701

702+
.. code-block:: php-attributes
703+
704+
// src/HandlerCollection.php
705+
namespace App;
706+
707+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
708+
709+
class HandlerCollection
710+
{
711+
public function __construct(
712+
#[TaggedIterator('app.handler', defaultPriorityMethod: 'getPriority')]
713+
iterable $handlers
714+
) {
715+
}
716+
}
717+
702718
.. code-block:: yaml
703719
704720
# config/services.yaml
@@ -754,6 +770,22 @@ indexed by the ``key`` attribute:
754770

755771
.. configuration-block::
756772

773+
.. code-block:: php-attributes
774+
775+
// src/HandlerCollection.php
776+
namespace App;
777+
778+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
779+
780+
class HandlerCollection
781+
{
782+
public function __construct(
783+
#[TaggedIterator('app.handler', indexAttribute: 'key')]
784+
iterable $handlers
785+
) {
786+
}
787+
}
788+
757789
.. code-block:: yaml
758790
759791
# config/services.yaml
@@ -860,6 +892,22 @@ array element. For example, to retrieve the ``handler_two`` handler::
860892

861893
.. configuration-block::
862894

895+
.. code-block:: php-attributes
896+
897+
// src/HandlerCollection.php
898+
namespace App;
899+
900+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
901+
902+
class HandlerCollection
903+
{
904+
public function __construct(
905+
#[TaggedIterator('app.handler', defaultIndexMethod: 'getIndex')]
906+
iterable $handlers
907+
) {
908+
}
909+
}
910+
863911
.. code-block:: yaml
864912
865913
# config/services.yaml

0 commit comments

Comments
 (0)