8000 refactored Normalizer interfaces · symfony/symfony@f8e2787 · GitHub
[go: up one dir, main page]

Skip to content

Commit f8e2787

Browse files
committed
refactored Normalizer interfaces
1 parent 58bd0f5 commit f8e2787

File tree

6 files changed

+72
-84
lines changed

6 files changed

+72
-84
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Normalizer;
4+
5+
use Symfony\Component\Serializer\SerializerInterface;
6+
7+
/*
8+
* This file is part of the Symfony framework.
9+
*
10+
* (c) Fabien Potencier <fabien@symfony.com>
11+
*
12+
* This source file is subject to the MIT license that is bundled
13+
* with this source code in the file LICENSE.
14+
*/
15+
16+
/**
17+
* Defines the most basic interface a class must implement to be denormalizable
18+
*
19+
* If a denormalizer is registered for the class and it doesn't implement
20+
* the Denormalizable interfaces, the normalizer will be used instead
21+
*
22+
* @author Jordi Boggiano <j.boggiano@seld.be>
23+
*/
24+
interface DenormalizableInterface
25+
{
26+
/**
27+
* Denormalizes the object back from an array of scalars|arrays.
28+
*
29+
* It is important to understand that the normalize() call should denormalize
30+
* recursively all child objects of the implementor.
31+
*
32+
* @param SerializerInterface $serializer The serializer is given so that you
33+
* can use it to denormalize objects contained within this object.
34+
* @param array|scalar $data The data from which to re-create the object.
35+
* @param string|null $format The format is optionally given to be able to denormalize differently
36+
* based on different input formats.
37+
*/
38+
function denormalize(SerializerInterface $serializer, $data, $format = null);
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Normalizer;
4+
5+
/*
6+
* This file is part of the Symfony framework.
7+
*
8+
* (c) Fabien Potencier <fabien@symfony.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
12+
*/
13+
14+
/**
15+
* Defines the interface of denormalizers.
16+
*
17+
* @author Jordi Boggiano <j.boggiano@seld.be>
18+
*/
19+
interface DenormalizerInterface
20+
{
21+
/**
22+
* Denormalizes data back into an object of the given class
23+
*
24+
* @param mixed $data data to restore
25+
* @param string $class the expected class to instantiate
26+
* @param string $format format the given data was extracted from
27+
* @return object
28+
*/
29+
function denormalize($data, $class, $format = null);
30+
}

src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,4 @@ interface NormalizableInterface
3636
* @return array|scalar
3737
*/
3838
function normalize(SerializerInterface $serializer, $format = null);
39-
40-
/**
41-
* Denormalizes the object back from an array of scalars|arrays.
42-
*
43-
* It is important to understand that the normalize() call should denormalize
44-
* recursively all child objects of the implementor.
45-
*
46-
* @param SerializerInterface $serializer The serializer is given so that you
47-
* can use it to denormalize objects contained within this object.
48-
* @param array|scalar $data The data from which to re-create the object.
49-
* @param string|null $format The format is optionally given to be able to denormalize differently
50-
* based on different input formats.
51-
*/
52-
function denormalize(SerializerInterface $serializer, $data, $format = null);
5339
}

src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Symfony\Component\Serializer\Normalizer;
44

5-
65
/*
76
* This file is part of the Symfony framework.
87
*
@@ -27,33 +26,4 @@ interface NormalizerInterface
2726
* @return array|scalar
2827
*/
2928
function normalize($object, $format = null);
30-
31-
/**
32-
* Denormalizes data back into an object of the given class
33-
*
34-
* @param mixed $data data to restore
35-
* @param string $class the expected class to instantiate
36-
* @param string $format format the given data was extracted from
37-
* @return object
38-
*/
39-
function denormalize($data, $class, $format = null);
40-
41-
/**
42-
* Checks whether the given class is supported for normalization by this normalizer
43-
*
44-
* @param mixed $data Data to normalize.
45-
* @param string $format The format being (de-)serialized from or into.
46-
* @return Boolean
47-
*/
48-
function supportsNormalization($data, $format = null);
49-
50-
/**
51-
* Checks whether the given class is supported for denormalization by this normalizer
52-
*
53-
* @param mixed $data Data to denormalize from.
54-
* @param string $type The class to which the data should be denormalized.
55-
* @param string $format The format being deserialized from.
56-
* @return Boolean
57-
*/
58-
function supportsDenormalization($data, $type, $format = null);
5929
}

src/Symfony/Component/Serializer/NormalizerInterface.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Symfony\Component\Serializer\Encoder\EncoderInterface;
66
use Symfony\Component\Serializer\Encoder\DecoderInterface;
77
use Symfony\Component\Serializer\Encoder\NormalizationAwareInterface;
8+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
9+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
810
use Symfony\Component\Serializer\Exception\RuntimeException;
911
use Symfony\Component\Serializer\Exception\LogicException;
1012
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
@@ -32,7 +34,7 @@
3234
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
3335
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
3436
*/
35-
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface, DecoderInterface
37+
class Serializer implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface
3638
{
3739
protected $normalizers = array();
3840
protected $encoders = array();

0 commit comments

Comments
 (0)
0