format() публичный Метод

public format ( CommerceGuys\Addressing\AddressInterface $address )
$address CommerceGuys\Addressing\AddressInterface
 /**
  * @covers \CommerceGuys\Addressing\Formatter\PostalLabelFormatter
  */
 public function testAddressLeadingPostPrefix()
 {
     $address = new Address();
     $address = $address->withCountryCode('CH')->withLocality('Herrliberg')->withPostalCode('8047');
     // Domestic mail shouldn't have the postal code prefix added.
     $expectedLines = ['8047 Herrliberg'];
     $this->formatter->setOriginCountryCode('CH');
     $formattedAddress = $this->formatter->format($address);
     $this->assertFormattedAddress($expectedLines, $formattedAddress);
     // International mail should have the postal code prefix added.
     $expectedLines = ['CH-8047 Herrliberg', 'SWITZERLAND'];
     $this->formatter->setOriginCountryCode('FR');
     $formattedAddress = $this->formatter->format($address);
     $this->assertFormattedAddress($expectedLines, $formattedAddress);
 }
Пример #2
0
 /**
  * Format an address to a postal label
  *
  * @param AddressInterface $address
  * @param null $locale
  * @param null $originCountry
  * @param array $options
  * @return string
  */
 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;
 }