<?php
namespace App\Entity;
use App\Entity\Abstract\Entity;
use App\Repository\AddressRepository;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AddressRepository::class)]
#[Index(name: "address_zip_city_street_idx", columns: ["zip", "city", "street"])]
class Address extends Entity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(groups: ['address'])]
private ?string $street = null;
#[ORM\Column(nullable: true)]
#[Assert\NotBlank(groups: ['address'])]
#[Assert\Positive]
#[Assert\Length(min:'4',max:'5')]
private ?int $zip = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank(groups: ['address'])]
private ?string $city = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $zipFeatureId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $addressFeatureId = null;
#[ORM\Column(length: 30, nullable: true)]
private ?string $country = null;
public function getId(): ?int
{
return $this->id;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(?string $street): self
{
$this->street = $street;
return $this;
}
public function getZip(): ?int
{
return $this->zip;
}
public function setZip(?int $zip): self
{
$this->zip = $zip;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getZipFeatureId(): ?string
{
return $this->zipFeatureId;
}
public function setZipFeatureId(?string $zipFeatureId): self
{
$this->zipFeatureId = $zipFeatureId;
return $this;
}
public function getAddressFeatureId(): ?string
{
return $this->addressFeatureId;
}
public function setAddressFeatureId(?string $addressFeatureId): self
{
$this->addressFeatureId = $addressFeatureId;
return $this;
}
/**
* @return string
*/
public function getAddressString(): string
{
if(!empty($this->street) && !empty($this->zip) && !empty($this->city)){
return sprintf("%s %s %s", $this->street, $this->zip, $this->city);
}
return '';
}
public function clearCityIfZipMissing(): void
{
if(empty($this->zip)){
$this->city = '';
}
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): static
{
$this->country = $country;
return $this;
}
}