Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78a5e9b

Browse files
committed
Merge branch '5.1' into master
* 5.1: Removed versionadded 4.4 directives [#12697] Some minor tweaks [DependencyInjection] Add docs for default priority method for tagged services [#12461] Added versionadded directive List CSV encoder's context options
2 parents94e4e7a +6488694 commit78a5e9b

File tree

2 files changed

+141
-32
lines changed

2 files changed

+141
-32
lines changed

‎components/serializer.rst‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,48 @@ These are the options available:
12951295
``remove_empty_tags``
12961296
If set to true, removes all empty tags in the generated XML (default: ``false``).
12971297

1298+
The ``CsvEncoder``
1299+
------------------
1300+
1301+
This encoder transforms arrays into CSV and vice versa.
1302+
1303+
Context
1304+
~~~~~~~
1305+
1306+
The ``encode()`` method defines a third optional parameter called ``context``
1307+
which defines the configuration options for the CsvEncoder an associative array::
1308+
1309+
$csvEncoder->encode($array, 'csv', $context);
1310+
1311+
These are the options available:
1312+
1313+
``csv_delimiter``
1314+
Sets the field delimiter separating values (one character only, default: ``,``).
1315+
1316+
``csv_enclosure``
1317+
Sets the field enclosure (one character only, default: ``"``).
1318+
1319+
``csv_escape_char``
1320+
Sets the escape character (at most one character, default: empty string).
1321+
1322+
``csv_key_separator``
1323+
Sets the separator for array's keys during its flattening (default: ``.``).
1324+
1325+
``csv_headers``
1326+
Sets the headers for the data (default: ``[]``, inferred from input data's keys).
1327+
1328+
``csv_escape_formulas``
1329+
Escapes fields containg formulas by prepending them with a ``\t`` character (default: ``false``).
1330+
1331+
``as_collection``
1332+
Always returns results as a collection, even if only one line is decoded.
1333+
1334+
``no_headers``
1335+
Disables header in the encoded CSV (default: ``false``).
1336+
1337+
``output_utf8_bom``
1338+
Outputs special `UTF-8 BOM`_ along with encoded data (default: ``false``).
1339+
12981340
Handling Constructor Arguments
12991341
------------------------------
13001342

@@ -1549,6 +1591,7 @@ Learn more
15491591
.. _YAML:https://yaml.org/
15501592
.. _CSV:https://tools.ietf.org/html/rfc4180
15511593
.. _`RFC 7807`:https://tools.ietf.org/html/rfc7807
1594+
.. _`UTF-8 BOM`:https://en.wikipedia.org/wiki/Byte_order_mark
15521595
.. _`Value Objects`:https://en.wikipedia.org/wiki/Value_object
15531596
.. _`API Platform`:https://api-platform.com
15541597
.. _`list of PHP timezones`:https://www.php.net/manual/en/timezones.php

‎service_container/tags.rst‎

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -587,47 +587,113 @@ application handlers::
587587
}
588588
}
589589

590-
..tip::
590+
Tagged Services with Priority
591+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
591592

592-
The collected services can be prioritized using the ``priority`` attribute:
593+
The tagged services can be prioritized using the ``priority`` attribute,
594+
thus providing a way to inject a sorted collection of services:
593595

594-
..configuration-block::
596+
..configuration-block::
595597

596-
..code-block::yaml
598+
..code-block::yaml
597599
598-
# config/services.yaml
599-
services:
600-
App\Handler\One:
601-
tags:
602-
-{ name: 'app.handler', priority: 20 }
600+
# config/services.yaml
601+
services:
602+
App\Handler\One:
603+
tags:
604+
-{ name: 'app.handler', priority: 20 }
603605
604-
..code-block::xml
606+
..code-block::xml
605607
606-
<!-- config/services.xml-->
607-
<?xml version="1.0" encoding="UTF-8" ?>
608-
<containerxmlns="http://symfony.com/schema/dic/services"
609-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
610-
xsi:schemaLocation="http://symfony.com/schema/dic/services
611-
https://symfony.com/schema/dic/services/services-1.0.xsd">
608+
<!-- config/services.xml-->
609+
<?xml version="1.0" encoding="UTF-8" ?>
610+
<containerxmlns="http://symfony.com/schema/dic/services"
611+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
612+
xsi:schemaLocation="http://symfony.com/schema/dic/services
613+
https://symfony.com/schema/dic/services/services-1.0.xsd">
612614
613-
<services>
614-
<serviceid="App\Handler\One">
615-
<tagname="app.handler"priority="20"/>
616-
</service>
617-
</services>
618-
</container>
615+
<services>
616+
<serviceid="App\Handler\One">
617+
<tagname="app.handler"priority="20"/>
618+
</service>
619+
</services>
620+
</container>
619621
620-
..code-block::php
622+
..code-block::php
621623
622-
// config/services.php
623-
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
624+
// config/services.php
625+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
624626
625-
return function(ContainerConfigurator $configurator) {
626-
$services = $configurator->services();
627+
use App\Handler\One;
627628
628-
$services->set(App\Handler\One::class)
629-
->tag('app.handler', ['priority' => 20])
630-
;
631-
};
629+
return function(ContainerConfigurator $configurator) {
630+
$services = $configurator->services();
631+
632+
$services->set(One::class)
633+
->tag('app.handler', ['priority' => 20])
634+
;
635+
};
632636
633-
Note that any other custom attributes will be ignored by this feature.
637+
Another option, which is particularly useful when using autoconfiguring
638+
tags, is to implement the static ``getDefaultPriority()`` method on the
639+
service itself::
640+
641+
// src/Handler/One.php
642+
namespace App/Handler;
643+
644+
class One
645+
{
646+
public static function getDefaultPriority(): int
647+
{
648+
return 3;
649+
}
650+
}
651+
652+
If you want to have another method defining the priority, you can define it
653+
in the configuration of the collecting service:
654+
655+
..configuration-block::
656+
657+
..code-block::yaml
658+
659+
# config/services.yaml
660+
services:
661+
App\HandlerCollection:
662+
# inject all services tagged with app.handler as first argument
663+
arguments:
664+
-!tagged_iterator{ tag: app.handler, default_priority_method: getPriority }
665+
666+
..code-block::xml
667+
668+
<!-- config/services.xml-->
669+
<?xml version="1.0" encoding="UTF-8" ?>
670+
<containerxmlns="http://symfony.com/schema/dic/services"
671+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
672+
xsi:schemaLocation="http://symfony.com/schema/dic/services
673+
https://symfony.com/schema/dic/services/services-1.0.xsd">
674+
<services>
675+
<serviceid="App\HandlerCollection">
676+
<argumenttype="tagged"tag="app.handler"default-priority-method="getPriority"/>
677+
</service>
678+
</services>
679+
</container>
680+
681+
..code-block::php
682+
683+
// config/services.php
684+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
685+
686+
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
687+
688+
return function (ContainerConfigurator $configurator) {
689+
$services = $configurator->services();
690+
691+
// ...
692+
693+
$services->set(App\HandlerCollection::class)
694+
->args([
695+
tagged_iterator('app.handler', null, null, 'getPriority'),
696+
]
697+
)
698+
;
699+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp