-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymfonySerializerConverterFactory.php
44 lines (37 loc) · 1.27 KB
/
SymfonySerializerConverterFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Retrofit\Converter\SymfonySerializer;
use Retrofit\Core\Converter\ConverterFactory;
use Retrofit\Core\Converter\RequestBodyConverter;
use Retrofit\Core\Converter\ResponseBodyConverter;
use Retrofit\Core\Converter\StringConverter;
use Retrofit\Core\Type;
use Symfony\Component\Serializer\Serializer;
/**
* {@link https://symfony.com/doc/current/components/serializer.html Symfony Serializer} converter factory implementation.
*
* @see ConverterFactory
*
* @api
*/
readonly class SymfonySerializerConverterFactory implements ConverterFactory
{
public function __construct(
private Serializer $serializer,
private SymfonySerializerFormat $symfonySerializerFormat = SymfonySerializerFormat::JSON,
)
{
}
public function requestBodyConverter(Type $type): ?RequestBodyConverter
{
return new SymfonySerializerRequestBodyConverter($this->serializer, $this->symfonySerializerFormat, $type);
}
public function responseBodyConverter(Type $type): ?ResponseBodyConverter
{
return new SymfonySerializerResponseBodyConverter($this->serializer, $this->symfonySerializerFormat, $type);
}
public function stringConverter(Type $type): ?StringConverter
{
return null;
}
}