<?php declare(strict_types=1);
namespace Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InvalidSerializerFieldException;
use Shopware\Core\Framework\DataAbstractionLayer\Field\EmailField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Field;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Write\DataStack\KeyValuePair;
use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityExistence;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteParameterBag;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* @deprecated tag:v6.5.0 - reason:becomes-internal - Will be internal
*/
class EmailFieldSerializer extends AbstractFieldSerializer
{
public function encode(
Field $field,
EntityExistence $existence,
KeyValuePair $data,
WriteParameterBag $parameters
): \Generator {
if (!$field instanceof EmailField) {
throw new InvalidSerializerFieldException(EmailField::class, $field);
}
$this->validateIfNeeded($field, $existence, $data, $parameters);
yield $field->getStorageName() => $data->getValue();
}
/**
* @return string|null
*
* @deprecated tag:v6.5.0 - reason:return-type-change - The return type will be native typed
*/
public function decode(Field $field, $value)/*: ?string*/
{
return $value;
}
protected function getConstraints(Field $field): array
{
$constraints = [new Email()];
if ($field->is(Required::class)) {
$constraints[] = new NotBlank();
}
return $constraints;
}
}