PHP Class CommerceGuys\Addressing\Formatter\DefaultFormatter

The address is formatted according to the destination country format. The localized country name is added to the formatted address.
Inheritance: implements CommerceGuys\Addressing\Formatter\FormatterInterface
Show file Open project: commerceguys/addressing Class Usage Examples

Protected Properties

Property Type Description
$addressFormatRepository CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface The address format repository.
$countryRepository CommerceGuys\Addressing\Country\CountryRepositoryInterface The country repository.
$locale string The locale.
$options array The options.
$subdivisionRepository CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface The subdivision repository.

Public Methods

Method Description
__construct ( CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface $addressFormatRepository, CommerceGuys\Addressing\Country\CountryRepositoryInterface $countryRepository, CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface $subdivisionRepository, string $locale = null, array $options = [] ) Creates a DefaultFormatter instance.
format ( CommerceGuys\Addressing\AddressInterface $address )
getLocale ( )
getOption ( $key )
getOptions ( )
setLocale ( $locale )
setOption ( $key, $value )
setOptions ( array $options )

Protected Methods

Method Description
buildView ( CommerceGuys\Addressing\AddressInterface $address, AddressFormat $addressFormat ) : array Builds the view for the given address.
cleanupOutput ( string $output ) : string Removes empty lines, leading punctuation, excess whitespace.
getDefaultOptions ( ) : array Gets the default options.
getValues ( CommerceGuys\Addressing\AddressInterface $address, AddressFormat $addressFormat ) : array Gets the address values used to build the view.
renderAttributes ( array $attributes ) : string Renders the given attributes.
renderView ( array $view ) : array Renders the given view.

Method Details

__construct() public method

Creates a DefaultFormatter instance.
public __construct ( CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface $addressFormatRepository, CommerceGuys\Addressing\Country\CountryRepositoryInterface $countryRepository, CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface $subdivisionRepository, string $locale = null, array $options = [] )
$addressFormatRepository CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface
$countryRepository CommerceGuys\Addressing\Country\CountryRepositoryInterface
$subdivisionRepository CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface
$locale string
$options array

buildView() protected method

Builds the view for the given address.
protected buildView ( CommerceGuys\Addressing\AddressInterface $address, AddressFormat $addressFormat ) : array
$address CommerceGuys\Addressing\AddressInterface The address.
$addressFormat CommerceGuys\Addressing\AddressFormat\AddressFormat The address format.
return array The view.

cleanupOutput() protected method

Removes empty lines, leading punctuation, excess whitespace.
protected cleanupOutput ( string $output ) : string
$output string The output that needs cleanup.
return string The cleaned up output.

format() public method

public format ( CommerceGuys\Addressing\AddressInterface $address )
$address CommerceGuys\Addressing\AddressInterface

getDefaultOptions() protected method

Gets the default options.
protected getDefaultOptions ( ) : array
return array The default options.

getLocale() public method

public getLocale ( )

getOption() public method

public getOption ( $key )

getOptions() public method

public getOptions ( )

getValues() protected method

Gets the address values used to build the view.
protected getValues ( CommerceGuys\Addressing\AddressInterface $address, AddressFormat $addressFormat ) : array
$address CommerceGuys\Addressing\AddressInterface The address.
$addressFormat CommerceGuys\Addressing\AddressFormat\AddressFormat The address format.
return array The values, keyed by address field.

renderAttributes() protected method

Renders the given attributes.
protected renderAttributes ( array $attributes ) : string
$attributes array The attributes.
return string The rendered attributes.

renderView() protected method

Renders the given view.
protected renderView ( array $view ) : array
$view array The view.
return array An array of rendered values with the original keys preserved.

setLocale() public method

public setLocale ( $locale )

setOption() public method

public setOption ( $key, $value )

setOptions() public method

public setOptions ( array $options )
$options array

Property Details

$addressFormatRepository protected property

The address format repository.
protected AddressFormatRepositoryInterface,CommerceGuys\Addressing\AddressFormat $addressFormatRepository
return CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface

$countryRepository protected property

The country repository.
protected CountryRepositoryInterface,CommerceGuys\Addressing\Country $countryRepository
return CommerceGuys\Addressing\Country\CountryRepositoryInterface

$locale protected property

The locale.
protected string $locale
return string

$options protected property

The options.
protected array $options
return array

$subdivisionRepository protected property

The subdivision repository.
protected SubdivisionRepositoryInterface,CommerceGuys\Addressing\Subdivision $subdivisionRepository
return CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface