Retrieves the full address for a given postcode.

@param $postcode
@return array
434632
public function lookup($postcode)
    {
        // Mutate the postcode
        $postcode = $this->mutatePostcode($postcode);

        // Sanitize the postcode:
        $coords = $this->getCoordinates($postcode);

        // If empty, we must have no results
        if (empty($coords)) {
            return [];
        }

        // A second call will now retrieve the address
        $address_url  = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $coords['latitude'] . ',' . $coords['longitude'] . '&sensor=false';

        $address_json = $this->api->fetch($address_url);

        // The correct result is not always the first one, so loop through results here
        foreach ($address_json->results as $current_address) {
            foreach ($current_address->address_components as $component) {
                // If this address_component is a postcode and matches...
                if(array_search('postal_code', $component->types) !== FALSE
                    && $postcode == $this->mutatePostcode($component->long_name)
                ) {
                    $address_data = $current_address->address_components;
                    break 2;
                }
            }
        }

        // If no exact match found, use the first as a closest option
        if (!isset($address_data)
            && !empty($address_json->results)
        ) {
            $address_data = $address_json->results[0]->address_components;
        }

        // If still nothing, return empty array
        if (!isset($address_data)) {
            return [];
        }

        // Initialize all values as empty
        $street_number = '';
        $street        = '';
        $sublocality   = '';
        $town          = '';
        $county        = '';
        $country       = '';

        // Process the return
        foreach ($address_data as $value) {
            if (array_search('street_number', $value->types) !== FALSE) {
                $street_number = $value->long_name;
            } elseif (array_search('route', $value->types) !== FALSE) {
                $street = $value->long_name;
            } elseif (array_search('sublocality', $value->types) !== FALSE) {
                $sublocality = $value->long_name;
            } elseif (array_search('locality', $value->types) !== FALSE) {
                $town = $value->long_name;
            } elseif (array_search('administrative_area_level_2', $value->types) !== FALSE) {
                $county = $value->long_name;
            } elseif (array_search('country', $value->types) !== FALSE) {
                $country = $value->long_name;
            }
        }

        return [
            'postcode'      => $postcode,
            'street_number' => $street_number,
            'street'        => $street,
            'sublocality'   => $sublocality,
            'town'          => $town,
            'county'        => $county,
            'country'       => $country,
            'latitude'      => $coords['latitude'],
            'longitude'     => $coords['longitude']
        ];
    }
407284
protected function getCode($code)
    {
        if (is_array($code)) {
            return $this->getCodeArray($code);
        }

        return $this->get($code);
    }
301642
public function geocode( $postal_code ) {
    // Setup local variable for holding results from geocoder.
    $addressCollection = null;

    // Try to call the geocoder.
    try {
      // Set it call to geocoder...
      $curl     = new \Ivory\HttpAdapter\CurlHttpAdapter();
      $geocoder = new \Geocoder\Provider\GoogleMaps( $curl, null, null, true );

      // Geocode the zipcode...
      $addressCollection = $geocoder->geocode( $postal_code );
    } catch ( \Exception $exception ) {
      // Recover from exception by rethrowing wrapped in GeocodingException.
      throw new GeocodingException( 'An exception occurred during geocoding.', 0, $exception );
    }

    // Make sure geocode found at least one result.
    if ( ! $addressCollection->has( 0 ) ) {
      throw new GeocodingException( 'ZIP code geocode did not return any results: ' . $postal_code );
    }

    // Store first result in local variable.
    $address = $addressCollection->get( 0 );

    // Return result.
    return new LatLon( $address->getLatitude(), $address->getLongitude() );
  }
199871
public function getPostalCode() : ?string 
    {
        if ( ! $this->hasPostalCode()) {
            $this->setPostalCode($this->getDefaultPostalCode());
        }
        return $this->postalCode;
    }
1222763
public function getFulltextAddress($separator = "\n")
    {
        $elems = [];
        if ($this->address) {
            $elems[] = $this->address;
        }
        $zip_city = [];
        if ($this->zip) {
            $zip_city[] = $this->zip;
        }
        if ($this->city) {
            $zip_city[] = $this->city;
        }

        if ($zip_city) {
            $elems[] = implode(' ', $zip_city);
        }
        if ($this->country) {
            $elems[] = $this->country;
        }

        return implode($separator, $elems);
    }
205225
public function getCurrenciesForCountry(string $countryCode) : array
    {
        if ($this->countryToCurrency === null) {
            $this->countryToCurrency = require __DIR__ . '/../data/country-to-currency.php';
        }

        $result = [];

        if (isset($this->countryToCurrency[$countryCode])) {
            foreach ($this->countryToCurrency[$countryCode] as $currencyCode) {
                $result[] = $this->getCurrency($currencyCode);
            }
        }

        return $result;
    }
1369198
public function getBillingAddress()
    {
        $address = ($this->Address1) ? $this->Address1 . ",\n" : '';
        $address .= ($this->Address2) ? $this->Address2 . ",\n" : '';
        $address .= ($this->City) ? $this->City . ",\n" : '';
        $address .= ($this->PostCode) ? $this->PostCode . ",\n" : '';
        $address .= ($this->Country) ? $this->Country : '';

        return $address;
    }
361029
private function getAddressFields($_params = array())
    {
        $params = array_merge(
            array(
                'includeHeader' => true,
            ),
            (array) $_params
        );

        $fields = array(
            TextField::create('Address', _t('Addressable.ADDRESS', 'Address')),
            TextField::create('Suburb', _t('Addressable.SUBURB', 'Suburb'))
        );

        if ($params['includeHeader']) {
            array_unshift(
                $fields,
                HeaderField::create('AddressHeader', _t('Addressable.ADDRESSHEADER', 'Address'))
            );
        }


        // Get state field
        $label = _t('Addressable.STATE', 'State');
        $allowedStates = $this->owner->getAllowedStates();
        if (count($allowedStates) >= 1) {
            // If allowed states are restricted, only allow those
            $fields[] = DropdownField::create('State', $label, $allowedStates);
        } elseif (!$allowedStates) {
            // If no allowed states defined, allow the user to type anything
            $fields[] = TextField::create('State', $label);
        }

        // Get postcode field
        $postcode = RegexTextField::create('Postcode', _t('Addressable.POSTCODE', 'Postcode'));
        $postcode->setRegex($this->getPostcodeRegex());
        $fields[] = $postcode;

        // Get country field
        $fields[] = DropdownField::create(
            'Country',
            _t('Addressable.COUNTRY', 'Country'),
            $this->owner->getAllowedCountries()
        );

        $this->owner->extend("updateAddressFields", $fields);

        return $fields;
    }
276666
public function format(Address $address)
    {
        $fields = [
            'p-street-address' => $address->getStreet(),
            'p-extended-address' => $address->getExtended(),
            'p-post-office-box' => $address->getPobox(),
            'p-locality' => $address->getLocality(),
            'p-region' => $address->getRegion(),
            'p-postal-code' => $address->getPostal(),
            'p-country' => $address->getCountry()
        ];
        $tags = [];
        foreach ($fields as $k => $v) {
            if (strlen($v) > 0) {
                $tags[] = '<span class="' . $k . '">' . htmlspecialchars($v) . '</span>';
            }
        }
        $geo = $address->getGeo();
        if ($geo !== null) {
            $tags[] = '<span class="p-geo">' . $this->geoFormatter->format($geo) . '</span>';
        }
        return '<span class="h-adr">' . implode(' ', $tags) . '</span>';
    }
28119
public function getFullAddress(): string
    {
        $address = \sprintf('%s@%s', $this->mailbox, $this->hostname);
        if (null !== $this->name) {
            $address = \sprintf('"%s" <%s>', \addcslashes($this->name, '"'), $address);
        }

        return $address;
    }
