Low-level refactor to core.php
This commit is contained in:
parent
4166200dbc
commit
7b473ba06f
7 changed files with 14 additions and 44 deletions
|
@ -1,5 +1,4 @@
|
|||
[chibi]
|
||||
userCodeDir=./src/
|
||||
prettyPrint=1
|
||||
|
||||
[main]
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0ec5cbda4b34f6273e2e02196cf6c16379623bb3
|
||||
Subproject commit bf824e781c520a85a82394622a5fefd5c178379f
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
chdir('..');
|
||||
require_once 'src/core.php';
|
||||
require_once 'src/Bootstrap.php';
|
||||
|
||||
$query = $_SERVER['REQUEST_URI'];
|
||||
\Chibi\Facade::run($query, configFactory(), new Bootstrap());
|
||||
\Chibi\Facade::run($query, new Bootstrap());
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../src/core.php';
|
||||
\Chibi\Registry::setConfig(configFactory());
|
||||
|
||||
function usage()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../src/core.php';
|
||||
$config = \Chibi\Registry::getConfig();
|
||||
|
||||
function usage()
|
||||
{
|
||||
|
@ -30,23 +31,23 @@ switch ($action)
|
|||
mkdir($dir, 0755, true);
|
||||
if (!is_dir($dir))
|
||||
die($dir . ' is not a dir' . PHP_EOL);
|
||||
$func = function($name) use ($dir)
|
||||
$func = function($name) use ($dir, $config)
|
||||
{
|
||||
echo $name . PHP_EOL;
|
||||
static $filesPath = null;
|
||||
if ($filesPath == null)
|
||||
$filesPath = configFactory()->main->filesPath;
|
||||
$filesPath = $config->main->filesPath;
|
||||
rename($filesPath . DS . $name, $dir . DS . $name);
|
||||
};
|
||||
break;
|
||||
|
||||
case '-purge':
|
||||
$func = function($name) use ($dir)
|
||||
$func = function($name) use ($dir, $config)
|
||||
{
|
||||
echo $name . PHP_EOL;
|
||||
static $filesPath = null;
|
||||
if ($filesPath == null)
|
||||
$filesPath = configFactory()->main->filesPath;
|
||||
$filesPath = $config->main->filesPath;
|
||||
unlink($filesPath . DS . $name);
|
||||
};
|
||||
break;
|
||||
|
@ -62,7 +63,6 @@ foreach (R::findAll('post') as $post)
|
|||
}
|
||||
$names = array_flip($names);
|
||||
|
||||
$config = configFactory();
|
||||
$filesPath = $config->main->filesPath;
|
||||
foreach (glob($filesPath . DS . '*') as $name)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
<footer>
|
||||
<div class="main-wrapper">
|
||||
<span>Load: <?php echo sprintf('%.05f', microtime(true) - trueStartTime()) ?>s</span>
|
||||
<span>Load: <?php echo sprintf('%.05f', microtime(true) - $this->context->startTime) ?>s</span>
|
||||
<span>Queries: <?php echo count(queryLogger()->getLogs()) ?></span>
|
||||
<?php if ($this->config->misc->debugQueries): ?>
|
||||
<pre class="debug"><?php echo join('<br>', array_map(function($x) { return preg_replace('/\s+/', ' ', $x); }, queryLogger()->getLogs())) ?></pre>
|
||||
|
|
39
src/core.php
39
src/core.php
|
@ -2,14 +2,7 @@
|
|||
define('SZURU_VERSION', '0.3.0');
|
||||
define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
|
||||
|
||||
function trueStartTime()
|
||||
{
|
||||
static $time = null;
|
||||
if ($time === null)
|
||||
$time = microtime(true);
|
||||
return $time;
|
||||
}
|
||||
trueStartTime();
|
||||
$startTime = microtime(true);
|
||||
|
||||
$requiredExtensions = ['pdo', 'pdo_sqlite', 'gd', 'openssl'];
|
||||
foreach ($requiredExtensions as $ext)
|
||||
|
@ -24,38 +17,18 @@ define('DS', DIRECTORY_SEPARATOR);
|
|||
require_once __DIR__ . '/../lib/php-markdown/Michelf/Markdown.php';
|
||||
require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php';
|
||||
require_once __DIR__ . '/../lib/chibi-core/Facade.php';
|
||||
require_once __DIR__ . '/../lib/chibi-core/Registry.php';
|
||||
|
||||
function configFactory()
|
||||
{
|
||||
static $config = null;
|
||||
\Chibi\AutoLoader::init(__DIR__);
|
||||
\Chibi\Facade::init();
|
||||
$config = \Chibi\Registry::getConfig();
|
||||
$context = \Chibi\Registry::getContext();
|
||||
$context->startTime = $startTime;
|
||||
|
||||
if ($config === null)
|
||||
{
|
||||
$config = new \Chibi\Config();
|
||||
$configPaths =
|
||||
[
|
||||
__DIR__ . DS . '../config.ini',
|
||||
__DIR__ . DS . '../local.ini',
|
||||
];
|
||||
$configPaths = array_filter($configPaths, 'file_exists');
|
||||
|
||||
foreach ($configPaths as $path)
|
||||
{
|
||||
$config->loadIni($path);
|
||||
}
|
||||
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
$config = configFactory();
|
||||
R::setup('sqlite:' . $config->main->dbPath);
|
||||
R::freeze(true);
|
||||
R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]);
|
||||
|
||||
//wire models
|
||||
\Chibi\AutoLoader::init([__DIR__ . '/../' . $config->chibi->userCodeDir, __DIR__]);
|
||||
foreach (\Chibi\AutoLoader::getAllIncludablePaths() as $path)
|
||||
if (preg_match('/Model/', $path))
|
||||
\Chibi\AutoLoader::safeInclude($path);
|
||||
|
|
Loading…
Reference in a new issue