Files
hydra-sql/src/Altcha/AltchaTransformer.php
Gauthier DUPONT 12523398f6
Some checks are pending
Cadoles/hydra-sql/pipeline/pr-develop Build started...
feat(altcha): add altcha validation layer to login
2025-04-10 16:01:22 +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);
}
}