-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormDataEncoder.php
More file actions
42 lines (32 loc) · 929 Bytes
/
FormDataEncoder.php
File metadata and controls
42 lines (32 loc) · 929 Bytes
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
<?php
namespace SyncEngine\Service\Serializer;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use SyncEngine\Service\Interface\CodecInterface;
class FormDataEncoder implements CodecInterface
{
const FORMAT = 'formdata';
protected function recursiveToString( $data ): array|string
{
if ( is_array( $data ) ) {
return array_map( [ $this, 'recursiveToString' ], $data );
}
return (string) $data;
}
public function encode( mixed $data, string $format, array $context = [] ): string
{
return ( new FormDataPart( (array) $this->recursiveToString( $data ) ) )->bodyToString();
}
public function decode( string $data, string $format, array $context = [] ): array
{
parse_str( $data, $parsed );
return $parsed;
}
public function supportsEncoding( string $format ): bool
{
return self::FORMAT === $format;
}
public function supportsDecoding( string $format ): bool
{
return false;
}
}