Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #17545 [Serializer] Add normalizer / denormalizer awarness (j…
…oelwurtz) This PR was merged into the 3.1-dev branch. Discussion ---------- [Serializer] Add normalizer / denormalizer awarness | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | SerializerAwareInterface is not really usable in a decode -> normalize context, as if we need to transform a subproperty with another class, we only have the context of a serialize however the data is already decoded so it will fail. This interfaces allow a normalizer / denormalizer to have a sub normalization / denormalization process context and not the whole context with serializer. I have also add a `AwareNormalizer` which is an abstract class implementing the 3 aware interfaces like it was done with the SerializerAwareNormalizer, since it's a standard way to implement this interfaces. This is needed for #17516, other solution would be to have a RawDecoder which don't decode and return the input as it is, but really not a fan of this solution. Commits ------- 790fb6e Add normalizer / denormalizer awarness
- Loading branch information
Showing
10 changed files
with
208 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Normalizer; | ||
|
||
/** | ||
* Class accepting a denormalizer. | ||
* | ||
* @author Joel Wurtz <joel.wurtz@gmail.com> | ||
*/ | ||
interface DenormalizerAwareInterface | ||
{ | ||
/** | ||
* Sets the owning Denormalizer object. | ||
* | ||
* @param DenormalizerInterface $denormalizer | ||
*/ | ||
public function setDenormalizer(DenormalizerInterface $denormalizer); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Normalizer; | ||
|
||
/** | ||
* DenormalizerAware trait. | ||
* | ||
* @author Joel Wurtz <joel.wurtz@gmail.com> | ||
*/ | ||
trait DenormalizerAwareTrait | ||
{ | ||
/** | ||
* @var DenormalizerInterface | ||
*/ | ||
protected $denormalizer; | ||
|
||
/** | ||
* Sets the Denormalizer. | ||
* | ||
* @param DenormalizerInterface $denormalizer A DenormalizerInterface instance | ||
*/ | ||
public function setSerializer(DenormalizerInterface $denormalizer) | ||
{ | ||
$this->denormalizer = $denormalizer; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Symfony/Component/Serializer/Normalizer/NormalizerAwareInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Normalizer; | ||
|
||
/** | ||
* Class accepting a normalizer. | ||
* | ||
* @author Joel Wurtz <joel.wurtz@gmail.com> | ||
*/ | ||
interface NormalizerAwareInterface | ||
{ | ||
/** | ||
* Sets the owning Normalizer object. | ||
* | ||
* @param NormalizerInterface $normalizer | ||
*/ | ||
public function setNormalizer(NormalizerInterface $normalizer); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Symfony/Component/Serializer/Normalizer/NormalizerAwareTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Normalizer; | ||
|
||
/** | ||
* NormalizerAware trait. | ||
* | ||
* @author Joel Wurtz <joel.wurtz@gmail.com> | ||
*/ | ||
trait NormalizerAwareTrait | ||
{ | ||
/** | ||
* @var NormalizerInterface | ||
*/ | ||
protected $normalizer; | ||
|
||
/** | ||
* Sets the normalizer. | ||
* | ||
* @param NormalizerInterface $normalizer A NormalizerInterface instance | ||
*/ | ||
public function setSerializer(NormalizerInterface $normalizer) | ||
{ | ||
$this->normalizer = $normalizer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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; | ||
|
||
/** | ||
* SerializerAware trait. | ||
* | ||
* @author Joel Wurtz <joel.wurtz@gmail.com> | ||
*/ | ||
trait SerializerAwareTrait | ||
{ | ||
/** | ||
* @var SerializerInterface | ||
*/ | ||
protected $serializer; | ||
|
||
/** | ||
* Sets the serializer. | ||
* | ||
* @param SerializerInterface $serializer A SerializerInterface instance | ||
*/ | ||
public function setSerializer(SerializerInterface $serializer) | ||
{ | ||
$this->serializer = $serializer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters