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

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

public static portMatches ( $pattern, $port )
    public static function portMatches($pattern, $port)
    {
        if ($pattern === "*") {
            return true;
        }
        if ((string) $pattern === "") {
            return (string) $port === "";
        }
        if (preg_match('/\\A\\d+\\z/', $pattern)) {
            return (string) $pattern === (string) $port;
        }
        if (preg_match('/\\A(?P<from>\\d+)-(?P<to>\\d+)\\z/', $pattern, $captured)) {
            return $captured['from'] <= $port && $port <= $captured['to'];
        }
        throw new \InvalidArgumentException("Invalid port pattern: {$pattern}");
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider portMatchesDataProvider
  */
 public function testPortMatches($pattern, $port, $matches)
 {
     $this->assertSame($matches, OriginMatcher::portMatches($pattern, $port));
 }