PhoneNumberDesc.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. namespace libphonenumber;
  3. /**
  4. * Phone Number Description
  5. */
  6. class PhoneNumberDesc
  7. {
  8. protected $hasNationalNumberPattern = false;
  9. protected $nationalNumberPattern = '';
  10. protected $hasExampleNumber = false;
  11. protected $exampleNumber = '';
  12. /**
  13. * @var array
  14. */
  15. protected $possibleLength;
  16. /**
  17. * @var array
  18. */
  19. protected $possibleLengthLocalOnly;
  20. public function __construct()
  21. {
  22. $this->clear();
  23. }
  24. /**
  25. * @return PhoneNumberDesc
  26. */
  27. public function clear()
  28. {
  29. $this->clearNationalNumberPattern();
  30. $this->clearPossibleLength();
  31. $this->clearPossibleLengthLocalOnly();
  32. $this->clearExampleNumber();
  33. return $this;
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function getPossibleLength()
  39. {
  40. return $this->possibleLength;
  41. }
  42. /**
  43. * @param array $possibleLength
  44. */
  45. public function setPossibleLength($possibleLength)
  46. {
  47. $this->possibleLength = $possibleLength;
  48. }
  49. public function addPossibleLength($possibleLength)
  50. {
  51. if (!in_array($possibleLength, $this->possibleLength)) {
  52. $this->possibleLength[] = $possibleLength;
  53. }
  54. }
  55. public function clearPossibleLength()
  56. {
  57. $this->possibleLength = array();
  58. }
  59. /**
  60. * @return array
  61. */
  62. public function getPossibleLengthLocalOnly()
  63. {
  64. return $this->possibleLengthLocalOnly;
  65. }
  66. /**
  67. * @param array $possibleLengthLocalOnly
  68. */
  69. public function setPossibleLengthLocalOnly($possibleLengthLocalOnly)
  70. {
  71. $this->possibleLengthLocalOnly = $possibleLengthLocalOnly;
  72. }
  73. public function addPossibleLengthLocalOnly($possibleLengthLocalOnly)
  74. {
  75. if (!in_array($possibleLengthLocalOnly, $this->possibleLengthLocalOnly)) {
  76. $this->possibleLengthLocalOnly[] = $possibleLengthLocalOnly;
  77. }
  78. }
  79. public function clearPossibleLengthLocalOnly()
  80. {
  81. $this->possibleLengthLocalOnly = array();
  82. }
  83. /**
  84. * @return boolean
  85. */
  86. public function hasNationalNumberPattern()
  87. {
  88. return $this->hasNationalNumberPattern;
  89. }
  90. /**
  91. * @return string
  92. */
  93. public function getNationalNumberPattern()
  94. {
  95. return $this->nationalNumberPattern;
  96. }
  97. /**
  98. * @param string $value
  99. * @return PhoneNumberDesc
  100. */
  101. public function setNationalNumberPattern($value)
  102. {
  103. $this->hasNationalNumberPattern = true;
  104. $this->nationalNumberPattern = $value;
  105. return $this;
  106. }
  107. /**
  108. * @return PhoneNumberDesc
  109. */
  110. public function clearNationalNumberPattern()
  111. {
  112. $this->hasNationalNumberPattern = false;
  113. $this->nationalNumberPattern = '';
  114. return $this;
  115. }
  116. /**
  117. * @return string
  118. */
  119. public function hasExampleNumber()
  120. {
  121. return $this->hasExampleNumber;
  122. }
  123. /**
  124. * @return string
  125. */
  126. public function getExampleNumber()
  127. {
  128. return $this->exampleNumber;
  129. }
  130. /**
  131. * @param string $value
  132. * @return PhoneNumberDesc
  133. */
  134. public function setExampleNumber($value)
  135. {
  136. $this->hasExampleNumber = true;
  137. $this->exampleNumber = $value;
  138. return $this;
  139. }
  140. /**
  141. * @return PhoneNumberDesc
  142. */
  143. public function clearExampleNumber()
  144. {
  145. $this->hasExampleNumber = false;
  146. $this->exampleNumber = '';
  147. return $this;
  148. }
  149. /**
  150. * @param PhoneNumberDesc $other
  151. * @return PhoneNumberDesc
  152. */
  153. public function mergeFrom(PhoneNumberDesc $other)
  154. {
  155. if ($other->hasNationalNumberPattern()) {
  156. $this->setNationalNumberPattern($other->getNationalNumberPattern());
  157. }
  158. if ($other->hasExampleNumber()) {
  159. $this->setExampleNumber($other->getExampleNumber());
  160. }
  161. $this->setPossibleLength($other->getPossibleLength());
  162. $this->setPossibleLengthLocalOnly($other->getPossibleLengthLocalOnly());
  163. return $this;
  164. }
  165. /**
  166. * @param PhoneNumberDesc $other
  167. * @return boolean
  168. */
  169. public function exactlySameAs(PhoneNumberDesc $other)
  170. {
  171. return $this->nationalNumberPattern === $other->nationalNumberPattern &&
  172. $this->exampleNumber === $other->exampleNumber;
  173. }
  174. /**
  175. * @return array
  176. */
  177. public function toArray()
  178. {
  179. $data = array();
  180. if ($this->hasNationalNumberPattern()) {
  181. $data['NationalNumberPattern'] = $this->getNationalNumberPattern();
  182. }
  183. if ($this->hasExampleNumber()) {
  184. $data['ExampleNumber'] = $this->getExampleNumber();
  185. }
  186. $data['PossibleLength'] = $this->getPossibleLength();
  187. $data['PossibleLengthLocalOnly'] = $this->getPossibleLengthLocalOnly();
  188. return $data;
  189. }
  190. /**
  191. * @param array $input
  192. * @return PhoneNumberDesc
  193. */
  194. public function fromArray(array $input)
  195. {
  196. if (isset($input['NationalNumberPattern']) && $input['NationalNumberPattern'] != '') {
  197. $this->setNationalNumberPattern($input['NationalNumberPattern']);
  198. }
  199. if (isset($input['ExampleNumber']) && $input['NationalNumberPattern'] != '') {
  200. $this->setExampleNumber($input['ExampleNumber']);
  201. }
  202. $this->setPossibleLength($input['PossibleLength']);
  203. $this->setPossibleLengthLocalOnly($input['PossibleLengthLocalOnly']);
  204. return $this;
  205. }
  206. }