Field names follow the OASIS "eXtensible Address Language" (xAL) standard: http://www.oasis-open.org/committees/ciq/download.shtml Doesn't include the sub-administrative area (United States: county, Italy: province, Great Britain: county) because it is not required for addressing purposes. Makes no assumptions about mutability. The implementing application can extend the interface to provide setters, or implement a value object that uses either PSR-7 style with* mutators or relies on an AddressBuilder.
See also: CommerceGuys\Addressing\ImmutableAddressInterface
Ejemplo n.º 1
0
 /**
  * {@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;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     $euCountries = ['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'];
     $countryCode = $address->getCountryCode();
     return in_array($countryCode, $euCountries);
 }
Ejemplo n.º 3
0
 /**
  * Gets the address values used to build the view.
  *
  * @param AddressInterface $address       The address.
  * @param AddressFormat    $addressFormat The address format.
  *
  * @return array The values, keyed by address field.
  */
 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 = LocaleHelper::match($address->getLocale(), $subdivision->getLocale());
         $values[$field] = $useLocalName ? $subdivision->getLocalCode() : $subdivision->getCode();
         if (!$subdivision->hasChildren()) {
             // The current subdivision has no children, stop.
             break;
         }
     }
     return $values;
 }