feat: add validations

feat: add forms

feat: add validations

validations

InexController
This commit is contained in:
Ondrej Vlach 2024-01-16 23:00:30 +01:00
parent 248b25576b
commit 63783cb90f
Signed by: ovlach
GPG Key ID: 4FF1A23B4914DE70
6 changed files with 76 additions and 3 deletions

View File

@ -1,6 +1,8 @@
framework:
validation:
email_validation_mode: html5
enabled: true
translation_domain: validation_errors
# Enables validator auto-mapping support.
# For instance, basic validation constraints will be inferred from Doctrine's metadata.

View File

@ -2,30 +2,47 @@
declare(strict_types=1);
namespace App\Entity\QRCode;
use Symfony\Component\Validator\Constraints as Assert;
/**
* QRCode description
*/
class QRCode
{
#[Assert\NotBlank]
#[Assert\Iban(
message: 'messages.not_a_iban_number',
)]
private ?string $iban;
#[Assert\NotBlank(message: 'messages.fill_value')]
#[Assert\GreaterThanOrEqual(
'today', message: 'messages.invalid_date'
)]
private ?\DateTime $dueDate;
#[Assert\NotBlank(message: 'messages.fill_value')]
private ?string $message;
#[Assert\Valid]
#[Assert\NotBlank]
private ?QRCodeMoney $money;
#[Assert\Valid]
#[Assert\NotBlank]
private ?QRCodePaymentIdentification $paymentIdentification;
#[Assert\Valid]
#[Assert\NotBlank]
private readonly QRCodeQROptions $codeQROptions;
/**
* @param QRCodeQROptions $codeQROptions
* @param string|null $iban
* @param string|null $dueDate
* @param \DateTime|null $dueDate
* @param string|null $message
* @param QRCodeMoney|null $money
*/
public function __construct(
QRCodeQROptions $codeQROptions,
?string $iban = null,
?string $dueDate = null,
?\DateTime $dueDate = null,
?string $message = null,
?QRCodeMoney $money = null)
{

View File

@ -3,13 +3,22 @@ declare(strict_types=1);
namespace App\Entity\QRCode;
use App\Service\CurrencyListerInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Money type for QR code
*/
class QRCodeMoney
{
#[Assert\Positive(
message: 'messages.not_valid_amount',
)]
#[Assert\NotBlank(message: 'messages.fill_value')]
private ?string $amount;
// TODO: getCurrencies validation
#[Assert\NotBlank(message: 'messages.fill_value')]
private ?string $currency;
/**

View File

@ -3,12 +3,46 @@ declare(strict_types=1);
namespace App\Entity\QRCode;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Payment identification for QR code
*/
class QRCodePaymentIdentification {
#[Assert\NotBlank(message: 'messages.fill_value')]
#[Assert\Length( // <<< Ano, mohl jsem si napsat vlastni validator ...
min: 1,
max: 10,
minMessage: 'messages.not_variable_symbol',
maxMessage: 'messages.not_variable_symbol',
)] // https://en.wikipedia.org/wiki/Variable_symbol
#[Assert\Positive(
message: 'messages.not_variable_symbol',
)]
private string $variableSymbol;
#[Assert\NotBlank(message: 'messages.fill_value')]
#[Assert\Length(
min: 1,
max: 10,
minMessage: 'messages.not_specific_symbol',
maxMessage: 'messages.not_specific_symbol',
)] // https://cs.wikipedia.org/wiki/Specifick%C3%BD_symbol
#[Assert\Positive(
message: 'The {{ value }} is not a variable symbol.',
)]
private string $specificSymbol;
#[Assert\NotBlank(message: 'messages.fill_value')]
#[Assert\Length(
min: 1,
max: 10,
minMessage: 'messages.not_constant_symbol',
maxMessage: 'messages.not_constant_symbol',
)] // https://www.hyponamiru.cz/en/glossary/constant-symbol/
#[Assert\Positive(
message: 'messages.not_constant_symbol',
)]
private string $constantSymbol;
public function getVariableSymbol(): string

View File

@ -3,11 +3,22 @@ declare(strict_types=1);
namespace App\Entity\QRCode;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Options for generating QR code
*/
readonly class QRCodeQROptions {
#[Assert\Positive(
message: 'messages.scale_must_be_positive',
)]
#[Assert\NotBlank(message: 'messages.fill_value')]
private int $scale;
#[Assert\PositiveOrZero(
message: 'messages.margin_must_be_positive',
)]
#[Assert\NotBlank(message: 'messages.fill_value')]
private int $margin;
/**

View File

@ -22,7 +22,7 @@ class QRCodeType extends AbstractType
->add('message', TextType::class)
->add('money', QRCodeMoneyType::class)
->add('paymentIdentification', QRCodePaymentIdentificationType::class)
->add('save', SubmitType::class);
->add('generate_qr_code', SubmitType::class);
}
public function configureOptions(OptionsResolver $resolver): void