<?php
namespace App\Entity\Structs;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
/**
* @ORM\Embeddable()
*/
class AddressEmbeddable implements JsonSerializable
{
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $recipient = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $organization = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $street = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $unit = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $city = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $state = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $postalCode = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $country = null;
/**
* @return string
*/
public function __toString(): string
{
return $this->getAddress() ?: '';
}
/**
* @param bool $recipient
* @return string|null
*/
public function getAddress(bool $recipient = false): ?string
{
return trim(implode("\n", array_filter([
($recipient) ? $this->getRecipient() : null,
$this->getOrganization(),
$this->getUnit(),
$this->getStreet(),
sprintf(
'%s %s %s',
$this->getCity() ? $this->getCity().',' : '',
$this->getState(),
$this->getPostalCode()
),
]))) ?: null;
}
/**
* @return string|null
*/
public function getRecipient(): ?string
{
return $this->recipient;
}
/**
* @param string|null $recipient
* @return $this
*/
public function setRecipient(?string $recipient): self
{
$this->recipient = $recipient;
return $this;
}
/**
* @return string|null
*/
public function getOrganization(): ?string
{
return $this->organization;
}
/**
* @param string|null $organization
* @return $this
*/
public function setOrganization(?string $organization): self
{
$this->organization = $organization;
return $this;
}
/**
* @return string|null
*/
public function getStreet(): ?string
{
return $this->street;
}
/**
* @param string|null $street
* @return $this
*/
public function setStreet(?string $street): self
{
$this->street = $street;
return $this;
}
/**
* @return string|null
*/
public function getUnit(): ?string
{
return $this->unit;
}
/**
* @param string|null $unit
* @return $this
*/
public function setUnit(?string $unit): self
{
$this->unit = $unit;
return $this;
}
/**
* @return string|null
*/
public function getCity(): ?string
{
return $this->city;
}
/**
* @param string|null $city
* @return $this
*/
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
/**
* @return string|null
*/
public function getState(): ?string
{
return $this->state;
}
/**
* @param string|null $state
* @return $this
*/
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
/**
* @return string|null
*/
public function getPostalCode(): ?string
{
return $this->postalCode;
}
/**
* @param string|null $postalCode
* @return $this
*/
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
/**
* @return string|null
*/
public function getCountry(): ?string
{
return $this->country;
}
/**
* @param string|null $country
* @return $this
*/
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
/**
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
return [
'recipient' => $this->getRecipient(),
'organization' => $this->getOrganization(),
'street' => $this->getStreet(),
'unit' => $this->getUnit(),
'city' => $this->getCity(),
'state' => $this->getState(),
'postcode' => $this->getPostalCode(),
'country' => $this->getCountry(),
];
}
}