runserver-drupal.inc

  1. 6.x commands/runserver/runserver-drupal.inc
  2. 5.x commands/runserver/runserver-drupal.inc

Classes extending the httpserver library that provide Drupal specific behaviours.

Classes

Namesort descending Description
DrupalServer Extends the HTTPServer class, handling request routing and environment.

File

commands/runserver/runserver-drupal.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Classes extending the httpserver library that provide Drupal specific
  5. * behaviours.
  6. */
  7. /**
  8. * Extends the HTTPServer class, handling request routing and environment.
  9. */
  10. class DrupalServer extends HTTPServer {
  11. // We pass in variables, rather than querying options here, to allow this to
  12. // potentially be used in other commands.
  13. public $path, $debug, $env, $site;
  14. /**
  15. * This is the equivalent of .htaccess, passing requests to files if they
  16. * exist, and all other requests to index.php. We also set a number
  17. * of CGI environment variables here.
  18. */
  19. function route_request($request) {
  20. $cgi_env = $this->env;
  21. // Handle static files and php scripts accessed directly
  22. $uri = $request->uri;
  23. $doc_root = DRUPAL_ROOT;
  24. $path = $doc_root . $uri;
  25. if (is_file(realpath($path))) {
  26. if (preg_match('#\.php$#', $uri)) {
  27. // SCRIPT_NAME is equal to uri if it does exist on disk
  28. $cgi_env['SCRIPT_NAME'] = $uri;
  29. return $this->get_php_response($request, $path, $cgi_env);
  30. }
  31. return $this->get_static_response($request, $path);
  32. }
  33. // Rewrite clean-urls
  34. $cgi_env['QUERY_STRING'] = 'q=' . ltrim($uri, '/');
  35. if ($request->query_string != "") {
  36. $cgi_env['QUERY_STRING'] .= '&' . $request->query_string;
  37. }
  38. $cgi_env['SCRIPT_NAME'] = '/index.php';
  39. $cgi_env['HTTP_HOST'] = $cgi_env['SERVER_NAME'] = $this->site;
  40. return $this->get_php_response($request, $doc_root . '/index.php', $cgi_env);
  41. }
  42. /**
  43. * Override get started event.
  44. */
  45. function listening() {
  46. if (!empty($this->browse)) {
  47. drush_start_browser($this->browse);
  48. }
  49. }
  50. /**
  51. * Override request done event.
  52. */
  53. function request_done($request) {
  54. drush_print(trim($this->get_log_line($request), "\n"));
  55. if ($this->debug) {
  56. drush_print_r($request);
  57. }
  58. }
  59. }