Skip to content

Commit 4ca7b5f

Browse files
committed
minor #16753 [Serializer] Skip calling ContextBuilder::toArray() when possible (chalasr)
This PR was merged into the 6.1 branch. Discussion ---------- [Serializer] Skip calling `ContextBuilder::toArray()` when possible <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Leverages symfony/symfony#46179 Commits ------- be1bd78 [Serializer] Skip calling `ContextBuilder::toArray()` when possible
2 parents eea96ba + be1bd78 commit 4ca7b5f

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

components/serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ you can use "context builders" to define the context using a fluent interface::
12221222
->withGroups(['group1', 'group2']);
12231223

12241224
$contextBuilder = (new CsvEncoderContextBuilder())
1225-
->withContext($contextBuilder->toArray())
1225+
->withContext($contextBuilder)
12261226
->withDelimiter(';');
12271227

12281228
$serializer->serialize($something, 'csv', $contextBuilder->toArray());

serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ To create a more complex (de)serialization context, you can chain them using the
185185
->withGroups(['group1', 'group2']);
186186

187187
$contextBuilder = (new CsvEncoderContextBuilder())
188-
->withContext($contextBuilder->toArray())
188+
->withContext($contextBuilder)
189189
->withDelimiter(';');
190190

191191
$serializer->serialize($something, 'csv', $contextBuilder->toArray());

serializer/custom_context_builders.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ context key, you can create a dedicated context builder::
6565
// src/Serializer/LegacyContextBuilder
6666
namespace App\Serializer;
6767

68+
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
6869
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
6970

70-
final class LegacyContextBuilder
71+
final class LegacyContextBuilder implements ContextBuilderInterface
7172
{
7273
use ContextBuilderTrait;
7374

0 commit comments

Comments
 (0)