GoogleAddress.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Geocoder package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. namespace Geocoder\Provider\GoogleMaps\Model;
  11. use Geocoder\Model\Address;
  12. use Geocoder\Model\AdminLevel;
  13. use Geocoder\Model\AdminLevelCollection;
  14. /**
  15. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  16. */
  17. final class GoogleAddress extends Address
  18. {
  19. /**
  20. * @var string|null
  21. */
  22. private $id;
  23. /**
  24. * @var string|null
  25. */
  26. private $locationType;
  27. /**
  28. * @var array
  29. */
  30. private $resultType = [];
  31. /**
  32. * @var string|null
  33. */
  34. private $formattedAddress;
  35. /**
  36. * @var string|null
  37. */
  38. private $streetAddress;
  39. /**
  40. * @var string|null
  41. */
  42. private $intersection;
  43. /**
  44. * @var string|null
  45. */
  46. private $postalCodeSuffix;
  47. /**
  48. * @var string|null
  49. */
  50. private $political;
  51. /**
  52. * @var string|null
  53. */
  54. private $colloquialArea;
  55. /**
  56. * @var string|null
  57. */
  58. private $ward;
  59. /**
  60. * @var string|null
  61. */
  62. private $neighborhood;
  63. /**
  64. * @var string|null
  65. */
  66. private $premise;
  67. /**
  68. * @var string|null
  69. */
  70. private $subpremise;
  71. /**
  72. * @var string|null
  73. */
  74. private $naturalFeature;
  75. /**
  76. * @var string|null
  77. */
  78. private $airport;
  79. /**
  80. * @var string|null
  81. */
  82. private $park;
  83. /**
  84. * @var string|null
  85. */
  86. private $pointOfInterest;
  87. /**
  88. * @var string|null
  89. */
  90. private $establishment;
  91. /**
  92. * @var AdminLevelCollection
  93. */
  94. private $subLocalityLevels;
  95. /**
  96. * @var bool
  97. */
  98. private $partialMatch;
  99. /**
  100. * @param string|null $id
  101. *
  102. * @return GoogleAddress
  103. */
  104. public function withId(string $id = null)
  105. {
  106. $new = clone $this;
  107. $new->id = $id;
  108. return $new;
  109. }
  110. /**
  111. * @see https://developers.google.com/places/place-id
  112. *
  113. * @return string|null
  114. */
  115. public function getId()
  116. {
  117. return $this->id;
  118. }
  119. /**
  120. * @param string|null $locationType
  121. *
  122. * @return GoogleAddress
  123. */
  124. public function withLocationType(string $locationType = null)
  125. {
  126. $new = clone $this;
  127. $new->locationType = $locationType;
  128. return $new;
  129. }
  130. /**
  131. * @return string|null
  132. */
  133. public function getLocationType()
  134. {
  135. return $this->locationType;
  136. }
  137. /**
  138. * @return array
  139. */
  140. public function getResultType(): array
  141. {
  142. return $this->resultType;
  143. }
  144. /**
  145. * @param array $resultType
  146. *
  147. * @return GoogleAddress
  148. */
  149. public function withResultType(array $resultType)
  150. {
  151. $new = clone $this;
  152. $new->resultType = $resultType;
  153. return $new;
  154. }
  155. /**
  156. * @return string|null
  157. */
  158. public function getFormattedAddress()
  159. {
  160. return $this->formattedAddress;
  161. }
  162. /**
  163. * @param string|null $formattedAddress
  164. *
  165. * @return GoogleAddress
  166. */
  167. public function withFormattedAddress(string $formattedAddress = null)
  168. {
  169. $new = clone $this;
  170. $new->formattedAddress = $formattedAddress;
  171. return $new;
  172. }
  173. /**
  174. * @return string|null
  175. */
  176. public function getAirport()
  177. {
  178. return $this->airport;
  179. }
  180. /**
  181. * @param string|null $airport
  182. *
  183. * @return GoogleAddress
  184. */
  185. public function withAirport(string $airport = null)
  186. {
  187. $new = clone $this;
  188. $new->airport = $airport;
  189. return $new;
  190. }
  191. /**
  192. * @return string|null
  193. */
  194. public function getColloquialArea()
  195. {
  196. return $this->colloquialArea;
  197. }
  198. /**
  199. * @param string|null $colloquialArea
  200. *
  201. * @return GoogleAddress
  202. */
  203. public function withColloquialArea(string $colloquialArea = null)
  204. {
  205. $new = clone $this;
  206. $new->colloquialArea = $colloquialArea;
  207. return $new;
  208. }
  209. /**
  210. * @return string|null
  211. */
  212. public function getIntersection()
  213. {
  214. return $this->intersection;
  215. }
  216. /**
  217. * @param string|null $intersection
  218. *
  219. * @return GoogleAddress
  220. */
  221. public function withIntersection(string $intersection = null)
  222. {
  223. $new = clone $this;
  224. $new->intersection = $intersection;
  225. return $new;
  226. }
  227. /**
  228. * @return string|null
  229. */
  230. public function getPostalCodeSuffix()
  231. {
  232. return $this->postalCodeSuffix;
  233. }
  234. /**
  235. * @param string|null $postalCodeSuffix
  236. *
  237. * @return GoogleAddress
  238. */
  239. public function withPostalCodeSuffix(string $postalCodeSuffix = null)
  240. {
  241. $new = clone $this;
  242. $new->postalCodeSuffix = $postalCodeSuffix;
  243. return $new;
  244. }
  245. /**
  246. * @return string|null
  247. */
  248. public function getNaturalFeature()
  249. {
  250. return $this->naturalFeature;
  251. }
  252. /**
  253. * @param string|null $naturalFeature
  254. *
  255. * @return GoogleAddress
  256. */
  257. public function withNaturalFeature(string $naturalFeature = null)
  258. {
  259. $new = clone $this;
  260. $new->naturalFeature = $naturalFeature;
  261. return $new;
  262. }
  263. /**
  264. * @return string|null
  265. */
  266. public function getNeighborhood()
  267. {
  268. return $this->neighborhood;
  269. }
  270. /**
  271. * @param string|null $neighborhood
  272. *
  273. * @return GoogleAddress
  274. */
  275. public function withNeighborhood(string $neighborhood = null)
  276. {
  277. $new = clone $this;
  278. $new->neighborhood = $neighborhood;
  279. return $new;
  280. }
  281. /**
  282. * @return string|null
  283. */
  284. public function getPark()
  285. {
  286. return $this->park;
  287. }
  288. /**
  289. * @param string|null $park
  290. *
  291. * @return GoogleAddress
  292. */
  293. public function withPark(string $park = null)
  294. {
  295. $new = clone $this;
  296. $new->park = $park;
  297. return $new;
  298. }
  299. /**
  300. * @return string|null
  301. */
  302. public function getPointOfInterest()
  303. {
  304. return $this->pointOfInterest;
  305. }
  306. /**
  307. * @param string|null $pointOfInterest
  308. *
  309. * @return GoogleAddress
  310. */
  311. public function withPointOfInterest(string $pointOfInterest = null)
  312. {
  313. $new = clone $this;
  314. $new->pointOfInterest = $pointOfInterest;
  315. return $new;
  316. }
  317. /**
  318. * @return string|null
  319. */
  320. public function getPolitical()
  321. {
  322. return $this->political;
  323. }
  324. /**
  325. * @param string|null $political
  326. *
  327. * @return GoogleAddress
  328. */
  329. public function withPolitical(string $political = null)
  330. {
  331. $new = clone $this;
  332. $new->political = $political;
  333. return $new;
  334. }
  335. /**
  336. * @return string|null
  337. */
  338. public function getPremise()
  339. {
  340. return $this->premise;
  341. }
  342. /**
  343. * @param string $premise
  344. *
  345. * @return GoogleAddress
  346. */
  347. public function withPremise(string $premise = null)
  348. {
  349. $new = clone $this;
  350. $new->premise = $premise;
  351. return $new;
  352. }
  353. /**
  354. * @return string|null
  355. */
  356. public function getStreetAddress()
  357. {
  358. return $this->streetAddress;
  359. }
  360. /**
  361. * @param string|null $streetAddress
  362. *
  363. * @return GoogleAddress
  364. */
  365. public function withStreetAddress(string $streetAddress = null)
  366. {
  367. $new = clone $this;
  368. $new->streetAddress = $streetAddress;
  369. return $new;
  370. }
  371. /**
  372. * @return string|null
  373. */
  374. public function getSubpremise()
  375. {
  376. return $this->subpremise;
  377. }
  378. /**
  379. * @param string|null $subpremise
  380. *
  381. * @return GoogleAddress
  382. */
  383. public function withSubpremise(string $subpremise = null)
  384. {
  385. $new = clone $this;
  386. $new->subpremise = $subpremise;
  387. return $new;
  388. }
  389. /**
  390. * @return string|null
  391. */
  392. public function getWard()
  393. {
  394. return $this->ward;
  395. }
  396. /**
  397. * @param string|null $ward
  398. *
  399. * @return GoogleAddress
  400. */
  401. public function withWard(string $ward = null)
  402. {
  403. $new = clone $this;
  404. $new->ward = $ward;
  405. return $new;
  406. }
  407. /**
  408. * @return string|null
  409. */
  410. public function getEstablishment()
  411. {
  412. return $this->establishment;
  413. }
  414. /**
  415. * @param string|null $establishment
  416. *
  417. * @return GoogleAddress
  418. */
  419. public function withEstablishment(string $establishment = null)
  420. {
  421. $new = clone $this;
  422. $new->establishment = $establishment;
  423. return $new;
  424. }
  425. /**
  426. * @return AdminLevelCollection
  427. */
  428. public function getSubLocalityLevels()
  429. {
  430. return $this->subLocalityLevels;
  431. }
  432. /**
  433. * @param array $subLocalityLevel
  434. *
  435. * @return $this
  436. */
  437. public function withSubLocalityLevels(array $subLocalityLevel)
  438. {
  439. $subLocalityLevels = [];
  440. foreach ($subLocalityLevel as $level) {
  441. if (empty($level['level'])) {
  442. continue;
  443. }
  444. $name = $level['name'] ?? $level['code'] ?? '';
  445. if (empty($name)) {
  446. continue;
  447. }
  448. $subLocalityLevels[] = new AdminLevel($level['level'], $name, $level['code'] ?? null);
  449. }
  450. $subLocalityLevels = array_unique($subLocalityLevels);
  451. $new = clone $this;
  452. $new->subLocalityLevels = new AdminLevelCollection($subLocalityLevels);
  453. return $new;
  454. }
  455. /**
  456. * @return bool
  457. */
  458. public function isPartialMatch()
  459. {
  460. return $this->partialMatch;
  461. }
  462. /**
  463. * @param bool $partialMatch
  464. *
  465. * @return $this
  466. */
  467. public function withPartialMatch(bool $partialMatch)
  468. {
  469. $new = clone $this;
  470. $new->partialMatch = $partialMatch;
  471. return $new;
  472. }
  473. }