Skip to content

Commit

Permalink
Removed deprecations in Serializer component
Browse files Browse the repository at this point in the history
  • Loading branch information
dosten authored and dunglas committed Apr 27, 2015
1 parent 4949477 commit e90e9b2
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 221 deletions.
21 changes: 0 additions & 21 deletions src/Symfony/Component/Serializer/Exception/Exception.php

This file was deleted.

Expand Up @@ -16,6 +16,6 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
interface ExceptionInterface extends Exception
interface ExceptionInterface
{
}
49 changes: 0 additions & 49 deletions src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
Expand Up @@ -13,11 +13,9 @@

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\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;

/**
Expand Down Expand Up @@ -140,37 +138,6 @@ public function setIgnoredAttributes(array $ignoredAttributes)
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.
*
Expand Down Expand Up @@ -221,22 +188,6 @@ protected function handleCircularReference($object)
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.
*
Expand Down
Expand Up @@ -99,79 +99,11 @@ public function testDenormalizeWithObject()
$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()
{
$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()
{
$obj = $this->normalizer->denormalize(
Expand Down
Expand Up @@ -96,21 +96,6 @@ public function testDenormalizeWithObject()
$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()
{
$this->assertEquals(new ObjectDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\ObjectDummy'));
Expand Down
Expand Up @@ -62,73 +62,6 @@ public function testDenormalize()
$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()
{
$obj = $this->normalizer->denormalize(
Expand Down

0 comments on commit e90e9b2

Please sign in to comment.