Feat: Refactor profile data validation
This commit is contained in:
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\Validator\Constraints as AppAssert;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
#[AppAssert\Address(message: 'Bitte vervollständige deine Anschrift', groups: ['profile_preflight'])]
|
||||
class Address
|
||||
{
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
@@ -27,6 +26,32 @@ class Address
|
||||
#[Assert\NotBlank(message: 'Bitte gib deinen Land an', groups: ['profile'])]
|
||||
protected ?string $country = null;
|
||||
|
||||
#[Assert\Callback(groups: ['profile_preflight'])]
|
||||
public function preflightCheck(ExecutionContextInterface $executionContext): void
|
||||
{
|
||||
$missing = [];
|
||||
|
||||
if (empty($this->getStreet())) {
|
||||
$missing[] = 'Straße';
|
||||
}
|
||||
if (empty($this->getCity())) {
|
||||
$missing[] = 'Ort';
|
||||
}
|
||||
if (empty($this->getPostCode())) {
|
||||
$missing[] = 'PLZ';
|
||||
}
|
||||
if (empty($this->getCountry())) {
|
||||
$missing[] = 'Land';
|
||||
}
|
||||
|
||||
if (0 < count($missing)) {
|
||||
$executionContext
|
||||
->buildViolation(sprintf('Bitte vervollständige deine Anschrift (%s).', implode(', ', $missing)))
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public function toPayload(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\Validator\Constraints as AppAssert;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
#[AppAssert\BankAccount(message: 'Bitte vervollständige deine Bankverbindung', groups: ['profile_preflight'])]
|
||||
class BankAccount
|
||||
{
|
||||
#[ORM\Column(nullable: true)]
|
||||
@@ -27,6 +26,33 @@ class BankAccount
|
||||
#[Assert\NotBlank(message: 'Bitte gib den Kontoinhaber an', groups: ['profile'])]
|
||||
private ?string $holder = null;
|
||||
|
||||
#[Assert\Callback(groups: ['profile_preflight'])]
|
||||
public function preflightCheck(ExecutionContextInterface $executionContext): void
|
||||
{
|
||||
$missing = [];
|
||||
|
||||
if (empty($this->getIban())) {
|
||||
$missing[] = 'IBAN';
|
||||
}
|
||||
if (empty($this->getBic())) {
|
||||
$missing[] = 'BIC';
|
||||
}
|
||||
if (empty($this->getBank())) {
|
||||
$missing[] = 'Name der Bank';
|
||||
}
|
||||
if (empty($this->getHolder())) {
|
||||
$missing[] = 'Kontoinhaber';
|
||||
}
|
||||
|
||||
if (0 < count($missing)) {
|
||||
$executionContext
|
||||
->buildViolation(sprintf('Bitte vervollständige deine Bankverbindung (%s)', implode(', ', $missing)))
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getIban(bool $obfuscated = false): ?string
|
||||
{
|
||||
if (false === $obfuscated) {
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\Validator\Constraints as AppAssert;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
#[AppAssert\Communication(message: 'Bitte vervollständige deine Kontaktdaten', groups: ['profile_preflight'])]
|
||||
class Communication
|
||||
{
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
@@ -23,6 +22,26 @@ class Communication
|
||||
#[Assert\NotBlank(message: 'Bitte gib deine E-Mail-Adresse an', groups: ['profile'])]
|
||||
protected ?string $email = null;
|
||||
|
||||
#[Assert\Callback(groups: ['profile_preflight'])]
|
||||
public function preflightCheck(ExecutionContextInterface $executionContext): void
|
||||
{
|
||||
$missing = [];
|
||||
|
||||
if (empty($this->getEmail())) {
|
||||
$missing[] = 'E-Mail';
|
||||
}
|
||||
if (empty($this->getMobile())) {
|
||||
$missing[] = 'Mobilnummer';
|
||||
}
|
||||
|
||||
if (0 < count($missing)) {
|
||||
$executionContext
|
||||
->buildViolation(sprintf('Bitte vervollständige deine Kontaktdaten (%s)', implode(', ', $missing)))
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public function toPayload(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user