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 254
Built in http server commands.

Code

function runserver_parse_uri($uri) {
  if ($uri[] == ':') {
    // ':port/path' shorthand, insert a placeholder hostname to allow parsing.
    $uri = 'placeholder-hostname' . $uri;
  }
  $first_part = substr($uri, , strpos($uri, '/'));
  if (ip2long($first_part)) {
    // 'IP/path' 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) ==  && isset($uri['path'])) {
    if (is_numeric($uri['path'])) {
      // Port only shorthand.
      $uri['port'] = $uri['path'];
      unset($uri['path']);
    }
    else if (ip2long($uri['path'])) {
      // IP only shorthand.
      $uri['host'] = $uri['path'];
      unset($uri['path']);
    }
  }
  if (isset($uri['host']) && $uri['host'] == 'placeholder-hostname') {
    unset($uri['host']);
  }
  return $uri;
}