Removed deprecations in Serializer component
This commit is contained in:
parent
49494771c5
commit
e90e9b20b3
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\Serializer\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base exception.
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.7, to be removed in 3.0. Use ExceptionInterface instead.
|
|
||||||
*/
|
|
||||||
interface Exception
|
|
||||||
{
|
|
||||||
}
|
|
@ -16,6 +16,6 @@ namespace Symfony\Component\Serializer\Exception;
|
|||||||
*
|
*
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
interface ExceptionInterface extends Exception
|
interface ExceptionInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,9 @@ namespace Symfony\Component\Serializer\Normalizer;
|
|||||||
|
|
||||||
use Symfony\Component\Serializer\Exception\CircularReferenceException;
|
use Symfony\Component\Serializer\Exception\CircularReferenceException;
|
||||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\Serializer\Exception\LogicException;
|
|
||||||
use Symfony\Component\Serializer\Exception\RuntimeException;
|
use Symfony\Component\Serializer\Exception\RuntimeException;
|
||||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||||
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
|
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
|
||||||
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
|
|
||||||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,37 +138,6 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set attributes to be camelized on denormalize.
|
|
||||||
*
|
|
||||||
* @deprecated Deprecated since version 2.7, to be removed in 3.0. Use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter instead.
|
|
||||||
*
|
|
||||||
* @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__));
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributes = array();
|
|
||||||
foreach ($camelizedAttributes as $camelizedAttribute) {
|
|
||||||
$attributes[] = lcfirst(preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
|
|
||||||
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
|
|
||||||
}, $camelizedAttribute));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->nameConverter = new CamelCaseToSnakeCaseNameConverter($attributes);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects if the configured circular reference limit is reached.
|
* Detects if the configured circular reference limit is reached.
|
||||||
*
|
*
|
||||||
@ -221,22 +188,6 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit));
|
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Format an attribute name, for example to convert a snake_case name to camelCase.
|
|
||||||
*
|
|
||||||
* @deprecated Deprecated since version 2.7, to be removed in 3.0. Use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter instead.
|
|
||||||
*
|
|
||||||
* @param string $attributeName
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function formatAttribute($attributeName)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
return $this->nameConverter ? $this->nameConverter->normalize($attributeName) : $attributeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets attributes to normalize using groups.
|
* Gets attributes to normalize using groups.
|
||||||
*
|
*
|
||||||
|
@ -99,79 +99,11 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar', $obj->getBar());
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyDenormalizeOnCamelCaseFormat()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('camel_case'));
|
|
||||||
$obj = $this->normalizer->denormalize(
|
|
||||||
array('camel_case' => 'camelCase'),
|
|
||||||
__NAMESPACE__.'\GetSetDummy'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals('camelCase', $obj->getCamelCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDenormalizeNull()
|
public function testDenormalizeNull()
|
||||||
{
|
{
|
||||||
$this->assertEquals(new GetSetDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\GetSetDummy'));
|
$this->assertEquals(new GetSetDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\GetSetDummy'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyCamelizedAttributesNormalize()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$obj = new GetCamelizedDummy('dunglas.fr');
|
|
||||||
$obj->setFooBar('les-tilleuls.coop');
|
|
||||||
$obj->setBar_foo('lostinthesupermarket.fr');
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
|
|
||||||
$this->assertEquals($this->normalizer->normalize($obj), array(
|
|
||||||
'kevin_dunglas' => 'dunglas.fr',
|
|
||||||
'fooBar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('foo_bar'));
|
|
||||||
$this->assertEquals($this->normalizer->normalize($obj), array(
|
|
||||||
'kevinDunglas' => 'dunglas.fr',
|
|
||||||
'foo_bar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyCamelizedAttributesDenormalize()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$obj = new GetCamelizedDummy('dunglas.fr');
|
|
||||||
$obj->setFooBar('les-tilleuls.coop');
|
|
||||||
$obj->setBar_foo('lostinthesupermarket.fr');
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
|
|
||||||
$this->assertEquals($this->normalizer->denormalize(array(
|
|
||||||
'kevin_dunglas' => 'dunglas.fr',
|
|
||||||
'fooBar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
), __NAMESPACE__.'\GetCamelizedDummy'), $obj);
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('foo_bar'));
|
|
||||||
$this->assertEquals($this->normalizer->denormalize(array(
|
|
||||||
'kevinDunglas' => 'dunglas.fr',
|
|
||||||
'foo_bar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
), __NAMESPACE__.'\GetCamelizedDummy'), $obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testConstructorDenormalize()
|
public function testConstructorDenormalize()
|
||||||
{
|
{
|
||||||
$obj = $this->normalizer->denormalize(
|
$obj = $this->normalizer->denormalize(
|
||||||
|
@ -96,21 +96,6 @@ class ObjectNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar', $obj->bar);
|
$this->assertEquals('bar', $obj->bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyDenormalizeOnCamelCaseFormat()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('camel_case'));
|
|
||||||
$obj = $this->normalizer->denormalize(
|
|
||||||
array('camel_case' => 'camelCase'),
|
|
||||||
__NAMESPACE__.'\ObjectDummy'
|
|
||||||
);
|
|
||||||
$this->assertEquals('camelCase', $obj->getCamelCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDenormalizeNull()
|
public function testDenormalizeNull()
|
||||||
{
|
{
|
||||||
$this->assertEquals(new ObjectDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\ObjectDummy'));
|
$this->assertEquals(new ObjectDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\ObjectDummy'));
|
||||||
|
@ -62,73 +62,6 @@ class PropertyNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar', $obj->getBar());
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyDenormalizeOnCamelCaseFormat()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('camel_case'));
|
|
||||||
$obj = $this->normalizer->denormalize(
|
|
||||||
array('camel_case' => 'value'),
|
|
||||||
__NAMESPACE__.'\PropertyDummy'
|
|
||||||
);
|
|
||||||
$this->assertEquals('value', $obj->getCamelCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyCamelizedAttributesNormalize()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$obj = new PropertyCamelizedDummy('dunglas.fr');
|
|
||||||
$obj->fooBar = 'les-tilleuls.coop';
|
|
||||||
$obj->bar_foo = 'lostinthesupermarket.fr';
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
|
|
||||||
$this->assertEquals($this->normalizer->normalize($obj), array(
|
|
||||||
'kevin_dunglas' => 'dunglas.fr',
|
|
||||||
'fooBar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('foo_bar'));
|
|
||||||
$this->assertEquals($this->normalizer->normalize($obj), array(
|
|
||||||
'kevinDunglas' => 'dunglas.fr',
|
|
||||||
'foo_bar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyCamelizedAttributesDenormalize()
|
|
||||||
{
|
|
||||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
$obj = new PropertyCamelizedDummy('dunglas.fr');
|
|
||||||
$obj->fooBar = 'les-tilleuls.coop';
|
|
||||||
$obj->bar_foo = 'lostinthesupermarket.fr';
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
|
|
||||||
$this->assertEquals($this->normalizer->denormalize(array(
|
|
||||||
'kevin_dunglas' => 'dunglas.fr',
|
|
||||||
'fooBar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
), __NAMESPACE__.'\PropertyCamelizedDummy'), $obj);
|
|
||||||
|
|
||||||
$this->normalizer->setCamelizedAttributes(array('foo_bar'));
|
|
||||||
$this->assertEquals($this->normalizer->denormalize(array(
|
|
||||||
'kevinDunglas' => 'dunglas.fr',
|
|
||||||
'foo_bar' => 'les-tilleuls.coop',
|
|
||||||
'bar_foo' => 'lostinthesupermarket.fr',
|
|
||||||
), __NAMESPACE__.'\PropertyCamelizedDummy'), $obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testConstructorDenormalize()
|
public function testConstructorDenormalize()
|
||||||
{
|
{
|
||||||
$obj = $this->normalizer->denormalize(
|
$obj = $this->normalizer->denormalize(
|
||||||
|
Reference in New Issue
Block a user