[Serializer] Use Serializer's LogicException when applicable
This commit is contained in:
parent
fcd6d6085f
commit
8ddc888f00
@ -13,6 +13,7 @@ namespace Symfony\Component\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\Serializer\Exception\CircularReferenceException;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Serializer\Exception\LogicException;
|
||||
use Symfony\Component\Serializer\Exception\RuntimeException;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
|
||||
@ -125,13 +126,15 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
||||
* @param array $camelizedAttributes
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function setCamelizedAttributes(array $camelizedAttributes)
|
||||
{
|
||||
trigger_error(sprintf('%s is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
if ($this->nameConverter && !$this->nameConverter instanceof CamelCaseToSnakeCaseNameConverter) {
|
||||
throw new \LogicException(sprintf('%s cannot be called if a custom Name Converter is defined.', __METHOD__));
|
||||
throw new LogicException(sprintf('%s cannot be called if a custom Name Converter is defined.', __METHOD__));
|
||||
}
|
||||
|
||||
$attributes = array();
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\Serializer\Exception\CircularReferenceException;
|
||||
use Symfony\Component\Serializer\Exception\LogicException;
|
||||
use Symfony\Component\Serializer\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
@ -40,6 +41,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws LogicException
|
||||
* @throws CircularReferenceException
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = array())
|
||||
@ -71,7 +73,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
||||
}
|
||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||
if (!$this->serializer instanceof NormalizerInterface) {
|
||||
throw new \LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $attributeName));
|
||||
throw new LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $attributeName));
|
||||
}
|
||||
|
||||
$attributeValue = $this->serializer->normalize($attributeValue, $format, $context);
|
||||
|
@ -348,7 +348,7 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
|
||||
* @expectedExceptionMessage Cannot normalize attribute "object" because injected serializer is not a normalizer
|
||||
*/
|
||||
public function testUnableToNormalizeObjectAttribute()
|
||||
|
Reference in New Issue
Block a user