hydra-sql/src/Altcha/AltchaTransformer.php
Gauthier DUPONT 3c06f6e09e
Some checks reported warnings
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
feat(altcha): add altcha validation layer to login
2025-04-10 12:56:11 +02:00

49 lines
919 B
PHP

<?php
namespace App\Altcha;
use App\Altcha\Form\AltchaModel;
use Symfony\Component\Form\DataTransformerInterface;
class AltchaTransformer implements DataTransformerInterface
{
/**
* {@inheritDoc}
*/
public function reverseTransform($value): AltchaModel
{
if (empty($value)) {
return new AltchaModel();
}
$decodedValue = base64_decode($value);
$data = json_decode($decodedValue);
$model = new AltchaModel();
foreach ($data as $property => $value) {
$model->{$property} = $value;
}
return $model;
}
/**
* {@inheritDoc}
*/
public function transform($value): string
{
if (empty($value)) {
return '';
}
$json = json_encode($value);
if (false === $json) {
return '';
}
return base64_encode($json);
}
}