/**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     if ($address->getCountryCode() != $this->configuration['country_code']) {
         return FALSE;
     }
     $administrative_area = $this->configuration['administrative_area'];
     $locality = $this->configuration['locality'];
     $dependent_locality = $this->configuration['dependent_locality'];
     if ($administrative_area && $administrative_area != $address->getAdministrativeArea()) {
         return FALSE;
     }
     if ($locality && $locality != $address->getLocality()) {
         return FALSE;
     }
     if ($dependent_locality && $dependent_locality != $address->getDependentLocality()) {
         return FALSE;
     }
     $included_postal_codes = $this->configuration['included_postal_codes'];
     $excluded_postal_codes = $this->configuration['excluded_postal_codes'];
     if (!PostalCodeHelper::match($address->getPostalCode(), $included_postal_codes, $excluded_postal_codes)) {
         return FALSE;
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function format(AddressInterface $address)
 {
     $countryCode = $address->getCountryCode();
     $addressFormat = $this->addressFormatRepository->get($countryCode, $address->getLocale());
     $formatString = $addressFormat->getFormat();
     // Add the country to the bottom or the top of the format string,
     // depending on whether the format is minor-to-major or major-to-minor.
     if (strpos($formatString, AddressField::ADDRESS_LINE1) < strpos($formatString, AddressField::ADDRESS_LINE2)) {
         $formatString .= "\n" . '%country';
     } else {
         $formatString = '%country' . "\n" . $formatString;
     }
     $view = $this->buildView($address, $addressFormat);
     $view = $this->renderView($view);
     // Insert the rendered elements into the format string.
     $replacements = [];
     foreach ($view as $key => $element) {
         $replacements['%' . $key] = $element;
     }
     $output = strtr($formatString, $replacements);
     $output = $this->cleanupOutput($output);
     if (!empty($this->options['html'])) {
         $output = nl2br($output, false);
         // Add the HTML wrapper element.
         $attributes = $this->renderAttributes($this->options['html_attributes']);
         $prefix = '<' . $this->options['html_tag'] . ' ' . $attributes . '>' . "\n";
         $suffix = "\n" . '</' . $this->options['html_tag'] . '>';
         $output = $prefix . $output . $suffix;
     }
     return $output;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     $eu_countries = ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'];
     return in_array($address->getCountryCode(), $eu_countries);
 }
 /**
  * {@inheritdoc}
  */
 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;
 }