Format an address

@param AddressInterface $address
@param null $locale
@param bool $html
@param string $htmlTag
@param array $htmlAttributes
@return string
498918
public function format(
        AddressInterface $address,
        $locale = null,
        $html = true,
        $htmlTag = "p",
        $htmlAttributes = []
    ) {
        $locale = $this->normalizeLocale($locale);

        $addressFormatRepository = new AddressFormatRepository();
        $countryRepository = new CountryRepository();
        $subdivisionRepository = new SubdivisionRepository();

        $formatter = new DefaultFormatter(
            $addressFormatRepository,
            $countryRepository,
            $subdivisionRepository,
            $locale
        );

        $formatter->setOption('html', $html);
        $formatter->setOption('html_tag', $htmlTag);
        $formatter->setOption('html_attributes', $htmlAttributes);


        $addressFormatted = $formatter->format($address);

        return $addressFormatted;
    }
410710
private function executeQuery(string $url, string $locale = null): AddressCollection
    {
        if (null !== $locale) {
            $url = sprintf('%s&language=%s', $url, $locale);
        }

        $content = $this->getUrlContents($url);
        $json = json_decode($content, true);

        // https://geocoder.opencagedata.com/api#codes
        if (isset($json['status'])) {
            switch ($json['status']['code']) {
                case 400:
                    throw new InvalidArgument('Invalid request (a required parameter is missing).');
                case 402:
                    throw new QuotaExceeded('Valid request but quota exceeded.');
                case 403:
                    throw new InvalidCredentials('Invalid or missing api key.');
            }
        }

        if (!isset($json['total_results']) || 0 == $json['total_results']) {
            return new AddressCollection([]);
        }

        $locations = $json['results'];

        if (empty($locations)) {
            return new AddressCollection([]);
        }

        $results = [];
        foreach ($locations as $location) {
            $builder = new AddressBuilder($this->getName());
            $this->parseCoordinates($builder, $location);

            $components = $location['components'];
            $annotations = $location['annotations'];

            $this->parseAdminsLevels($builder, $components);
            $this->parseCountry($builder, $components);
            $builder->setLocality($this->guessLocality($components));
            $builder->setSubLocality($this->guessSubLocality($components));
            $builder->setStreetNumber(isset($components['house_number']) ? $components['house_number'] : null);
            $builder->setStreetName($this->guessStreetName($components));
            $builder->setPostalCode(isset($components['postcode']) ? $components['postcode'] : null);
            $builder->setTimezone(isset($annotations['timezone']['name']) ? $annotations['timezone']['name'] : null);

            /** @var OpenCageAddress $address */
            $address = $builder->build(OpenCageAddress::class);
            $address = $address->withMGRS(isset($annotations['MGRS']) ? $annotations['MGRS'] : null);
            $address = $address->withMaidenhead(isset($annotations['Maidenhead']) ? $annotations['Maidenhead'] : null);
            $address = $address->withGeohash(isset($annotations['geohash']) ? $annotations['geohash'] : null);
            $address = $address->withWhat3words(isset($annotations['what3words'], $annotations['what3words']['words']) ? $annotations['what3words']['words'] : null);
            $address = $address->withFormattedAddress($location['formatted']);

            $results[] = $address;
        }

        return new AddressCollection($results);
    }
980824
public function setSendAsAlias($domain, $user, $name, $address, $replyTo = null, $makeDefault = false)
    {
        $url = self::BASE_URL . "{$domain}/{$user}/sendas";
        $request = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">
    <apps:property name="name" value="{$name}" />
    <apps:property name="address" value="{$address}" />
XML;
        if ($replyTo !== null) {
            $request .= "<apps:property name=\"replyTo\" value=\"{$replyTo}\" />";
        }
        if ($makeDefault) {
            $request .= "<apps:property name=\"makeDefault\" value=\"true\" />";
        }
        $request .= "</atom:entry>";
        $request = new \Google_Http_Request($url, 'POST', array('Content-Type' => 'application/atom+xml'),
           $request);

        $httpRequest = $this->helper->getClient()
           ->getAuth()
           ->authenticatedRequest($request);

        return ($httpRequest->getResponseHttpCode() == 201);
    }
