Skip to content

Instantly share code, notes, and snippets.

@mikaelz
Created November 21, 2023 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelz/536d19961e5ae224472477f528e50533 to your computer and use it in GitHub Desktop.
Save mikaelz/536d19961e5ae224472477f528e50533 to your computer and use it in GitHub Desktop.
<?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