Skip to content

Commit a929de0

Browse files
committed
feature #59536 [JsonEncoder] Allow to warm up object and list (mtarld)
This PR was merged into the 7.3 branch. Discussion ---------- [JsonEncoder] Allow to warm up object and list | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT As discussed with `@chalasr`, configuration in FrameworkBundle must be avoided as much as possible. That's why symfony/symfony#59396 might not be the way to go. Instead, this PR addresses the most common use cases, which are warming up cache files for `GivenClass` and `list<GivenClass>`. This can be configured by setting the `object` and `list` attributes of `json_encoder.encodable`, or `asObject` and `asList` of the `JsonEncodable` attribute accordingly. Commits ------- cb36ec0d09b [JsonEncoder] Allow to warm up item and list
2 parents 1d0686b + 3b39194 commit a929de0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,11 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
750750
}
751751
);
752752
}
753-
$container->registerAttributeForAutoconfiguration(JsonEncodable::class, static function (ChildDefinition $definition): void {
754-
$definition->addTag('json_encoder.encodable');
753+
$container->registerAttributeForAutoconfiguration(JsonEncodable::class, static function (ChildDefinition $definition, JsonEncodable $attribute): void {
754+
$definition->addTag('json_encoder.encodable', [
755+
'object' => $attribute->asObject,
756+
'list' => $attribute->asList,
757+
]);
755758
$definition->addTag('container.excluded');
756759
});
757760

Tests/Functional/JsonEncoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public function testWarmupEncodableClasses()
6262
static::getContainer()->get('json_encoder.cache_warmer.encoder_decoder.alias')->warmUp(static::getContainer()->getParameter('kernel.cache_dir'));
6363

6464
$this->assertFileExists($encodersDir);
65-
$this->assertCount(1, glob($encodersDir.'/*'));
65+
$this->assertCount(2, glob($encodersDir.'/*'));
6666
}
6767
}

0 commit comments

Comments
 (0)