wibble init into a separate bootstrap file, for more unit-testability
This commit is contained in:
parent
f68102b267
commit
0b385d05af
4 changed files with 70 additions and 102 deletions
43
core/_bootstrap.inc.php
Normal file
43
core/_bootstrap.inc.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/*
|
||||
* Load all the files into memory, sanitise the environment, but don't
|
||||
* actually do anything as far as the app is concerned
|
||||
*/
|
||||
|
||||
require_once "core/sys_config.inc.php";
|
||||
require_once "core/util.inc.php";
|
||||
require_once "lib/context.php";
|
||||
|
||||
// set up and purify the environment
|
||||
_version_check();
|
||||
_sanitise_environment();
|
||||
|
||||
// load base files
|
||||
ctx_log_start("Opening files");
|
||||
$files = array_merge(
|
||||
zglob("core/*.php"),
|
||||
zglob("ext/{".ENABLED_EXTS."}/main.php")
|
||||
);
|
||||
foreach($files as $filename) {
|
||||
if(basename($filename)[0] != "_") {
|
||||
require_once $filename;
|
||||
}
|
||||
}
|
||||
ctx_log_endok();
|
||||
|
||||
// connect to the database
|
||||
ctx_log_start("Connecting to DB");
|
||||
$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;
|
||||
}
|
||||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||
ctx_log_endok();
|
||||
|
||||
// hook up event handlers
|
||||
_load_extensions();
|
|
@ -699,28 +699,6 @@ function getExtension ($mime_type){
|
|||
return ($ext ? $ext : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function is_cli() {
|
||||
return (PHP_SAPI === 'cli');
|
||||
}
|
||||
|
||||
|
||||
$_execs = 0;
|
||||
/**
|
||||
|
@ -1144,7 +1122,8 @@ define("SCORE_LOG_NOTSET", 0);
|
|||
function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=false, $args=array()) {
|
||||
send_event(new LogEvent($section, $priority, $message, $args));
|
||||
$threshold = defined("CLI_LOG_LEVEL") ? CLI_LOG_LEVEL : 0;
|
||||
if(is_cli() && ($priority >= $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("</pre>");
|
||||
*/
|
||||
}
|
||||
//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
|
||||
|
|
39
index.php
39
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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue