function drush_core_runserver_validate

6.x runserver.drush.inc drush_core_runserver_validate()
5.x runserver.drush.inc drush_core_runserver_validate()

Validate callback for runserver command.

File

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

Code

function drush_core_runserver_validate() {
  if (version_compare(PHP_VERSION, '5.3.0') < ) {
    return drush_set_error('RUNSERVER_PHP53_VERSION', dt('The runserver command requires php 5.3, which could not be found.'));
  }
  $php_cgi = drush_shell_exec('which ' . drush_get_option('php-cgi', 'php-cgi'));
  $builtin = version_compare(PHP_VERSION, '5.4.0') >= ;
  $server = drush_get_option('server', FALSE);
  if (!$server) {
    // No server specified, try and find a valid server option, preferring cgi.
    if ($php_cgi) {
      $server = 'cgi';
      drush_set_option('server', 'cgi');
    }
    else if ($builtin) {
      $server = 'builtin';
      drush_set_option('server', 'builtin');
    }
    else {
      return drush_set_error('RUNSERVER_PHP_CGI54', dt('The runserver command requires either the php-cgi binary, or php 5.4 (or higher). Neither could not be found.'));
    }
  }
  else if ($server == 'cgi' && !$php_cgi) {
    // Validate user specified cgi server option.
    return drush_set_error('RUNSERVER_PHP_CGI', dt('The runserver command with the "cgi" server requires the php-cgi binary, which could not be found.'));
  }
  else if ($server == 'builtin' && !$builtin) {
    // Validate user specified builtin server option.
    return drush_set_error('RUNSERVER_PHP_CGI', dt('The runserver command with the "builtin" server requires php 5.4 (or higher), which could not be found.'));
  }

  // Update with detected configuration.
  $server = drush_get_option('server', FALSE);
  if ($server == 'cgi') {
    // Fetch httpserver cgi based server to our /lib directory, if needed.
    $lib = drush_get_option('lib', DRUSH_BASE_PATH . '/lib');
    $httpserverfile = $lib . '/' . DRUSH_HTTPSERVER_DIR_BASE . substr(DRUSH_HTTPSERVER_VERSION, , ) . '/httpserver.php';
    if (!drush_file_not_empty($httpserverfile)) {
      // Download and extract httpserver, and confirm success.
      drush_lib_fetch(DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION);
      if (!drush_file_not_empty($httpserverfile)) {
        // Something went wrong - the library is still not present.
        return drush_set_error('RUNSERVER_HTTPSERVER_LIB_NOT_FOUND', dt("The runserver command needs a copy of the httpserver library in order to function, and the attempt to download this file automatically failed. To continue you will need to download the package from !url, extract it into the !lib directory, such that httpserver.php exists at !httpserverfile.", array('!version' => DRUSH_HTTPSERVER_VERSION, '!url' => DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION, '!httpserverfile' => $httpserverfile, '!lib' => $lib)));
      }
    }
  }

  // Check we have a valid server.
  if (!in_array($server, array('cgi', 'builtin'))) {
    return drush_set_error('RUNSERVER_INVALID', dt('Invalid server specified.'));
  }
}