585934
private function _google ($parts)
	{
		if (!$this->_isAssoc($parts))
		{
			$parts = array_reduce(
				$parts,
				function ($a, $part) {
					$key     = $part['types'][0];
					$a[$key] = $part['long_name'];

					return $a;
				},
				[]
			);
		}

		foreach (PartsLegacy::$legacyKeys as $key)
			if (!array_key_exists($key, $parts))
				$parts[$key] = '';

		$this->number = $this->_join([
			$parts['subpremise'],
			$parts['premise'],
			$parts['street_number'],
		]);

		$this->address = $this->_join([
			$parts['route'],
			$parts['neighborhood'],
			$parts['sublocality_level_5'],
			$parts['sublocality_level_4'],
			$parts['sublocality_level_3'],
			$parts['sublocality_level_2'],
			$parts['sublocality_level_1'],
			$parts['sublocality'],
		]);

		$this->city = $this->_join([
			$parts['postal_town'],
			$parts['locality'],
		]);

		$this->postcode = $parts['postal_code'] ?? $parts['postal_code_prefix'];
		$this->county = $parts['administrative_area_level_2'];
		$this->state = $parts['administrative_area_level_1'];
		$this->country = $parts['country'];
	}
567399
public function get($codes = null){
		if(is_array($codes)){
			$return = Array();
			foreach($codes as $code){
				$return[$code] = $this->get($code);
			}
			return $return;
		}elseif(is_string($codes)){
			return $this->shortcodes[$codes];
		}else{
			return $this->shortcodes;
		}
	}
630635
public function getCoordinates($address)
    {
        if (! empty($this->country)) {
            $address = trim($address) . ' ' . $this->country;
        }

        // Sanitize the address:
        $search_code = urlencode($address);

        // Retrieve the latitude and longitude
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $search_code . '&sensor=false';

        // If Google Maps API fails, catch it and throw a better error
        $json = $this->api->fetch($url);

        if(!empty($json->results)) {
            $lat = $json->results[0]->geometry->location->lat;
            $lng = $json->results[0]->geometry->location->lng;

            return [
                'latitude'  => $lat,
                'longitude' => $lng
            ];
        }

        // We must have nothing if we've got here
        return [];
    }
65489
public function getCitiesToPostalCode($postalCode) {
		preg_match("/\d+/", $postalCode, $matches);
		if (!isset($matches[0]) || strlen($matches[0]) !== 5) {
			return null;
		}
		return $this->find('all', ['conditions' => ['Cities.postal_code LIKE' => $matches[0]]]);
	}
648632
public function fetchAddress($zipCode, $houseNumber)
    {
        if (0 === preg_match('/^[1-9]{1}[0-9]{3}[\s]{0,1}[a-z]{2}$/i', $zipCode)) {
            throw new InvalidPostcodeException('Given postcode incorrect');
        }

        $uri = sprintf("http://json.api-postcode.nl?postcode=%s&number=%s", $zipCode, $houseNumber);
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $uri);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, [sprintf('Token: %s', $this->token)]);

        $serverOutput = curl_exec($curl);
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($httpCode !== 200) {
            throw new InvalidResponseException('Response does not return a valid response code');
        }

        curl_close($curl);

        $responseData = json_decode($serverOutput, true);

        $address = new Address(
            $responseData['street'],
            $responseData['postcode'],
            $responseData['house_number'],
            $responseData['city']
        );

        $address->setLatitude($responseData['latitude']);
        $address->setLongitude($responseData['longitude']);

        return $address;
    }
1328284
public function postcodeLookupBulk($postcodes)
    {
        $headers = ['Content-Type' => 'application/json'];
        $body = ['postcodes' => $postcodes];

        $request = new Request('POST', '/postcodes', $headers, json_encode($body));

        return $this->httpTransport($request);
    }
1007543
public function getAddresses($type = ShopgateAddress::BOTH)
    {
        if (empty($this->addresses)) {
            return array();
        }

        $addresses = array();

        foreach ($this->addresses as $address) {
            if (($address->getAddressType() & $type) == $address->getAddressType()) {
                $addresses[] = $address;
            }
        }

        return $addresses;
    }