|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jellyfish\SerializerSymfony\NameConverter; |
|
4
|
|
|
|
|
5
|
|
|
use Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyProviderInterface; |
|
6
|
|
|
|
|
7
|
|
|
class PropertyNameConverter implements PropertyNameConverterInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var \Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyProviderInterface |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $strategyProvider; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param \Jellyfish\Serializer\NameConverter\PropertyNameConverterStrategyProviderInterface $strategyProvider |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(PropertyNameConverterStrategyProviderInterface $strategyProvider) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->strategyProvider = $strategyProvider; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $propertyName |
|
24
|
|
|
* @param string|null $class |
|
25
|
|
|
* @param string|null $format |
|
26
|
|
|
* |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
public function normalize($propertyName, ?string $class = null, ?string $format = null): string |
|
30
|
|
|
{ |
|
31
|
|
|
foreach ($this->strategyProvider->getAllStrategies() as $strategy) { |
|
32
|
|
|
$convertedPropertyName = $strategy->convertAfterNormalize($propertyName, $class, $format); |
|
33
|
|
|
|
|
34
|
|
|
if ($convertedPropertyName !== null) { |
|
35
|
|
|
return $convertedPropertyName; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $propertyName; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $propertyName |
|
44
|
|
|
* @param string|null $class |
|
45
|
|
|
* @param string|null $format |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function denormalize($propertyName, ?string $class = null, ?string $format = null): string |
|
50
|
|
|
{ |
|
51
|
|
|
foreach ($this->strategyProvider->getAllStrategies() as $strategy) { |
|
52
|
|
|
$convertedPropertyName = $strategy->convertAfterDenormalize($propertyName, $class, $format); |
|
53
|
|
|
|
|
54
|
|
|
if ($convertedPropertyName !== null) { |
|
55
|
|
|
return $convertedPropertyName; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $propertyName; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|