-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add normalizer / denormalizer awarness #17545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,18 @@ | |
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; | ||
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface; | ||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
use Symfony\Component\Serializer\SerializerAwareInterface; | ||
use Symfony\Component\Serializer\SerializerAwareTrait; | ||
|
||
/** | ||
* Normalizer implementation. | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
abstract class AbstractNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface | ||
abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface | ||
{ | ||
use SerializerAwareTrait; | ||
|
||
const CIRCULAR_REFERENCE_LIMIT = 'circular_reference_limit'; | ||
const OBJECT_TO_POPULATE = 'object_to_populate'; | ||
const GROUPS = 'groups'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,16 @@ | |
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
use Symfony\Component\Serializer\SerializerAwareInterface; | ||
use Symfony\Component\Serializer\SerializerAwareTrait; | ||
|
||
/** | ||
* @author Jordi Boggiano <[email protected]> | ||
*/ | ||
class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface | ||
class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface | ||
{ | ||
use SerializerAwareTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
/** | ||
* Class accepting a denormalizer. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
interface DenormalizerAwareInterface | ||
{ | ||
/** | ||
* Sets the owning Denormalizer object. | ||
* | ||
* @param DenormalizerInterface $denormalizer | ||
*/ | ||
public function setDenormalizer(DenormalizerInterface $denormalizer); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
/** | ||
* DenormalizerAware trait. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
trait DenormalizerAwareTrait | ||
{ | ||
/** | ||
* @var DenormalizerInterface | ||
*/ | ||
protected $denormalizer; | ||
|
||
/** | ||
* Sets the Denormalizer. | ||
* | ||
* @param DenormalizerInterface $denormalizer A DenormalizerInterface instance | ||
*/ | ||
public function setSerializer(DenormalizerInterface $denormalizer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oups :) Fix in #18536 |
||
{ | ||
$this->denormalizer = $denormalizer; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
/** | ||
* Class accepting a normalizer. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
interface NormalizerAwareInterface | ||
{ | ||
/** | ||
* Sets the owning Normalizer object. | ||
* | ||
* @param NormalizerInterface $normalizer | ||
*/ | ||
public function setNormalizer(NormalizerInterface $normalizer); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
/** | ||
* NormalizerAware trait. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
trait NormalizerAwareTrait | ||
{ | ||
/** | ||
* @var NormalizerInterface | ||
*/ | ||
protected $normalizer; | ||
|
||
/** | ||
* Sets the normalizer. | ||
* | ||
* @param NormalizerInterface $normalizer A NormalizerInterface instance | ||
*/ | ||
public function setSerializer(NormalizerInterface $normalizer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #18536 |
||
{ | ||
$this->normalizer = $normalizer; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,26 +11,17 @@ | |
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Symfony\Component\Serializer\SerializerAwareTrait; | ||
use Symfony\Component\Serializer\SerializerAwareInterface; | ||
|
||
/** | ||
* SerializerAware Normalizer implementation. | ||
* | ||
* @author Jordi Boggiano <[email protected]> | ||
* | ||
* @deprecated since version 3.1, to be removed in 4.0. Use the SerializerAwareTrait instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must trigger a deprecation error like this one: You should also adapt existing normalizers in Symfony to avoid using this deprecated class. But if you do that... It will be a small BC break ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since there is no more code / method in this class i don't think it's possible, i have done this deprecated feature in the same way it was done for the ContainerAwareTrait in 2.8 https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/DependencyInjection/ContainerAware.php
It's already done, but maybe i have miss some implementations ? |
||
*/ | ||
abstract class SerializerAwareNormalizer implements SerializerAwareInterface | ||
{ | ||
/** | ||
* @var SerializerInterface | ||
*/ | ||
protected $serializer; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSerializer(SerializerInterface $serializer) | ||
{ | ||
$this->serializer = $serializer; | ||
} | ||
use SerializerAwareTrait; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer; | ||
|
||
/** | ||
* SerializerAware trait. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
trait SerializerAwareTrait | ||
{ | ||
/** | ||
* @var SerializerInterface | ||
*/ | ||
protected $serializer; | ||
|
||
/** | ||
* Sets the serializer. | ||
* | ||
* @param SerializerInterface $serializer A SerializerInterface instance | ||
*/ | ||
public function setSerializer(SerializerInterface $serializer) | ||
{ | ||
$this->serializer = $serializer; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a BC break for anyone having a type hint on the
SerializerAwareNormalizer
class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we readd the extends and override the methods ? Or is this an acceptable BC break ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So according to this : http://symfony.com/doc/current/contributing/code/bc.html#id10 it is not something acceptable, will do a PR to readd this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry I was on a mobile when writing the comment and forgot to add a reference to that later.