src/App/Entity/Structs/AddressEmbeddable.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Structs;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JsonSerializable;
  5. /**
  6.  * @ORM\Embeddable()
  7.  */
  8. class AddressEmbeddable implements JsonSerializable
  9. {
  10.     /**
  11.      * @var string|null
  12.      *
  13.      * @ORM\Column(
  14.      *     type = "string",
  15.      *     nullable = true,
  16.      * )
  17.      */
  18.     protected ?string $recipient null;
  19.     /**
  20.      * @var string|null
  21.      *
  22.      * @ORM\Column(
  23.      *     type = "string",
  24.      *     nullable = true,
  25.      * )
  26.      */
  27.     protected ?string $organization null;
  28.     /**
  29.      * @var string|null
  30.      *
  31.      * @ORM\Column(
  32.      *     type = "string",
  33.      *     nullable = true,
  34.      * )
  35.      */
  36.     protected ?string $street null;
  37.     /**
  38.      * @var string|null
  39.      *
  40.      * @ORM\Column(
  41.      *     type = "string",
  42.      *     nullable = true,
  43.      * )
  44.      */
  45.     protected ?string $unit null;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(
  50.      *     type = "string",
  51.      *     nullable = true,
  52.      * )
  53.      */
  54.     protected ?string $city null;
  55.     /**
  56.      * @var string|null
  57.      *
  58.      * @ORM\Column(
  59.      *     type = "string",
  60.      *     nullable = true,
  61.      * )
  62.      */
  63.     protected ?string $state null;
  64.     /**
  65.      * @var string|null
  66.      *
  67.      * @ORM\Column(
  68.      *     type = "string",
  69.      *     nullable = true,
  70.      * )
  71.      */
  72.     protected ?string $postalCode null;
  73.     /**
  74.      * @var string|null
  75.      *
  76.      * @ORM\Column(
  77.      *     type = "string",
  78.      *     nullable = true,
  79.      * )
  80.      */
  81.     protected ?string $country null;
  82.     /**
  83.      * @return string
  84.      */
  85.     public function __toString(): string
  86.     {
  87.         return $this->getAddress() ?: '';
  88.     }
  89.     /**
  90.      * @param bool $recipient
  91.      * @return string|null
  92.      */
  93.     public function getAddress(bool $recipient false): ?string
  94.     {
  95.         return trim(implode("\n"array_filter([
  96.             ($recipient) ? $this->getRecipient() : null,
  97.             $this->getOrganization(),
  98.             $this->getUnit(),
  99.             $this->getStreet(),
  100.             sprintf(
  101.                 '%s %s %s',
  102.                 $this->getCity() ? $this->getCity().',' '',
  103.                 $this->getState(),
  104.                 $this->getPostalCode()
  105.             ),
  106.         ]))) ?: null;
  107.     }
  108.     /**
  109.      * @return string|null
  110.      */
  111.     public function getRecipient(): ?string
  112.     {
  113.         return $this->recipient;
  114.     }
  115.     /**
  116.      * @param string|null $recipient
  117.      * @return $this
  118.      */
  119.     public function setRecipient(?string $recipient): self
  120.     {
  121.         $this->recipient $recipient;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return string|null
  126.      */
  127.     public function getOrganization(): ?string
  128.     {
  129.         return $this->organization;
  130.     }
  131.     /**
  132.      * @param string|null $organization
  133.      * @return $this
  134.      */
  135.     public function setOrganization(?string $organization): self
  136.     {
  137.         $this->organization $organization;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return string|null
  142.      */
  143.     public function getStreet(): ?string
  144.     {
  145.         return $this->street;
  146.     }
  147.     /**
  148.      * @param string|null $street
  149.      * @return $this
  150.      */
  151.     public function setStreet(?string $street): self
  152.     {
  153.         $this->street $street;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return string|null
  158.      */
  159.     public function getUnit(): ?string
  160.     {
  161.         return $this->unit;
  162.     }
  163.     /**
  164.      * @param string|null $unit
  165.      * @return $this
  166.      */
  167.     public function setUnit(?string $unit): self
  168.     {
  169.         $this->unit $unit;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return string|null
  174.      */
  175.     public function getCity(): ?string
  176.     {
  177.         return $this->city;
  178.     }
  179.     /**
  180.      * @param string|null $city
  181.      * @return $this
  182.      */
  183.     public function setCity(?string $city): self
  184.     {
  185.         $this->city $city;
  186.         return $this;
  187.     }
  188.     /**
  189.      * @return string|null
  190.      */
  191.     public function getState(): ?string
  192.     {
  193.         return $this->state;
  194.     }
  195.     /**
  196.      * @param string|null $state
  197.      * @return $this
  198.      */
  199.     public function setState(?string $state): self
  200.     {
  201.         $this->state $state;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return string|null
  206.      */
  207.     public function getPostalCode(): ?string
  208.     {
  209.         return $this->postalCode;
  210.     }
  211.     /**
  212.      * @param string|null $postalCode
  213.      * @return $this
  214.      */
  215.     public function setPostalCode(?string $postalCode): self
  216.     {
  217.         $this->postalCode $postalCode;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return string|null
  222.      */
  223.     public function getCountry(): ?string
  224.     {
  225.         return $this->country;
  226.     }
  227.     /**
  228.      * @param string|null $country
  229.      * @return $this
  230.      */
  231.     public function setCountry(?string $country): self
  232.     {
  233.         $this->country $country;
  234.         return $this;
  235.     }
  236.     /**
  237.      * {@inheritDoc}
  238.      */
  239.     public function jsonSerialize(): array
  240.     {
  241.         return [
  242.             'recipient' => $this->getRecipient(),
  243.             'organization' => $this->getOrganization(),
  244.             'street' => $this->getStreet(),
  245.             'unit' => $this->getUnit(),
  246.             'city' => $this->getCity(),
  247.             'state' => $this->getState(),
  248.             'postcode' => $this->getPostalCode(),
  249.             'country' => $this->getCountry(),
  250.         ];
  251.     }
  252. }