function runserver_parse_uri

8.0.x runserver.drush.inc runserver_parse_uri($uri)
6.x runserver.drush.inc runserver_parse_uri($uri)
7.x runserver.drush.inc runserver_parse_uri($uri)
5.x runserver.drush.inc runserver_parse_uri($uri)
master runserver.drush.inc runserver_parse_uri($uri)

Parse a URI or partial URI (including just a port, host IP or path).

Parameters

$uri: String that can contain partial URI.

Return value

array URI array as returned by parse_url.

1 call to runserver_parse_uri()
drush_core_runserver in commands/runserver/runserver.drush.inc
Callback for runserver command.

File

commands/runserver/runserver.drush.inc, line 257
Built in http server commands.

Code

function runserver_parse_uri($uri) {
  if ($uri[0] == ':') {
    // ':port/path' shorthand, insert a placeholder hostname to allow parsing.
    $uri = 'placeholder-hostname' . $uri;
  }
  // FILTER_VALIDATE_IP expects '[' and ']' to be removed from IPv6 addresses.
  // We check for colon from the right, since IPv6 addresses contain colons.
  $to_path = trim(substr($uri, 0, strpos($uri, '/')), '[]');
  $to_port = trim(substr($uri, 0, strrpos($uri, ':')), '[]');
  if (filter_var(trim($uri, '[]'), FILTER_VALIDATE_IP) || filter_var($to_path, FILTER_VALIDATE_IP) || filter_var($to_port, FILTER_VALIDATE_IP)) {
    // 'IP', 'IP/path' or 'IP:port' shorthand, insert a schema to allow parsing.
    $uri = 'http://' . $uri;
  }
  $uri = parse_url($uri);
  if (empty($uri)) {
    return drush_set_error('RUNSERVER_INVALID_ADDRPORT', dt('Invalid argument - should be in the "host:port/path" format, numeric (port only) or non-numeric (path only).'));
  }
  if (count($uri) == 1 && isset($uri['path'])) {
    if (is_numeric($uri['path'])) {
      // Port only shorthand.
      $uri['port'] = $uri['path'];
      unset($uri['path']);
    }
  }
  if (isset($uri['host']) && $uri['host'] == 'placeholder-hostname') {
    unset($uri['host']);
  }
  return $uri;
}