File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed
Bridge/Symfony/Bundle/Resources/config
tests/Bridge/Symfony/Bundle/DependencyInjection Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 126
126
<tag name =" serializer.normalizer" priority =" -925" />
127
127
</service >
128
128
129
+ <service id =" api_platform.serializer.normalizer.no_op_scalar" class =" ApiPlatform\Core\Serializer\NoOpScalarNormalizer" public =" false" >
130
+ <!-- Run before our non-cacheable normalizers -->
131
+ <tag name =" serializer.normalizer" priority =" -900" />
132
+ </service >
133
+
129
134
<!-- Resources Operations path resolver -->
130
135
131
136
<service id =" api_platform.operation_path_resolver" alias =" api_platform.operation_path_resolver.router" public =" false" />
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Core \Serializer ;
15
+
16
+ use Symfony \Component \Serializer \Normalizer \CacheableSupportsMethodInterface ;
17
+ use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
18
+
19
+ /**
20
+ * A no-op normalizer that passes through scalar values.
21
+ *
22
+ * When there are non-cacheable normalizers in use, and you don't need to normalize
23
+ * scalar values, register this normalizer with a higher priority than the non-cacheable
24
+ * normalizers. This allows caching supportsNormalization calls for scalar values.
25
+ */
26
+ final class NoOpScalarNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
27
+ {
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ public function supportsNormalization ($ data , $ format = null ): bool
32
+ {
33
+ return is_scalar ($ data );
34
+ }
35
+
36
+ /**
37
+ * {@inheritdoc}
38
+ */
39
+ public function normalize ($ object , $ format = null , array $ context = [])
40
+ {
41
+ return $ object ;
42
+ }
43
+
44
+ /**
45
+ * {@inheritdoc}
46
+ */
47
+ public function hasCacheableSupportsMethod (): bool
48
+ {
49
+ return true ;
50
+ }
51
+ }
Original file line number Diff line number Diff line change @@ -836,6 +836,7 @@ private function getPartialContainerBuilderProphecy()
836
836
'api_platform.serializer.group_filter ' ,
837
837
'api_platform.serializer.normalizer.item ' ,
838
838
'api_platform.serializer.normalizer.item.non_resource ' ,
839
+ 'api_platform.serializer.normalizer.no_op_scalar ' ,
839
840
'api_platform.serializer.property_filter ' ,
840
841
'api_platform.serializer_locator ' ,
841
842
'api_platform.subresource_data_provider ' ,
You can’t perform that action at this time.
0 commit comments