Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6024134

Browse files
committed
[FrameworkBundle][Serializer] Use ::class where possible
1 parent 7bc0ce7 commit 6024134

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,28 +1194,28 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
11941194
*/
11951195
private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
11961196
{
1197-
if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
1197+
if (class_exists(DataUriNormalizer::class)) {
11981198
// Run after serializer.normalizer.object
11991199
$definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
12001200
$definition->setPublic(false);
12011201
$definition->addTag('serializer.normalizer', array('priority' => -920));
12021202
}
12031203

1204-
if (class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) {
1204+
if (class_exists(DateTimeNormalizer::class)) {
12051205
// Run before serializer.normalizer.object
12061206
$definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class);
12071207
$definition->setPublic(false);
12081208
$definition->addTag('serializer.normalizer', array('priority' => -910));
12091209
}
12101210

1211-
if (class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) {
1211+
if (class_exists(JsonSerializableNormalizer::class)) {
12121212
// Run before serializer.normalizer.object
12131213
$definition = $container->register('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class);
12141214
$definition->setPublic(false);
12151215
$definition->addTag('serializer.normalizer', array('priority' => -900));
12161216
}
12171217

1218-
if (class_exists('Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer')) {
1218+
if (class_exists(ConstraintViolationListNormalizer::class)) {
12191219
// Run before serializer.normalizer.object
12201220
$definition = $container->register('serializer.normalizer.constraint_violation_list_normalizer', ConstraintViolationListNormalizer::class);
12211221
$definition->setPublic(false);

src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
/**
1717
* A normalizer that normalize a ConstraintViolationListInterface instance.
1818
*
19+
* This Normalizer implements RFC7807 {@link https://tools.ietf.org/html/rfc7807}.
20+
*
1921
* @author Grégoire Pineau <[email protected]>
2022
* @author Kévin Dunglas <[email protected]>
2123
*/
@@ -30,8 +32,9 @@ public function normalize($object, $format = null, array $context = array())
3032
$messages = array();
3133
foreach ($object as $violation) {
3234
$violations[] = array(
33-
'propertyPath' => $violation->getPropertyPath(),
35+
'property_path' => $violation->getPropertyPath(),
3436
'message' => $violation->getMessage(),
37+
'code' => $violation->getCode(),
3538
);
3639
$propertyPath = $violation->getPropertyPath();
3740
$prefix = $propertyPath ? sprintf('%s: ', $propertyPath) : '';

src/Symfony/Component/Serializer/Tests/Normalizer/ConstraintViolationListNormalizerTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function testSupportsNormalization()
3838
public function testNormalize()
3939
{
4040
$list = new ConstraintViolationList(array(
41-
new ConstraintViolation('a', 'b', array(), 'c', 'd', 'e'),
42-
new ConstraintViolation('1', '2', array(), '3', '4', '5'),
41+
new ConstraintViolation('a', 'b', array(), 'c', 'd', 'e', null, 'f'),
42+
new ConstraintViolation('1', '2', array(), '3', '4', '5', null, '6'),
4343
));
4444

4545
$expected = array(
@@ -49,12 +49,14 @@ public function testNormalize()
4949
4: 1',
5050
'violations' => array(
5151
array(
52-
'propertyPath' => 'd',
52+
'property_path' => 'd',
5353
'message' => 'a',
54+
'code' => 'f',
5455
),
5556
array(
56-
'propertyPath' => '4',
57+
'property_path' => '4',
5758
'message' => '1',
59+
'code' => '6',
5860
),
5961
),
6062
);

0 commit comments

Comments
 (0)