CommerceGuys\Addressing\LocaleHelper::match PHP Метод

match() публичный статический Метод

Checks whether the two locales match.
public static match ( string $firstLocale, string $secondLocale ) : boolean
$firstLocale string The first locale.
$secondLocale string The second locale.
Результат boolean TRUE if the locales match, FALSE otherwise.
    public static function match($firstLocale, $secondLocale)
    {
        if (empty($firstLocale) || empty($secondLocale)) {
            return false;
        }
        $firstLocale = str_replace('-', '_', strtolower($firstLocale));
        $firstLocaleParts = explode('_', $firstLocale);
        $secondLocale = str_replace('-', '_', strtolower($secondLocale));
        $secondLocaleParts = explode('_', $secondLocale);
        // Language codes must match.
        if ($firstLocaleParts[0] != $secondLocaleParts[0]) {
            return false;
        }
        // @todo Match scripts, if found.
        return true;
    }

Usage Example

Пример #1
0
 /**
  * @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'));
 }
All Usage Examples Of CommerceGuys\Addressing\LocaleHelper::match