more stuff into regular functions
This commit is contained in:
parent
9b50e98927
commit
903679dc53
7 changed files with 34 additions and 55 deletions
|
@ -22,59 +22,26 @@ $tracer_enabled = constant('TRACE_FILE')!==null;
|
||||||
|
|
||||||
// load base files
|
// load base files
|
||||||
$_tracer->begin("Bootstrap");
|
$_tracer->begin("Bootstrap");
|
||||||
$_tracer->begin("Opening core files");
|
require_all(array_merge(
|
||||||
$_shm_files = array_merge(
|
|
||||||
zglob("core/*.php"),
|
zglob("core/*.php"),
|
||||||
zglob("core/{".ENABLED_MODS."}/*.php"),
|
zglob("core/{".ENABLED_MODS."}/*.php"),
|
||||||
zglob("ext/*/info.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);
|
$cache = new Cache(CACHE_DSN);
|
||||||
$_tracer->end();
|
$database = new Database(DATABASE_DSN);
|
||||||
|
|
||||||
$_tracer->begin("Connecting to DB");
|
|
||||||
$database = new Database();
|
|
||||||
$config = new DatabaseConfig($database);
|
$config = new DatabaseConfig($database);
|
||||||
$_tracer->end();
|
|
||||||
|
|
||||||
$_tracer->begin("Loading extension info");
|
|
||||||
ExtensionInfo::load_all_extension_info();
|
ExtensionInfo::load_all_extension_info();
|
||||||
Extension::determine_enabled_extensions();
|
Extension::determine_enabled_extensions();
|
||||||
$_tracer->end();
|
require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php"));
|
||||||
|
|
||||||
$_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();
|
|
||||||
|
|
||||||
// load the theme parts
|
// load the theme parts
|
||||||
$_tracer->begin("Loading themelets");
|
require_all(_get_themelet_files(get_theme()));
|
||||||
foreach (_get_themelet_files(get_theme()) as $themelet) {
|
|
||||||
require_once $themelet;
|
|
||||||
}
|
|
||||||
unset($themelet);
|
|
||||||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||||
$_tracer->end();
|
|
||||||
|
|
||||||
// hook up event handlers
|
// hook up event handlers
|
||||||
$_tracer->begin("Loading event listeners");
|
|
||||||
_load_event_listeners();
|
_load_event_listeners();
|
||||||
$_tracer->end();
|
|
||||||
|
|
||||||
if (AUTO_DB_UPGRADE) {
|
if (AUTO_DB_UPGRADE) {
|
||||||
send_event(new DatabaseUpgradeEvent());
|
send_event(new DatabaseUpgradeEvent());
|
||||||
|
|
|
@ -92,10 +92,9 @@ function do_install()
|
||||||
}
|
}
|
||||||
|
|
||||||
define("CACHE_DSN", null);
|
define("CACHE_DSN", null);
|
||||||
define("DATABASE_KA", true);
|
|
||||||
try {
|
try {
|
||||||
create_dirs();
|
create_dirs();
|
||||||
create_tables(new Database());
|
create_tables(new Database(DATABASE_DSN));
|
||||||
write_config();
|
write_config();
|
||||||
} catch (InstallerException $e) {
|
} catch (InstallerException $e) {
|
||||||
print <<<EOD
|
print <<<EOD
|
||||||
|
|
|
@ -13,6 +13,8 @@ abstract class DatabaseDriver
|
||||||
*/
|
*/
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
|
/** @var string */
|
||||||
|
private $dsn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The PDO database connection object, for anyone who wants direct access.
|
* The PDO database connection object, for anyone who wants direct access.
|
||||||
|
@ -44,9 +46,13 @@ class Database
|
||||||
*/
|
*/
|
||||||
public $query_count = 0;
|
public $query_count = 0;
|
||||||
|
|
||||||
|
public function __construct(string $dsn) {
|
||||||
|
$this->dsn = $dsn;
|
||||||
|
}
|
||||||
|
|
||||||
private function connect_db(): void
|
private function connect_db(): void
|
||||||
{
|
{
|
||||||
$this->db = new PDO(DATABASE_DSN, [
|
$this->db = new PDO($this->dsn, [
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -469,6 +469,14 @@ function get_debug_info(): string
|
||||||
|
|
||||||
/** @privatesection */
|
/** @privatesection */
|
||||||
|
|
||||||
|
function require_all(array $files): void {
|
||||||
|
foreach ($files as $filename) {
|
||||||
|
if (basename($filename)[0] != "_") {
|
||||||
|
require_once $filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _version_check(): void
|
function _version_check(): void
|
||||||
{
|
{
|
||||||
if (MIN_PHP_VERSION) {
|
if (MIN_PHP_VERSION) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ if (!file_exists("vendor/")) {
|
||||||
<head>
|
<head>
|
||||||
<title>Shimmie Error</title>
|
<title>Shimmie Error</title>
|
||||||
<link rel="shortcut icon" href="ext/handle_static/static/favicon.ico">
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="installer">
|
<div id="installer">
|
||||||
|
|
|
@ -10,18 +10,6 @@ $_SERVER['QUERY_STRING'] = '/';
|
||||||
chdir(dirname(dirname(__FILE__)));
|
chdir(dirname(dirname(__FILE__)));
|
||||||
require_once "core/_bootstrap.php";
|
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
|
abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private $images = [];
|
private $images = [];
|
||||||
|
@ -35,6 +23,9 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
|
||||||
$this->markTestSkipped("$class not supported with this database");
|
$this->markTestSkipped("$class not supported with this database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->create_user("demo");
|
||||||
|
$this->create_user("test");
|
||||||
|
|
||||||
// things to do after bootstrap and before request
|
// things to do after bootstrap and before request
|
||||||
// log in as anon
|
// log in as anon
|
||||||
$this->log_out();
|
$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)
|
protected function get_page($page_name, $args=null)
|
||||||
{
|
{
|
||||||
// use a fresh page
|
// use a fresh page
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
define("DATABASE_DSN", null);
|
define("DATABASE_DSN", null);
|
||||||
define("DATABASE_KA", true);
|
|
||||||
define("DATABASE_TIMEOUT", 10000);
|
define("DATABASE_TIMEOUT", 10000);
|
||||||
define("CACHE_DSN", null);
|
define("CACHE_DSN", null);
|
||||||
define("DEBUG", false);
|
define("DEBUG", false);
|
||||||
|
|
Reference in a new issue