clearCountryCode(); $this->clearNationalNumber(); $this->clearExtension(); $this->clearItalianLeadingZero(); $this->clearNumberOfLeadingZeros(); $this->clearRawInput(); $this->clearCountryCodeSource(); $this->clearPreferredDomesticCarrierCode(); return $this; } public function clearCountryCode(): static { $this->countryCode = null; return $this; } public function clearNationalNumber(): static { $this->nationalNumber = null; return $this; } public function clearExtension(): static { $this->extension = null; return $this; } public function clearItalianLeadingZero(): static { $this->italianLeadingZero = null; return $this; } public function clearNumberOfLeadingZeros(): static { $this->hasNumberOfLeadingZeros = false; $this->numberOfLeadingZeros = 1; return $this; } public function clearRawInput(): static { $this->rawInput = null; return $this; } public function clearCountryCodeSource(): static { $this->countryCodeSource = CountryCodeSource::UNSPECIFIED; return $this; } public function clearPreferredDomesticCarrierCode(): static { $this->preferredDomesticCarrierCode = null; return $this; } /** * Merges the information from another phone number into this phone number. */ public function mergeFrom(PhoneNumber $other): static { if ($other->hasCountryCode()) { $this->setCountryCode($other->getCountryCode()); } if ($other->hasNationalNumber()) { $this->setNationalNumber($other->getNationalNumber()); } if ($other->hasExtension()) { $this->setExtension($other->getExtension()); } if ($other->hasItalianLeadingZero()) { $this->setItalianLeadingZero($other->isItalianLeadingZero()); } if ($other->hasNumberOfLeadingZeros()) { $this->setNumberOfLeadingZeros($other->getNumberOfLeadingZeros()); } if ($other->hasRawInput()) { $this->setRawInput($other->getRawInput()); } if ($other->hasCountryCodeSource()) { $this->setCountryCodeSource($other->getCountryCodeSource()); } if ($other->hasPreferredDomesticCarrierCode()) { $this->setPreferredDomesticCarrierCode($other->getPreferredDomesticCarrierCode()); } return $this; } public function hasCountryCode(): bool { return $this->countryCode !== null; } public function getCountryCode(): ?int { return $this->countryCode; } public function setCountryCode(int $value): static { $this->countryCode = $value; return $this; } public function hasNationalNumber(): bool { return $this->nationalNumber !== null; } public function getNationalNumber(): ?string { return $this->nationalNumber; } public function setNationalNumber(string $value): static { $this->nationalNumber = $value; return $this; } public function hasExtension(): bool { return isset($this->extension) && $this->extension !== ''; } public function getExtension(): ?string { return $this->extension; } public function setExtension(string $value): static { $this->extension = $value; return $this; } public function hasItalianLeadingZero(): bool { return isset($this->italianLeadingZero); } public function setItalianLeadingZero(bool $value): static { $this->italianLeadingZero = $value; return $this; } /** * Returns whether this phone number uses an italian leading zero. * * @return bool|null True if it uses an italian leading zero, false it it does not, null if not set. */ public function isItalianLeadingZero(): ?bool { return $this->italianLeadingZero ?? null; } public function hasNumberOfLeadingZeros(): bool { return $this->hasNumberOfLeadingZeros; } public function getNumberOfLeadingZeros(): int { return $this->numberOfLeadingZeros; } public function setNumberOfLeadingZeros(int $value): static { $this->hasNumberOfLeadingZeros = true; $this->numberOfLeadingZeros = $value; return $this; } public function hasRawInput(): bool { return isset($this->rawInput); } public function getRawInput(): ?string { return $this->rawInput; } public function setRawInput(string $value): static { $this->rawInput = $value; return $this; } public function hasCountryCodeSource(): bool { return $this->countryCodeSource !== CountryCodeSource::UNSPECIFIED; } public function getCountryCodeSource(): ?CountryCodeSource { return $this->countryCodeSource; } public function setCountryCodeSource(CountryCodeSource $value): static { $this->countryCodeSource = $value; return $this; } public function hasPreferredDomesticCarrierCode(): bool { return isset($this->preferredDomesticCarrierCode); } public function getPreferredDomesticCarrierCode(): ?string { return $this->preferredDomesticCarrierCode; } public function setPreferredDomesticCarrierCode(string $value): static { $this->preferredDomesticCarrierCode = $value; return $this; } /** * Returns whether this phone number is equal to another. * * @param PhoneNumber $other The phone number to compare. * * @return bool True if the phone numbers are equal, false otherwise. */ public function equals(PhoneNumber $other): bool { if ($this === $other) { return true; } return $this->countryCode === $other->countryCode && $this->nationalNumber === $other->nationalNumber && $this->extension === $other->extension && $this->italianLeadingZero === $other->italianLeadingZero && $this->numberOfLeadingZeros === $other->numberOfLeadingZeros && $this->rawInput === $other->rawInput && $this->countryCodeSource === $other->countryCodeSource && $this->preferredDomesticCarrierCode === $other->preferredDomesticCarrierCode; } /** * Returns a string representation of this phone number. */ public function __toString(): string { $outputString = 'Country Code: ' . $this->countryCode; $outputString .= ' National Number: ' . $this->nationalNumber; if ($this->hasItalianLeadingZero()) { $outputString .= ' Leading Zero(s): true'; } if ($this->hasNumberOfLeadingZeros()) { $outputString .= ' Number of leading zeros: ' . $this->numberOfLeadingZeros; } if ($this->hasExtension()) { $outputString .= ' Extension: ' . $this->extension; } if ($this->hasCountryCodeSource()) { $outputString .= ' Country Code Source: ' . $this->countryCodeSource->name; } if ($this->hasPreferredDomesticCarrierCode()) { $outputString .= ' Preferred Domestic Carrier Code: ' . $this->preferredDomesticCarrierCode; } return $outputString; } public function serialize(): ?string { return serialize($this->__serialize()); } public function __serialize(): array { return [ $this->countryCode, $this->nationalNumber, $this->extension, $this->italianLeadingZero, $this->numberOfLeadingZeros, $this->rawInput, $this->countryCodeSource, $this->preferredDomesticCarrierCode, ]; } public function unserialize($data): void { $this->__unserialize(unserialize($data, ['allowed_classes' => [__CLASS__]])); } /** * @param array{int,string,string,bool|null,int,string|null,CountryCodeSource|null,string|null} $data */ public function __unserialize(array $data): void { [ $this->countryCode, $this->nationalNumber, $this->extension, $this->italianLeadingZero, $this->numberOfLeadingZeros, $this->rawInput, $countryCodeSource, $this->preferredDomesticCarrierCode ] = $data; // BC layer to allow this method to unserialize "old" phonenumbers if (is_int($countryCodeSource)) { $countryCodeSource = CountryCodeSource::from($countryCodeSource); } $this->countryCodeSource = $countryCodeSource; if ($this->numberOfLeadingZeros > 1) { $this->hasNumberOfLeadingZeros = true; } } }