1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\JoseFramework\Normalizer; |
15
|
|
|
|
16
|
|
|
use Jose\Component\Encryption\JWE; |
17
|
|
|
use Jose\Component\Encryption\Serializer\JWESerializerManager; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
19
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
20
|
|
|
|
21
|
|
|
final class JWENormalizer implements NormalizerInterface, DenormalizerInterface |
22
|
|
|
{ |
23
|
|
|
public function supportsNormalization($data, $format = null) |
24
|
|
|
{ |
25
|
|
|
return $data instanceof JWE && $this->componentInstalled(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
29
|
|
|
{ |
30
|
|
|
return JWE::class === $type && $this->componentInstalled(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed $object Object to normalize |
35
|
|
|
* @param string $format Format the normalization result will be encoded as |
36
|
|
|
* |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function normalize($object, $format = null, array $context = []) |
40
|
|
|
{ |
41
|
|
|
return $object; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param mixed $data Data to restore |
46
|
|
|
* @param string $type The expected class to instantiate |
47
|
|
|
* @param string $format Format the given data was extracted from |
48
|
|
|
* |
49
|
|
|
* @return array|object |
50
|
|
|
*/ |
51
|
|
|
public function denormalize($data, $type, $format = null, array $context = []) |
52
|
|
|
{ |
53
|
|
|
return $data; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Check if encryption component is installed. |
58
|
|
|
*/ |
59
|
|
|
private function componentInstalled(): bool |
60
|
|
|
{ |
61
|
|
|
return class_exists(JWESerializerManager::class); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|