| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- <?php
- namespace libphonenumber;
- /**
- * Number Format
- */
- class NumberFormat
- {
- /**
- * @var string
- */
- protected $pattern;
- /**
- * @var bool
- */
- protected $hasPattern = false;
- /**
- * @var string
- */
- protected $format;
- /**
- * @var bool
- */
- protected $hasFormat = false;
- /**
- * @var array
- */
- protected $leadingDigitsPattern = array();
- /**
- * @var string
- */
- protected $nationalPrefixFormattingRule = '';
- /**
- * @var bool
- */
- protected $hasNationalPrefixFormattingRule = false;
- /**
- * @var bool
- */
- protected $nationalPrefixOptionalWhenFormatting = false;
- /**
- * @var bool
- */
- protected $hasNationalPrefixOptionalWhenFormatting = false;
- /**
- * @var string
- */
- protected $domesticCarrierCodeFormattingRule = '';
- /**
- * @var bool
- */
- protected $hasDomesticCarrierCodeFormattingRule = false;
- public function __construct()
- {
- $this->clear();
- }
- /**
- * @return NumberFormat
- */
- public function clear()
- {
- $this->hasPattern = false;
- $this->pattern = null;
- $this->hasFormat = false;
- $this->format = null;
- $this->leadingDigitsPattern = array();
- $this->hasNationalPrefixFormattingRule = false;
- $this->nationalPrefixFormattingRule = '';
- $this->hasNationalPrefixOptionalWhenFormatting = false;
- $this->nationalPrefixOptionalWhenFormatting = false;
- $this->hasDomesticCarrierCodeFormattingRule = false;
- $this->domesticCarrierCodeFormattingRule = '';
- return $this;
- }
- /**
- * @return boolean
- */
- public function hasPattern()
- {
- return $this->hasPattern;
- }
- /**
- * @return string
- */
- public function getPattern()
- {
- return $this->pattern;
- }
- /**
- * @param string $value
- * @return NumberFormat
- */
- public function setPattern($value)
- {
- $this->hasPattern = true;
- $this->pattern = $value;
- return $this;
- }
- /**
- * @return boolean
- */
- public function hasNationalPrefixOptionalWhenFormatting()
- {
- return $this->hasNationalPrefixOptionalWhenFormatting;
- }
- /**
- * @return boolean
- */
- public function getNationalPrefixOptionalWhenFormatting()
- {
- return $this->nationalPrefixOptionalWhenFormatting;
- }
- /**
- * @param boolean $nationalPrefixOptionalWhenFormatting
- */
- public function setNationalPrefixOptionalWhenFormatting($nationalPrefixOptionalWhenFormatting)
- {
- $this->hasNationalPrefixOptionalWhenFormatting = true;
- $this->nationalPrefixOptionalWhenFormatting = $nationalPrefixOptionalWhenFormatting;
- }
- /**
- * @return boolean
- */
- public function hasFormat()
- {
- return $this->hasFormat;
- }
- /**
- * @return string
- */
- public function getFormat()
- {
- return $this->format;
- }
- /**
- * @param string $value
- * @return NumberFormat
- */
- public function setFormat($value)
- {
- $this->hasFormat = true;
- $this->format = $value;
- return $this;
- }
- /**
- * @return string[]
- */
- public function leadingDigitPatterns()
- {
- return $this->leadingDigitsPattern;
- }
- /**
- * @return int
- */
- public function leadingDigitsPatternSize()
- {
- return count($this->leadingDigitsPattern);
- }
- /**
- * @param int $index
- * @return string
- */
- public function getLeadingDigitsPattern($index)
- {
- return $this->leadingDigitsPattern[$index];
- }
- /**
- * @param string $value
- * @return NumberFormat
- */
- public function addLeadingDigitsPattern($value)
- {
- $this->leadingDigitsPattern[] = $value;
- return $this;
- }
- /**
- * @return boolean
- */
- public function hasNationalPrefixFormattingRule()
- {
- return $this->hasNationalPrefixFormattingRule;
- }
- /**
- * @return string
- */
- public function getNationalPrefixFormattingRule()
- {
- return $this->nationalPrefixFormattingRule;
- }
- /**
- * @param string $value
- * @return NumberFormat
- */
- public function setNationalPrefixFormattingRule($value)
- {
- $this->hasNationalPrefixFormattingRule = true;
- $this->nationalPrefixFormattingRule = (string)$value;
- return $this;
- }
- /**
- * @return NumberFormat
- */
- public function clearNationalPrefixFormattingRule()
- {
- $this->nationalPrefixFormattingRule = '';
- return $this;
- }
- /**
- * @return boolean
- */
- public function hasDomesticCarrierCodeFormattingRule()
- {
- return $this->hasDomesticCarrierCodeFormattingRule;
- }
- /**
- * @return string
- */
- public function getDomesticCarrierCodeFormattingRule()
- {
- return $this->domesticCarrierCodeFormattingRule;
- }
- /**
- * @param string $value
- * @return NumberFormat
- */
- public function setDomesticCarrierCodeFormattingRule($value)
- {
- $this->hasDomesticCarrierCodeFormattingRule = true;
- $this->domesticCarrierCodeFormattingRule = (string)$value;
- return $this;
- }
- /**
- * @param NumberFormat $other
- * @return NumberFormat
- */
- public function mergeFrom(NumberFormat $other)
- {
- if ($other->hasPattern()) {
- $this->setPattern($other->getPattern());
- }
- if ($other->hasFormat()) {
- $this->setFormat($other->getFormat());
- }
- $leadingDigitsPatternSize = $other->leadingDigitsPatternSize();
- for ($i = 0; $i < $leadingDigitsPatternSize; $i++) {
- $this->addLeadingDigitsPattern($other->getLeadingDigitsPattern($i));
- }
- if ($other->hasNationalPrefixFormattingRule()) {
- $this->setNationalPrefixFormattingRule($other->getNationalPrefixFormattingRule());
- }
- if ($other->hasDomesticCarrierCodeFormattingRule()) {
- $this->setDomesticCarrierCodeFormattingRule($other->getDomesticCarrierCodeFormattingRule());
- }
- if ($other->hasNationalPrefixOptionalWhenFormatting()) {
- $this->setNationalPrefixOptionalWhenFormatting($other->getNationalPrefixOptionalWhenFormatting());
- }
- return $this;
- }
- /**
- * @return array
- */
- public function toArray()
- {
- $output = array();
- $output['pattern'] = $this->getPattern();
- $output['format'] = $this->getFormat();
- $output['leadingDigitsPatterns'] = $this->leadingDigitPatterns();
- if ($this->hasNationalPrefixFormattingRule()) {
- $output['nationalPrefixFormattingRule'] = $this->getNationalPrefixFormattingRule();
- }
- if ($this->hasDomesticCarrierCodeFormattingRule()) {
- $output['domesticCarrierCodeFormattingRule'] = $this->getDomesticCarrierCodeFormattingRule();
- }
- if ($this->hasNationalPrefixOptionalWhenFormatting()) {
- $output['nationalPrefixOptionalWhenFormatting'] = $this->getNationalPrefixOptionalWhenFormatting();
- }
- return $output;
- }
- /**
- * @param array $input
- */
- public function fromArray(array $input)
- {
- $this->setPattern($input['pattern']);
- $this->setFormat($input['format']);
- foreach ($input['leadingDigitsPatterns'] as $leadingDigitsPattern) {
- $this->addLeadingDigitsPattern($leadingDigitsPattern);
- }
- if (isset($input['nationalPrefixFormattingRule']) && $input['nationalPrefixFormattingRule'] !== '') {
- $this->setNationalPrefixFormattingRule($input['nationalPrefixFormattingRule']);
- }
- if (isset($input['domesticCarrierCodeFormattingRule']) && $input['domesticCarrierCodeFormattingRule'] !== '') {
- $this->setDomesticCarrierCodeFormattingRule($input['domesticCarrierCodeFormattingRule']);
- }
- if (isset($input['nationalPrefixOptionalWhenFormatting'])) {
- $this->setNationalPrefixOptionalWhenFormatting($input['nationalPrefixOptionalWhenFormatting']);
- }
- }
- }
|