Skip to content

Commit cd5c442

Browse files
authored
Merge pull request #52 from acrobat/normalizer-bc-layer
Ported the removed DefaultMessageNormalizer to the BernardBundle
2 parents 92b1fa3 + 242f518 commit cd5c442

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Bernard\BernardBundle\Normalizer;
4+
5+
use Assert\Assertion;
6+
use Bernard\Message\DefaultMessage;
7+
use Bernard\Normalizer\PlainMessageNormalizer;
8+
9+
class DefaultMessageNormalizer extends PlainMessageNormalizer
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function normalize($object, $format = null, array $context = [])
15+
{
16+
@trigger_error('The '.__CLASS__.' class is deprecated and will removed in version 3.0. Use '.PlainMessageNormalizer::class.' instead.', E_USER_DEPRECATED);
17+
18+
parent::normalize($object, $format, $context);
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function denormalize($data, $class, $format = null, array $context = [])
25+
{
26+
@trigger_error('The '.__CLASS__.' class is deprecated and will removed in version 3.0. Use '.PlainMessageNormalizer::class.' instead.', E_USER_DEPRECATED);
27+
28+
Assertion::notEmptyKey($data, 'name');
29+
Assertion::keyExists($data, 'arguments');
30+
Assertion::isArray($data['arguments']);
31+
32+
return new DefaultMessage($data['name'], $data['arguments']);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function supportsDenormalization($data, $type, $format = null)
39+
{
40+
return $type === DefaultMessage::class;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function supportsNormalization($data, $format = null)
47+
{
48+
return $data instanceof DefaultMessage;
49+
}
50+
}

Resources/config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
<tag name="bernard.normalizer" />
7070
</service>
7171

72+
<service id="bernard.normalizer.default_message" class="Bernard\BernardBundle\Normalizer\DefaultMessageNormalizer">
73+
<tag name="bernard.normalizer" />
74+
</service>
75+
76+
7277
<!-- Drivers -->
7378

7479
<service id="bernard.driver.doctrine" class="Bernard\Driver\DoctrineDriver" public="false">

0 commit comments

Comments
 (0)