match() public static method

Checks whether the two locales match.
public static match ( string $firstLocale, string $secondLocale ) : boolean
$firstLocale string The first locale.
$secondLocale string The second locale.
return boolean TRUE if the locales match, FALSE otherwise.
 /**
  * @covers ::match
  */
 public function testMatch()
 {
     $this->assertFalse(LocaleHelper::match('', 'pt'));
     $this->assertFalse(LocaleHelper::match('pt', ''));
     $this->assertFalse(LocaleHelper::match('pt', 'es'));
     $this->assertTrue(LocaleHelper::match('pt', 'pt'));
     $this->assertTrue(LocaleHelper::match('pt-BR', 'pt_BR'));
 }
 /**
  * {@inheritdoc}
  */
 public function getList(array $parents, $locale = null)
 {
     $definitions = $this->loadDefinitions($parents);
     if (empty($definitions)) {
         return [];
     }
     $definitionLocale = isset($definitions['locale']) ? $definitions['locale'] : '';
     $useLocalName = LocaleHelper::match($locale, $definitionLocale);
     $list = [];
     foreach ($definitions['subdivisions'] as $code => $definition) {
         $list[$code] = $useLocalName ? $definition['local_name'] : $definition['name'];
     }
     return $list;
 }
 /**
  * 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;
 }