|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MindbazBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) David DELEVOYE <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kozikaza\MindbazBundle\Serializer\Bridge; |
|
13
|
|
|
|
|
14
|
|
|
use JMS\Serializer\ArrayTransformerInterface; |
|
15
|
|
|
use JMS\Serializer\SerializerInterface as JMSSerializerInterface; |
|
16
|
|
|
use Kozikaza\MindbazBundle\Model\Subscriber; |
|
17
|
|
|
use mbzSubscriber\Subscriber as MindbazSubscriber; |
|
18
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
19
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Vincent Chalamon <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class Serializer |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var SerializerInterface|DenormalizerInterface|JMSSerializerInterface|ArrayTransformerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $serializer; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param SerializerInterface|DenormalizerInterface|JMSSerializerInterface|ArrayTransformerInterface $serializer |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct($serializer) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->serializer = $serializer; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param array $data |
|
41
|
|
|
* @param string $class |
|
42
|
|
|
* |
|
43
|
|
|
* @return Subscriber |
|
44
|
|
|
*/ |
|
45
|
|
|
public function denormalize(array $data, $class) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->serializer instanceof JMSSerializerInterface ? $this->serializer->fromArray($data, $class) : $this->serializer->denormalize($data, $class); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param Subscriber $data |
|
52
|
|
|
* @param string $format |
|
53
|
|
|
* |
|
54
|
|
|
* @return MindbazSubscriber |
|
55
|
|
|
*/ |
|
56
|
|
|
public function serialize(Subscriber $data, $format) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->serializer->serialize($data, $format); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param MindbazSubscriber $data |
|
63
|
|
|
* @param string $type |
|
64
|
|
|
* @param string $format |
|
65
|
|
|
* |
|
66
|
|
|
* @return Subscriber |
|
67
|
|
|
*/ |
|
68
|
|
|
public function deserialize(MindbazSubscriber $data, $type, $format) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->serializer->deserialize($data, $type, $format); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: