SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/cli_bootstrap.php

For local development without an Apache or FPM server.

Fire up your local PHP server with:
> php -S localhost:8080 -t src src/index.php

DO NOT USE THIS IN PRODUCTION.
  1. <?php
  2. /**
  3.  * For local development without an Apache or FPM server.
  4.  *
  5.  * Fire up your local PHP server with:
  6.  * > php -S localhost:8080 -t src src/index.php
  7.  *
  8.  * DO NOT USE THIS IN PRODUCTION.
  9.  */
  10.  
  11. if (PHP_SAPI !== 'cli-server') return;
  12.  
  13. $url = parse_url($_SERVER['REQUEST_URI']);
  14. $_SERVER['QUERY_STRING'] = $url['query'] ?? '';
  15. $path = trim($url['path'], '/');
  16.  
  17. // Serve it statically.
  18. if (is_file(DOCROOT . $path)) {
  19. return false;
  20. }
  21.  
  22. // Rewrites for media + skin files.
  23. // These are identical to those in .htaccess and nginx.conf.
  24. $count = 0;
  25.  
  26. if (!$count) {
  27. $target = preg_replace('!^media-[0-9]+/core/([a-z]+)/(.+)!', 'media/$1/$2', $path, -1, $count);
  28. }
  29.  
  30. if (!$count) {
  31. $target = preg_replace('!^media-[0-9]+/sprout/([a-z]+)/(.+)!', 'sprout/media/$1/$2', $path, -1, $count);
  32. }
  33.  
  34. if (!$count) {
  35. $target = preg_replace('!^media-[0-9]+/([_a-zA-Z0-9]+)/([a-z]+)/(.+)!', 'modules/$1/media/$2/$3', $path, -1, $count);
  36. }
  37.  
  38. if (!$count) {
  39. $target = preg_replace('!^skin-[0-9]+/([_a-z0-9\-]+)/([a-z]+)/(.+)!', 'skin/$1/$2/$3', $path, -1, $count);
  40. }
  41.  
  42. $target = DOCROOT . $target;
  43.  
  44. // Matched a rewrite.
  45. if ($count and file_exists($target)) {
  46. $type = mime_content_type($target);
  47.  
  48. $matches = [];
  49.  
  50. // Built-in mime doesn't do js/css consistently.
  51. if (preg_match('!\.(css)|(js)$!', $target, $matches)) {
  52. if ($matches[1]) $type = 'text/css';
  53. if ($matches[2]) $type = 'application/javascript';
  54. }
  55.  
  56. // Fallback.
  57. if (!$type) {
  58. $type = 'text/plain';
  59. }
  60.  
  61. header('Content-Type: ' . $type);
  62. readfile($target);
  63.  
  64. return true;
  65. }
  66.  
  67. // Otherwise let sprout do it's thing.
  68. return null;
  69.