public static function parseOriginPattern($originPattern, $component = -1)
{
$matched = preg_match('!\\A
(?: (?P<scheme> https? ):// )?
(?P<host> (?:\\*|[\\w-]+)(?:\\.[\\w-]+)* )
(?: :(?P<port> (?: \\*|\\d+(?:-\\d+)? ) ) )?
\\z!x', $originPattern, $captured);
if (!$matched) {
throw new \InvalidArgumentException("Invalid origin pattern {$originPattern}");
}
$components = ['scheme' => $captured['scheme'] ?: null, 'host' => $captured['host'], 'port' => array_key_exists('port', $captured) ? $captured['port'] : null];
switch ($component) {
case -1:
return $components;
case PHP_URL_SCHEME:
return $components['scheme'];
case PHP_URL_HOST:
return $components['host'];
case PHP_URL_PORT:
return $components['port'];
}
throw new \InvalidArgumentException("Invalid component: {$component}");
}