SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/composer_bootstrap.php

  1. <?php
  2. // This bootstrap only concerns CLI environments.
  3. // The sprout index.php does all this for web contexts.
  4. if (PHP_SAPI !== 'cli') return;
  5.  
  6. // We can also rely on the autoloader being initialised much later.
  7. // This tells us that we're being included when all of this already exists (sprout workers, crons).
  8. if (!(
  9. defined('KOHANA') or
  10. defined('PHPUNIT') or
  11. defined('PHPUNIT_COMPOSER_INSTALL')
  12. )):
  13.  
  14. date_default_timezone_set('Australia/Adelaide');
  15.  
  16. define('IN_PRODUCTION', false);
  17. define('KOHANA', realpath(__DIR__ . '/../'));
  18. define('DOCROOT', KOHANA . '/');
  19. define('APPPATH', DOCROOT . 'sprout/');
  20.  
  21. function _privDetermineWebDirectory() {
  22. if (!empty($_SERVER['PHP_S_WEBDIR'])) return $_SERVER['PHP_S_WEBDIR'];
  23. if (! $_SERVER['DOCUMENT_ROOT']) return false;
  24.  
  25. $pos = strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']);
  26. if ($pos === 0) {
  27. $doc_path = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']));
  28. $doc_path = dirname($doc_path);
  29.  
  30. if (substr($doc_path, 0, 1) != '/') $doc_path = '/' . $doc_path;
  31. if (substr($doc_path, -1, 1) != '/') $doc_path .= '/';
  32.  
  33. if ($_SERVER['REQUEST_URI'] and preg_match('!^/v[1-9]/!', $doc_path) and !preg_match('!^/v[1-9]/!', $_SERVER['REQUEST_URI'])) {
  34. $doc_path = preg_replace('!^/v[1-9]/!', '/', $doc_path);
  35. }
  36.  
  37. return $doc_path;
  38. }
  39.  
  40. return false;
  41. }
  42.  
  43. // Fake server vars when run from CLI
  44. if (empty($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  45.  
  46. // Load core files
  47. require_once APPPATH . 'core/utf8.php';
  48. require_once APPPATH . 'core/Event.php';
  49. require_once APPPATH . 'core/Kohana.php';
  50.  
  51. endif;