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\HttpFoundation\File\File; |
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, NormalizerInterface, DenormalizerInterface |
35
|
|
|
{ |
36
|
|
|
use DenormalizerAwareTrait; |
37
|
|
|
use NormalizerAwareTrait; |
38
|
|
|
|
39
|
|
|
private NormalizerInterface|SymfonyDataUriNormalizer $decorated; |
40
|
|
|
|
41
|
|
|
public function __construct(NormalizerInterface|SymfonyDataUriNormalizer $decorated) |
42
|
|
|
{ |
43
|
|
|
$this->decorated = $decorated; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function denormalize($data, $type, $format = null, array $context = []): mixed |
47
|
|
|
{ |
48
|
|
|
if ($data instanceof UploadedDataUriFile || ($data instanceof File && '' === $data->getPath())) { |
49
|
|
|
return $data; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $this->decorated->denormalize($data, $type, $format, $context); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool |
56
|
|
|
{ |
57
|
|
|
return $this->decorated->supportsDenormalization($data, $type, $format, $context); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function normalize($object, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null |
61
|
|
|
{ |
62
|
|
|
return $this->decorated->normalize($object, $format, $context); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function supportsNormalization($data, $format = null, array $context = []): bool |
66
|
|
|
{ |
67
|
|
|
return $this->decorated->supportsNormalization($data, $format, $context); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getSupportedTypes(?string $format): array |
71
|
|
|
{ |
72
|
|
|
return $this->decorated->getSupportedTypes($format); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.