more stuff into regular functions

This commit is contained in:
Shish 2020-01-27 18:24:11 +00:00
parent 9b50e98927
commit 903679dc53
7 changed files with 34 additions and 55 deletions

View File

@ -22,59 +22,26 @@ $tracer_enabled = constant('TRACE_FILE')!==null;
// load base files
$_tracer->begin("Bootstrap");
$_tracer->begin("Opening core files");
$_shm_files = array_merge(
require_all(array_merge(
zglob("core/*.php"),
zglob("core/{".ENABLED_MODS."}/*.php"),
zglob("ext/*/info.php")
);
foreach ($_shm_files as $_shm_filename) {
if (basename($_shm_filename)[0] != "_") {
require_once $_shm_filename;
}
}
unset($_shm_files);
unset($_shm_filename);
$_tracer->end();
));
$_tracer->begin("Connecting to Cache");
$cache = new Cache(CACHE_DSN);
$_tracer->end();
$_tracer->begin("Connecting to DB");
$database = new Database();
$database = new Database(DATABASE_DSN);
$config = new DatabaseConfig($database);
$_tracer->end();
$_tracer->begin("Loading extension info");
ExtensionInfo::load_all_extension_info();
Extension::determine_enabled_extensions();
$_tracer->end();
$_tracer->begin("Opening enabled extension files");
$_shm_files = zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php");
foreach ($_shm_files as $_shm_filename) {
if (basename($_shm_filename)[0] != "_") {
require_once $_shm_filename;
}
}
unset($_shm_files);
unset($_shm_filename);
$_tracer->end();
require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php"));
// load the theme parts
$_tracer->begin("Loading themelets");
foreach (_get_themelet_files(get_theme()) as $themelet) {
require_once $themelet;
}
unset($themelet);
require_all(_get_themelet_files(get_theme()));
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
$_tracer->end();
// hook up event handlers
$_tracer->begin("Loading event listeners");
_load_event_listeners();
$_tracer->end();
if (AUTO_DB_UPGRADE) {
send_event(new DatabaseUpgradeEvent());

View File

@ -92,10 +92,9 @@ function do_install()
}
define("CACHE_DSN", null);
define("DATABASE_KA", true);
try {
create_dirs();
create_tables(new Database());
create_tables(new Database(DATABASE_DSN));
write_config();
} catch (InstallerException $e) {
print <<<EOD

View File

@ -13,6 +13,8 @@ abstract class DatabaseDriver
*/
class Database
{
/** @var string */
private $dsn;
/**
* The PDO database connection object, for anyone who wants direct access.
@ -44,9 +46,13 @@ class Database
*/
public $query_count = 0;
public function __construct(string $dsn) {
$this->dsn = $dsn;
}
private function connect_db(): void
{
$this->db = new PDO(DATABASE_DSN, [
$this->db = new PDO($this->dsn, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

View File

@ -469,6 +469,14 @@ function get_debug_info(): string
/** @privatesection */
function require_all(array $files): void {
foreach ($files as $filename) {
if (basename($filename)[0] != "_") {
require_once $filename;
}
}
}
function _version_check(): void
{
if (MIN_PHP_VERSION) {

View File

@ -60,7 +60,7 @@ if (!file_exists("vendor/")) {
<head>
<title>Shimmie Error</title>
<link rel="shortcut icon" href="ext/handle_static/static/favicon.ico">
<link rel="stylesheet" href="lib/shimmie.css" type="text/css">
<link rel="stylesheet" href="ext/handle_static/style.css" type="text/css">
</head>
<body>
<div id="installer">

View File

@ -10,18 +10,6 @@ $_SERVER['QUERY_STRING'] = '/';
chdir(dirname(dirname(__FILE__)));
require_once "core/_bootstrap.php";
function create_user(string $name)
{
if (is_null(User::by_name($name))) {
$userPage = new UserPage();
$userPage->onUserCreation(new UserCreationEvent($name, $name, ""));
assert(!is_null(User::by_name($name)), "Creation of user $name failed");
}
}
create_user("demo");
create_user("test");
abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
{
private $images = [];
@ -35,6 +23,9 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
$this->markTestSkipped("$class not supported with this database");
}
$this->create_user("demo");
$this->create_user("test");
// things to do after bootstrap and before request
// log in as anon
$this->log_out();
@ -47,6 +38,15 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
}
}
protected function create_user(string $name)
{
if (is_null(User::by_name($name))) {
$userPage = new UserPage();
$userPage->onUserCreation(new UserCreationEvent($name, $name, ""));
assert(!is_null(User::by_name($name)), "Creation of user $name failed");
}
}
protected function get_page($page_name, $args=null)
{
// use a fresh page

View File

@ -1,6 +1,5 @@
<?php
define("DATABASE_DSN", null);
define("DATABASE_KA", true);
define("DATABASE_TIMEOUT", 10000);
define("CACHE_DSN", null);
define("DEBUG", false);