Skip to content

Commit

Permalink
Merge pull request #52 from acrobat/normalizer-bc-layer
Browse files Browse the repository at this point in the history
Ported the removed DefaultMessageNormalizer to the BernardBundle
  • Loading branch information
acrobat authored Jul 23, 2017
2 parents 92b1fa3 + 242f518 commit cd5c442
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Normalizer/DefaultMessageNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Bernard\BernardBundle\Normalizer;

use Assert\Assertion;
use Bernard\Message\DefaultMessage;
use Bernard\Normalizer\PlainMessageNormalizer;

class DefaultMessageNormalizer extends PlainMessageNormalizer
{
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
{
@trigger_error('The '.__CLASS__.' class is deprecated and will removed in version 3.0. Use '.PlainMessageNormalizer::class.' instead.', E_USER_DEPRECATED);

parent::normalize($object, $format, $context);
}

/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null, array $context = [])
{
@trigger_error('The '.__CLASS__.' class is deprecated and will removed in version 3.0. Use '.PlainMessageNormalizer::class.' instead.', E_USER_DEPRECATED);

Assertion::notEmptyKey($data, 'name');
Assertion::keyExists($data, 'arguments');
Assertion::isArray($data['arguments']);

return new DefaultMessage($data['name'], $data['arguments']);
}

/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null)
{
return $type === DefaultMessage::class;
}

/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
{
return $data instanceof DefaultMessage;
}
}
5 changes: 5 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<tag name="bernard.normalizer" />
</service>

<service id="bernard.normalizer.default_message" class="Bernard\BernardBundle\Normalizer\DefaultMessageNormalizer">
<tag name="bernard.normalizer" />
</service>


<!-- Drivers -->

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

0 comments on commit cd5c442

Please sign in to comment.