public function format(Location $location, string $format): string
    {
        $countryName = null;
        $code = null;
        if (null !== $country = $location->getCountry()) {
            $countryName = $country->getName();
            if (null !== $code = $country->getCode()) {
                $code = strtoupper($code);
            }
        }

        $replace = [
            self::STREET_NUMBER => $location->getStreetNumber(),
            self::STREET_NAME => $location->getStreetName(),
            self::LOCALITY => $location->getLocality(),
            self::POSTAL_CODE => $location->getPostalCode(),
            self::SUB_LOCALITY => $location->getSubLocality(),
            self::COUNTRY => $countryName,
            self::COUNTRY_CODE => $code,
            self::TIMEZONE => $location->getTimezone(),
        ];

        for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++$level) {
            $replace[self::ADMIN_LEVEL.$level] = null;
            $replace[self::ADMIN_LEVEL_CODE.$level] = null;
        }

        foreach ($location->getAdminLevels() as $level => $adminLevel) {
            $replace[self::ADMIN_LEVEL.$level] = $adminLevel->getName();
            $replace[self::ADMIN_LEVEL_CODE.$level] = $adminLevel->getCode();
        }

        return strtr($format, $replace);
    }
public function format(Location $location, string $format): string
    {
        $countryName = null;
        $code = null;
        if (null !== $country = $location->getCountry()) {
            $countryName = $country->getName();
            if (null !== $code = $country->getCode()) {
                $code = strtoupper($code);
            }
        }

        $replace = [
            self::STREET_NUMBER => $location->getStreetNumber(),
            self::STREET_NAME => $location->getStreetName(),
            self::LOCALITY => $location->getLocality(),
            self::POSTAL_CODE => $location->getPostalCode(),
            self::SUB_LOCALITY => $location->getSubLocality(),
            self::COUNTRY => $countryName,
            self::COUNTRY_CODE => $code,
            self::TIMEZONE => $location->getTimezone(),
        ];

        for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++$level) {
            $replace[self::ADMIN_LEVEL.$level] = null;
            $replace[self::ADMIN_LEVEL_CODE.$level] = null;
        }

        foreach ($location->getAdminLevels() as $level => $adminLevel) {
            $replace[self::ADMIN_LEVEL.$level] = $adminLevel->getName();
            $replace[self::ADMIN_LEVEL_CODE.$level] = $adminLevel->getCode();
        }

        return strtr($format, $replace);
    }
public function format ( Location $ location , string $ format ) : string { $ countryName = null ; $ code = null ; if ( null !== $ country = $ location -> getCountry ( ) ) { $ countryName = $ country -> getName ( ) ; if ( null !== $ code = $ country -> getCode ( ) ) { $ code = strtoupper ( $ code ) ; } } $ replace = [ self :: STREET_NUMBER => $ location -> getStreetNumber ( ) , self :: STREET_NAME => $ location -> getStreetName ( ) , self :: LOCALITY => $ location -> getLocality ( ) , self :: POSTAL_CODE => $ location -> getPostalCode ( ) , self :: SUB_LOCALITY => $ location -> getSubLocality ( ) , self :: COUNTRY => $ countryName , self :: COUNTRY_CODE => $ code , self :: TIMEZONE => $ location -> getTimezone ( ) , ] ; for ( $ level = 1 ; $ level <= AdminLevelCollection :: MAX_LEVEL_DEPTH ; ++ $ level ) { $ replace [ self :: ADMIN_LEVEL . $ level ] = null ; $ replace [ self :: ADMIN_LEVEL_CODE . $ level ] = null ; } foreach ( $ location -> getAdminLevels ( ) as $ level => $ adminLevel ) { $ replace [ self :: ADMIN_LEVEL . $ level ] = $ adminLevel -> getName ( ) ; $ replace [ self :: ADMIN_LEVEL_CODE . $ level ] = $ adminLevel -> getCode ( ) ; } return strtr ( $ format , $ replace ) ; }
Transform an `Address` instance into a string representation.

@param Location $location
@param string   $format

@return string
Transform an Address instance into a string representation .