From 0b385d05af545460f3f972e507aa5cb4bcc7a669 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Aug 2015 15:47:04 +0100 Subject: [PATCH] wibble init into a separate bootstrap file, for more unit-testability --- core/_bootstrap.inc.php | 43 +++++++++++++++++++++++++++ core/util.inc.php | 64 +++++++++++++---------------------------- index.php | 39 ++++--------------------- tests/all.php | 26 +---------------- 4 files changed, 70 insertions(+), 102 deletions(-) create mode 100644 core/_bootstrap.inc.php diff --git a/core/_bootstrap.inc.php b/core/_bootstrap.inc.php new file mode 100644 index 00000000..5659665c --- /dev/null +++ b/core/_bootstrap.inc.php @@ -0,0 +1,43 @@ += $threshold)) { + + if((PHP_SAPI === 'cli') && ($priority >= $threshold)) { print date("c")." $section: $message\n"; } if($flash === true) { @@ -1504,10 +1483,7 @@ function score_assert_handler($file, $line, $code, $desc = null) { print(""); */ } -//assert_options(ASSERT_ACTIVE, 1); -assert_options(ASSERT_WARNING, 0); -assert_options(ASSERT_QUIET_EVAL, 1); -assert_options(ASSERT_CALLBACK, 'score_assert_handler'); + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Request initialisation stuff * @@ -1515,12 +1491,16 @@ assert_options(ASSERT_CALLBACK, 'score_assert_handler'); /** @privatesection */ -/** - * @param array|string $arr - * @return array|string - */ -function _stripslashes_r($arr) { - return is_array($arr) ? array_map('_stripslashes_r', $arr) : stripslashes($arr); +function _version_check() { + $min_version = "5.4.8"; + if(version_compare(PHP_VERSION, $min_version) == -1) { + print " +Currently SCore Engine doesn't support versions of PHP lower than $min_version -- +if your web host is running an older version, they are dangerously out of +date and you should plan on moving elsewhere. +"; + exit; + } } function _sanitise_environment() { @@ -1530,11 +1510,15 @@ function _sanitise_environment() { if(DEBUG) { error_reporting(E_ALL); + assert_options(ASSERT_ACTIVE, 1); + assert_options(ASSERT_BAIL, 1); + assert_options(ASSERT_WARNING, 0); + assert_options(ASSERT_QUIET_EVAL, 1); + assert_options(ASSERT_CALLBACK, 'score_assert_handler'); } if(CONTEXT) { ctx_set_log(CONTEXT); - ctx_log_start(@$_SERVER["REQUEST_URI"], true, true); } if(COVERAGE) { @@ -1542,18 +1526,9 @@ function _sanitise_environment() { register_shutdown_function("_end_coverage"); } - assert_options(ASSERT_ACTIVE, 1); - assert_options(ASSERT_BAIL, 1); - ob_start(); - if(get_magic_quotes_gpc()) { - $_GET = _stripslashes_r($_GET); - $_POST = _stripslashes_r($_POST); - $_COOKIE = _stripslashes_r($_COOKIE); - } - - if(is_cli()) { + if(PHP_SAPI === 'cli') { if(isset($_SERVER['REMOTE_ADDR'])) { die("CLI with remote addr? Confused, not taking the risk."); } @@ -1562,6 +1537,7 @@ function _sanitise_environment() { } } + /** * @param string $_theme * @return array diff --git a/index.php b/index.php index d386aa44..a629da01 100644 --- a/index.php +++ b/index.php @@ -47,48 +47,21 @@ if(!file_exists("data/config/shimmie.conf.php")) { header("Location: install.php"); exit; } -require_once "core/sys_config.inc.php"; -require_once "core/util.inc.php"; - -// set up and purify the environment -_version_check(); -_sanitise_environment(); try { - // load base files - ctx_log_start("Opening files"); - $files = array_merge(zglob("core/*.php"), zglob("ext/{".ENABLED_EXTS."}/main.php")); - foreach($files as $filename) { - require_once $filename; - } - ctx_log_endok(); - - ctx_log_start("Connecting to DB"); - // connect to the database - $database = new Database(); - $config = new DatabaseConfig($database); - ctx_log_endok(); - - // load the theme parts - ctx_log_start("Loading themelets"); - foreach(_get_themelet_files(get_theme()) as $themelet) { - require_once $themelet; - } - ctx_log_endok(); - - _load_extensions(); + require_once "core/_bootstrap.inc.php"; + ctx_log_start(@$_SERVER["REQUEST_URI"], true, true); // start the page generation waterfall - $page = class_exists("CustomPage") ? new CustomPage() : new Page(); $user = _get_user(); send_event(new InitExtEvent()); - if(!is_cli()) { // web request + if(PHP_SAPI === 'cli') { + send_event(new CommandEvent($argv)); + } + else { send_event(new PageRequestEvent(_get_query())); $page->display(); } - else { // command line request - send_event(new CommandEvent($argv)); - } // saving cache data and profiling data to disk can happen later if(function_exists("fastcgi_finish_request")) fastcgi_finish_request(); diff --git a/tests/all.php b/tests/all.php index 59a687f4..2d82e8e9 100644 --- a/tests/all.php +++ b/tests/all.php @@ -29,33 +29,9 @@ define("_TRAVIS_WEBHOST", $host); // The code below is based on the code in index.php //-------------------------------------------------- -require_once "core/sys_config.inc.php"; -require_once "core/util.inc.php"; - -// set up and purify the environment -_version_check(); -_sanitise_environment(); - -// load base files -$files = array_merge(zglob("core/*.php"), zglob("ext/{".ENABLED_EXTS."}/main.php")); -foreach($files as $filename) { - require_once $filename; -} - -// We also need to pull in the SimpleTest extension. +require_once('core/_bootstrap.inc.php'); require_once('ext/simpletest/main.php'); -// connect to the database -$database = new Database(); -$config = new DatabaseConfig($database); - -// load the theme parts -foreach(_get_themelet_files(get_theme()) as $themelet) { - require_once $themelet; -} - -_load_extensions(); - // Fire off the InitExtEvent() $page = class_exists("CustomPage") ? new CustomPage() : new Page(); $user = _get_user();