Created
November 21, 2023 12:15
-
-
Save mikaelz/536d19961e5ae224472477f528e50533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Infrastructure\Serializer; | |
use Symfony\Component\Serializer\Encoder\DecoderInterface; | |
use Symfony\Component\Serializer\Encoder\EncoderInterface; | |
class FormEncoder implements EncoderInterface, DecoderInterface | |
{ | |
public const FORMAT = 'form'; | |
public function decode(string $data, string $format, array $context = []): array | |
{ | |
parse_str($data, $result); | |
return $result; | |
} | |
public function supportsDecoding(string $format): bool | |
{ | |
return self::FORMAT === $format; | |
} | |
public function encode(mixed $data, string $format, array $context = []): string | |
{ | |
return http_build_query($data); | |
} | |
public function supportsEncoding(string $format): bool | |
{ | |
return self::FORMAT === $format; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment