validFrom = new DateTime(); } public static function createFromAddress(Address $original): Address { return (new Address()) ->setAddressReference($original->getAddressReference()) ->setBuildingName($original->getBuildingName()) ->setConfidential($original->getConfidential()) ->setCorridor($original->getCorridor()) ->setCustoms($original->getCustoms()) ->setDistribution($original->getDistribution()) ->setExtra($original->getExtra()) ->setFlat($original->getFlat()) ->setFloor($original->getFloor()) ->setIsNoAddress($original->getIsNoAddress()) ->setLinkedToThirdParty($original->getLinkedToThirdParty()) ->setPoint($original->getPoint()) ->setPostcode($original->getPostcode()) ->setSteps($original->getSteps()) ->setStreet($original->getStreet()) ->setStreetNumber($original->getStreetNumber()) ->setValidFrom($original->getValidFrom()) ->setValidTo($original->getValidTo()); } public static function createFromAddressReference(AddressReference $original): Address { return (new Address()) ->setPoint($original->getPoint()) ->setPostcode($original->getPostcode()) ->setStreet($original->getStreet()) ->setStreetNumber($original->getStreetNumber()) ->setAddressReference($original); } public function getAddressReference(): ?AddressReference { return $this->addressReference; } public function getBuildingName(): ?string { return $this->buildingName; } public function getConfidential(): bool { return $this->confidential; } public function getCorridor(): ?string { return $this->corridor; } /** * Get customs informations in the address. */ public function getCustoms(): array { return $this->customs; } public function getDistribution(): ?string { return $this->distribution; } public function getExtra(): ?string { return $this->extra; } public function getFlat(): ?string { return $this->flat; } public function getFloor(): ?string { return $this->floor; } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Get IsNoAddress. * * Indicate true if the address is a fake address (homeless, ...) */ public function getIsNoAddress(): bool { return $this->isNoAddress; } public function getLinkedToThirdParty() { return $this->linkedToThirdParty; } public function getPoint(): ?Point { return $this->point; } /** * Get postcode. * * @return PostalCode */ public function getPostcode() { return $this->postcode; } public function getSteps(): ?string { return $this->steps; } public function getStreet(): ?string { return $this->street; } /** * Get streetAddress1 (legacy function). * * @return string */ public function getStreetAddress1() { return $this->street; } /** * Get streetAddress2 (legacy function). * * @return string */ public function getStreetAddress2() { return $this->streetNumber; } public function getStreetNumber(): ?string { return $this->streetNumber; } /** * @return DateTime */ public function getValidFrom() { return $this->validFrom; } public function getValidTo(): ?DateTimeInterface { return $this->validTo; } public function isNoAddress(): bool { return $this->getIsNoAddress(); } public function setAddressReference(?AddressReference $addressReference = null): Address { $this->addressReference = $addressReference; return $this; } public function setBuildingName(?string $buildingName): self { $this->buildingName = $buildingName; return $this; } public function setConfidential(bool $confidential): self { $this->confidential = $confidential; return $this; } public function setCorridor(?string $corridor): self { $this->corridor = $corridor; return $this; } /** * Store custom informations in the address. * * @return $this */ public function setCustoms(array $customs): self { $this->customs = $customs; return $this; } public function setDistribution(?string $distribution): self { $this->distribution = $distribution; return $this; } public function setExtra(?string $extra): self { $this->extra = $extra; return $this; } public function setFlat(?string $flat): self { $this->flat = $flat; return $this; } public function setFloor(?string $floor): self { $this->floor = $floor; return $this; } /** * Set IsNoAddress. * * Indicate true if the address is a fake address (homeless, ...) * * @return $this */ public function setIsNoAddress(bool $isNoAddress): self { $this->isNoAddress = $isNoAddress; return $this; } public function setLinkedToThirdParty($linkedToThirdParty): self { $this->linkedToThirdParty = $linkedToThirdParty; return $this; } public function setPoint(?Point $point): self { $this->point = $point; return $this; } /** * Set postcode. * * @param PostalCode $postcode * * @return Address */ public function setPostcode(?PostalCode $postcode = null) { $this->postcode = $postcode; return $this; } public function setSteps(?string $steps): self { $this->steps = $steps; return $this; } public function setStreet(string $street): self { $this->street = $street; return $this; } /** * Set streetAddress1 (legacy function). * * @param string $streetAddress1 * * @return Address */ public function setStreetAddress1($streetAddress1) { $this->street = null === $streetAddress1 ? '' : $streetAddress1; return $this; } /** * Set streetAddress2 (legacy function). * * @param string $streetAddress2 * * @return Address */ public function setStreetAddress2($streetAddress2) { $this->streetNumber = null === $streetAddress2 ? '' : $streetAddress2; return $this; } public function setStreetNumber(string $streetNumber): self { $this->streetNumber = $streetNumber; return $this; } /** * @return Address */ public function setValidFrom(DateTime $validFrom) { $this->validFrom = $validFrom; return $this; } public function setValidTo(?DateTimeInterface $validTo = null): self { $this->validTo = $validTo; return $this; } /** * Validate the address. * * Check that: * * * if the address is not home address: * * the postal code is present * * the valid from is not null * * the address street 1 is greater than 2 * * @param array $payload */ public function validate(ExecutionContextInterface $context, $payload) { if (!$this->getValidFrom() instanceof DateTime) { $context ->buildViolation('address.date-should-be-set') ->atPath('validFrom') ->addViolation(); } if ($this->isNoAddress()) { return; } if (empty($this->getStreetAddress1())) { $context ->buildViolation('address.street1-should-be-set') ->atPath('streetAddress1') ->addViolation(); } if (!$this->getPostcode() instanceof PostalCode) { $context ->buildViolation('address.postcode-should-be-set') ->atPath('postCode') ->addViolation(); } } }