Files
myep-team/src/Entity/Embeddable/BankAccount.php
T

112 lines
2.7 KiB
PHP

<?php
namespace App\Entity\Embeddable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Embeddable]
class BankAccount
{
#[ORM\Column(nullable: true)]
#[Assert\NotBlank(message: 'Bitte gib die IBAN an', groups: ['profile'])]
#[Assert\Iban(message: 'Bitte gib eine gültige IBAN an', groups: ['profile'])]
private ?string $iban = null;
#[ORM\Column(nullable: true)]
#[Assert\NotBlank(message: 'Bitte gib den BIC an', groups: ['profile'])]
private ?string $bic = null;
#[ORM\Column(nullable: true)]
#[Assert\NotBlank(message: 'Bitte gib den Namen deiner Bank an', groups: ['profile'])]
private ?string $bank = null;
#[ORM\Column(nullable: true)]
#[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) {
return $this->iban;
}
if (null === $iban = $this->getIban()) {
return '';
}
return sprintf('%s*****%s', substr($iban, 0, 6), substr($iban, -4));
}
public function setIban(?string $iban): static
{
$this->iban = $iban;
return $this;
}
public function getBic(): ?string
{
return $this->bic;
}
public function setBic(?string $bic): static
{
$this->bic = $bic;
return $this;
}
public function getBank(): ?string
{
return $this->bank;
}
public function setBank(?string $bank): static
{
$this->bank = $bank;
return $this;
}
public function getHolder(): ?string
{
return $this->holder;
}
public function setHolder(?string $holder): static
{
$this->holder = $holder;
return $this;
}
}