more stuff to util.php

This commit is contained in:
Shish 2020-01-27 19:05:43 +00:00
parent b03eb861d4
commit b0237ddd97
4 changed files with 34 additions and 36 deletions

View file

@ -4,47 +4,23 @@
* actually do anything as far as the app is concerned * actually do anything as far as the app is concerned
*/ */
global $cache, $config, $database, $user, $page, $_tracer, $tracer_enabled; global $cache, $config, $database, $user, $page, $_tracer;
require_once "core/sys_config.php"; require_once "core/sys_config.php";
require_once "core/polyfills.php"; require_once "core/polyfills.php";
require_once "core/util.php"; require_once "core/util.php";
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
// set up and purify the environment
_version_check();
_sanitise_environment(); _sanitise_environment();
// The trace system has a certain amount of memory consumption every time it is used,
// so to prevent running out of memory during complex operations code that uses it should
// check if tracer output is enabled before making use of it.
$tracer_enabled = constant('TRACE_FILE')!==null;
// load base files
$_tracer->begin("Bootstrap"); $_tracer->begin("Bootstrap");
require_all(array_merge( _load_core_files();
zglob("core/*.php"),
zglob("core/{".ENABLED_MODS."}/*.php"),
zglob("ext/*/info.php")
));
$cache = new Cache(CACHE_DSN); $cache = new Cache(CACHE_DSN);
$database = new Database(DATABASE_DSN); $database = new Database(DATABASE_DSN);
$config = new DatabaseConfig($database); $config = new DatabaseConfig($database);
ExtensionInfo::load_all_extension_info(); ExtensionInfo::load_all_extension_info();
Extension::determine_enabled_extensions(); Extension::determine_enabled_extensions();
require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php"));
_load_theme_files();
// load the theme parts
require_all(_get_themelet_files(get_theme()));
$page = new Page(); $page = new Page();
// hook up event handlers
_load_event_listeners(); _load_event_listeners();
if (AUTO_DB_UPGRADE) {
send_event(new DatabaseUpgradeEvent());
}
send_event(new InitExtEvent());
$_tracer->end(); $_tracer->end();

View file

@ -477,8 +477,22 @@ function require_all(array $files): void {
} }
} }
function _version_check(): void function _load_core_files() {
require_all(array_merge(
zglob("core/*.php"),
zglob("core/{".ENABLED_MODS."}/*.php"),
zglob("ext/*/info.php")
));
}
function _load_theme_files() {
require_all(_get_themelet_files(get_theme()));
}
function _sanitise_environment(): void
{ {
global $_tracer, $tracer_enabled;
if (MIN_PHP_VERSION) { if (MIN_PHP_VERSION) {
if (version_compare(phpversion(), MIN_PHP_VERSION, ">=") === false) { if (version_compare(phpversion(), MIN_PHP_VERSION, ">=") === false) {
print " print "
@ -490,11 +504,10 @@ date and you should plan on moving elsewhere.
exit; exit;
} }
} }
}
function _sanitise_environment(): void if (file_exists("images") && !file_exists("data/images")) {
{ die("As of Shimmie 2.7 images and thumbs should be moved to data/images and data/thumbs");
global $_tracer; }
if (TIMEZONE) { if (TIMEZONE) {
date_default_timezone_set(TIMEZONE); date_default_timezone_set(TIMEZONE);
@ -506,6 +519,10 @@ function _sanitise_environment(): void
error_reporting(E_ALL); error_reporting(E_ALL);
} }
// The trace system has a certain amount of memory consumption every time it is used,
// so to prevent running out of memory during complex operations code that uses it should
// check if tracer output is enabled before making use of it.
$tracer_enabled = constant('TRACE_FILE')!==null;
$_tracer = new EventTracer(); $_tracer = new EventTracer();
if (COVERAGE) { if (COVERAGE) {

View file

@ -48,10 +48,6 @@ if (!file_exists("data/config/shimmie.conf.php")) {
exit; exit;
} }
if (file_exists("images") && !file_exists("data/images")) {
die("As of Shimmie 2.7 images and thumbs should be moved to data/images and data/thumbs");
}
if (!file_exists("vendor/")) { if (!file_exists("vendor/")) {
//CHECK: Should we just point to install.php instead? Seems unsafe though. //CHECK: Should we just point to install.php instead? Seems unsafe though.
print <<<EOD print <<<EOD
@ -87,6 +83,11 @@ require_once "core/_bootstrap.php";
//$_tracer->mark(@$_SERVER["REQUEST_URI"]); //$_tracer->mark(@$_SERVER["REQUEST_URI"]);
$_tracer->begin($_SERVER["REQUEST_URI"] ?? "No Request"); $_tracer->begin($_SERVER["REQUEST_URI"] ?? "No Request");
if (AUTO_DB_UPGRADE) {
send_event(new DatabaseUpgradeEvent());
}
send_event(new InitExtEvent());
try { try {
// start the page generation waterfall // start the page generation waterfall
$user = _get_user(); $user = _get_user();

View file

@ -9,6 +9,10 @@ $_SERVER['QUERY_STRING'] = '/';
chdir(dirname(dirname(__FILE__))); chdir(dirname(dirname(__FILE__)));
require_once "core/_bootstrap.php"; require_once "core/_bootstrap.php";
if (AUTO_DB_UPGRADE) {
send_event(new DatabaseUpgradeEvent());
}
send_event(new InitExtEvent());
abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
{ {