918155
private function _generatorAddressCode($address)
    {
        $addressCode = array_search($address, $this->_addressCodeList);
        $classification = $this->_addressCodeClassification($addressCode);
        switch ($classification) {
            case 'country':
                $pattern = '/\d{4}(?!00)[0-9]{2}$/';
                $addressCode = $this->_getRandAddressCode($pattern);
                break;
            case 'province':
                $provinceCode = substr($addressCode, 0, 2);
                $pattern = '/^'.$provinceCode.'\d{2}(?!00)[0-9]{2}$/';
                $addressCode = $this->_getRandAddressCode($pattern);
                break;
            case 'city':
                $cityCode = substr($addressCode, 0, 4);
                $pattern = '/^'.$cityCode.'(?!00)[0-9]{2}$/';
                $addressCode = $this->_getRandAddressCode($pattern);
                break;
        }

        return $addressCode;
    }
89648
public static String formatAddress(int address) {
		int b1 = (address >>> 24) & 0xff;
		int b2 = (address >>> 16) & 0xff;
		int b3 = (address >>>  8) & 0xff;
		int b4 =  address         & 0xff;

		return "" + b1 + '.' + b2 + '.' + b3 + '.' + b4;
	}
262058
protected function getValues(AddressInterface $address, AddressFormat $addressFormat)
    {
        $values = [];
        foreach (AddressField::getAll() as $field) {
            $getter = 'get' . ucfirst($field);
            $values[$field] = $address->$getter();
        }

        // Replace the subdivision values with the names of any predefined ones.
        $originalValues = [];
        $subdivisionFields = $addressFormat->getUsedSubdivisionFields();
        $parents = [];
        foreach ($subdivisionFields as $index => $field) {
            if (empty($values[$field])) {
                // This level is empty, so there can be no sublevels.
                break;
            }
            $parents[] = $index ? $originalValues[$subdivisionFields[$index - 1]] : $address->getCountryCode();
            $subdivision = $this->subdivisionRepository->get($values[$field], $parents);
            if (!$subdivision) {
                break;
            }

            // Remember the original value so that it can be used for $parents.
            $originalValues[$field] = $values[$field];
            // Replace the value with the expected code.
            $useLocalName = Locale::matchCandidates($address->getLocale(), $subdivision->getLocale());
            $values[$field] = $useLocalName ? $subdivision->getLocalCode() : $subdivision->getCode();
            if (!$subdivision->hasChildren()) {
                // The current subdivision has no children, stop.
                break;
            }
        }

        return $values;
    }
191970
protected function _execute($address) {
		$this->_Geocoder = new Geocoder();
		try {
			$addresses = $this->_Geocoder->geocode($address);
		} catch (InconclusiveException $e) {
			return null;
		} catch (NotAccurateEnoughException $e) {
			return null;
		}

		if (!$addresses || $addresses->count() < 1) {
			return null;
		}
		$address = $addresses->first();
		return $address;
	}
877639
public function formatBillingAddress(ClientBillingAddress $address, $lineSeparator = self::LINES_SEPARATOR)
    {
        $lines   = [];
        $lines[] = sprintf('%s %s', $address->getFirstName(), $address->getLastName());
        if ('' !== $address->getCompanyName()) {
            $lines[] = $address->getCompanyName();
        }
        $lines[] = $address->getLine1();
        $lines[] = $address->getLine2();
        $lines[] = sprintf('%s, %s %s', $address->getCountry(), $address->getPostalCode(), $address->getCity());
        
        return implode($lineSeparator, $lines);
    }
164034
public function toArray(AddressInterface $address)
    {
        $cityLocationId = $address->getCity();
        $cityHierarchy = $this
            ->locationProvider
            ->getHierarchy($cityLocationId);
        $cityHierarchyAsc = array_reverse($cityHierarchy);

        $addressArray = [
            'id' => $address->getId(),
            'name' => $address->getName(),
            'recipientName' => $address->getRecipientName(),
            'recipientSurname' => $address->getRecipientSurname(),
            'address' => $address->getAddress(),
            'addressMore' => $address->getAddressMore(),
            'postalCode' => $address->getPostalcode(),
            'phone' => $address->getPhone(),
            'mobile' => $address->getMobile(),
            'comment' => $address->getComments(),
        ];

        foreach ($cityHierarchyAsc as $cityLocationNode) {
            /**
             * @var LocationData $cityLocationNode
             */
            $addressArray['city'][$cityLocationNode->getType()]
                = $cityLocationNode->getName();
        }

        $addressArray['fullAddress'] =
            $this->buildFullAddressString(
                $address,
                $addressArray['city']
            );

        return $addressArray;
    }
1145565
public function match(AddressInterface $address)
    {
        if ($address->getCountryCode() != $this->countryCode) {
            return false;
        }
        if ($this->administrativeArea && $this->administrativeArea != $address->getAdministrativeArea()) {
            return false;
        }
        if ($this->locality && $this->locality != $address->getLocality()) {
            return false;
        }
        if ($this->dependentLocality && $this->dependentLocality != $address->getDependentLocality()) {
            return false;
        }
        if (!PostalCodeHelper::match($address->getPostalCode(), $this->includedPostalCodes, $this->excludedPostalCodes)) {
            return false;
        }

        return true;
    }
675727
public function cleanCartAddress($address) {
    $address = (array) $address;

    $address = $this->cleanAddress($address);

    if (isset($address['customer_address_id'])) {
      $address['customer_address_id'] = (int) $address['customer_address_id'];
    }

    // Never send address_id in API request, it confuses Magento.
    if (isset($address['address_id'])) {
      unset($address['address_id']);
    }

    return $address;
  }
128709
public function postalLabelFormat(AddressInterface $address, $locale = null, $originCountry = null, $options = [])
    {
        $locale = $this->normalizeLocale($locale);

        $addressFormatRepository = new AddressFormatRepository();
        $countryRepository = new CountryRepository();
        $subdivisionRepository = new SubdivisionRepository();

        if (null === $originCountry) {
            $countryId = Country::getShopLocation();
            if (null === $country = CountryQuery::create()->findPk($countryId)) {
                $country = Country::getDefaultCountry();
            }

            $originCountry = $country->getIsoalpha2();
        }

        $formatter = new PostalLabelFormatter(
            $addressFormatRepository,
            $countryRepository,
            $subdivisionRepository,
            $originCountry,
            $locale,
            $options
        );

        $addressFormatted = $formatter->format($address);

        return $addressFormatted;
    }
410905
private function normalizeAddress($address) {
    if (isset($address->extension)) {
      if (!is_object($address->extension)) {
        $anObject = (object) $address->extension;
        $address->extension = $anObject;
      }
    }
    return $address;
  }
435133
public function saveAddress(AddressInterface $address)
    {
        if ($address->getId()) {
            $addressToSave = clone $address;
            $addressToSave->setId(null);

            $this->addressObjectManager->refresh($address);
            $this->addressObjectManager->persist($addressToSave);
            $this->addressObjectManager->flush($addressToSave);

            $this->addressEventDispatcher->dispatchAddressOnCloneEvent(
                $address,
                $addressToSave
            );

            return $addressToSave;
        }

        $this
            ->addressObjectManager
            ->flush($address);

        return $address;
    }
1331358
function formatAddress(address) {
  const result = address
  if (result) {
    result.formatted =
      `${result.street_address}\n${result.postal_code} ${result.locality}\n${result.country}`
    return result
  }
  return null
}
1229459
public function email($address, $text=null, $title=null, $class=null) {
		if (is_null($text)) {
			$text = $address;
		}
		$attributes = $this->getHtmlAttributes(array(
			'title'=>$title,
			'class'=>$class
		));
		return "<a href='mailto:$address'$attributes>$text</a>";
	}
657219
public function geolocateIPAddress(AddressInterface $address)
    {
        $result = new GeolocationResult();
        try {
            switch ($address->getRangeType()) {
                case IPRangeType::T_PUBLIC:
                    $addressString = (string) $address;
                    $session = $this->app->make('session');
                    $sessionKey = 'ccm/geolocation/' . $this->geolocator->getGeolocatorHandle() . '/' . $this->geolocator->getGeolocatorID() . '/' . md5(serialize($this->geolocator->getGeolocatorConfiguration())) . '/' . $addressString;
                    if ($session->has($sessionKey)) {
                        $result = $session->get($sessionKey);
                    } else {
                        $result = $this->performGeolocation($address);
                        $session->set($sessionKey, $result);
                    }
                    break;
                default:
                    $result->setError(GeolocationResult::ERR_IPNOTPUBLIC);
                    break;
            }
        } catch (Exception $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', $x);
        } catch (Throwable $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', new Exception($x->getMessage(), $x->getCode()));
        }

        return $result;
    }