1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Serializer\Normalizer; |
15
|
|
|
|
16
|
|
|
use Silverback\ApiComponentsBundle\Model\Uploadable\UploadedDataUriFile; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer as SymfonyDataUriNormalizer; |
19
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
20
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
21
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
22
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
23
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
24
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The DataUriNormalizer would be called even if we have already denormalized. The `supports` |
28
|
|
|
* method seems to have 'null' data. So we check during denormalization if we have already done it. |
29
|
|
|
* Bit hacky, but it'll be OK for now. Should trace source of issue, probably a bug in dependency, |
30
|
|
|
* Check removing this every now and again perhaps too. Tests will fail. |
31
|
|
|
* |
32
|
|
|
* @author Daniel West <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class DataUriNormalizer implements NormalizerAwareInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface, NormalizerInterface, DenormalizerInterface |
35
|
|
|
{ |
36
|
|
|
use NormalizerAwareTrait; |
37
|
|
|
use DenormalizerAwareTrait; |
38
|
|
|
|
39
|
|
|
private SymfonyDataUriNormalizer $decorated; |
40
|
|
|
|
41
|
7 |
|
public function __construct(SymfonyDataUriNormalizer $decorated) |
42
|
|
|
{ |
43
|
7 |
|
$this->decorated = $decorated; |
44
|
7 |
|
} |
45
|
|
|
|
46
|
|
|
public function hasCacheableSupportsMethod(): bool |
47
|
|
|
{ |
48
|
|
|
return $this->decorated->hasCacheableSupportsMethod(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function denormalize($data, $type, $format = null, array $context = []) |
52
|
|
|
{ |
53
|
|
|
if ($data instanceof UploadedDataUriFile) { |
54
|
|
|
return $data; |
55
|
|
|
} |
56
|
|
|
$this->decorated->denormalize($data, $type, $format, $context); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function supportsDenormalization($data, $type, $format = null): bool |
60
|
|
|
{ |
61
|
|
|
return $this->decorated->supportsDenormalization($data, $type, $format); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function normalize($object, $format = null, array $context = []) |
65
|
|
|
{ |
66
|
|
|
return $this->decorated->normalize($object, $format, $context); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function supportsNormalization($data, $format = null): bool |
70
|
|
|
{ |
71
|
|
|
return $this->decorated->supportsNormalization($data, $format); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|