Barryvdh\Cors\Util\OriginMatcher::hostMatches PHP Метод

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

public static hostMatches ( $pattern, $host )
    public static function hostMatches($pattern, $host)
    {
        $patternComponents = array_reverse(explode('.', $pattern));
        $hostComponents = array_reverse(explode('.', $host));
        foreach ($patternComponents as $index => $patternComponent) {
            if ($patternComponent === '*') {
                return true;
            }
            if (!isset($hostComponents[$index])) {
                return false;
            }
            if ($hostComponents[$index] !== $patternComponent) {
                return false;
            }
        }
        return count($patternComponents) === count($hostComponents);
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider hostMatchesDataProvider
  */
 public function testHostMatches($pattern, $host, $matches)
 {
     $this->assertSame($matches, OriginMatcher::hostMatches($pattern, $host));
 }