Low-level refactor to core.php

This commit is contained in:
Marcin Kurczewski 2013-11-17 13:02:41 +01:00
parent 4166200dbc
commit 7b473ba06f
7 changed files with 14 additions and 44 deletions

View file

@ -1,5 +1,4 @@
[chibi] [chibi]
userCodeDir=./src/
prettyPrint=1 prettyPrint=1
[main] [main]

@ -1 +1 @@
Subproject commit 0ec5cbda4b34f6273e2e02196cf6c16379623bb3 Subproject commit bf824e781c520a85a82394622a5fefd5c178379f

View file

@ -1,7 +1,6 @@
<?php <?php
chdir('..'); chdir('..');
require_once 'src/core.php'; require_once 'src/core.php';
require_once 'src/Bootstrap.php';
$query = $_SERVER['REQUEST_URI']; $query = $_SERVER['REQUEST_URI'];
\Chibi\Facade::run($query, configFactory(), new Bootstrap()); \Chibi\Facade::run($query, new Bootstrap());

View file

@ -1,6 +1,5 @@
<?php <?php
require_once __DIR__ . '/../src/core.php'; require_once __DIR__ . '/../src/core.php';
\Chibi\Registry::setConfig(configFactory());
function usage() function usage()
{ {

View file

@ -1,5 +1,6 @@
<?php <?php
require_once __DIR__ . '/../src/core.php'; require_once __DIR__ . '/../src/core.php';
$config = \Chibi\Registry::getConfig();
function usage() function usage()
{ {
@ -30,23 +31,23 @@ switch ($action)
mkdir($dir, 0755, true); mkdir($dir, 0755, true);
if (!is_dir($dir)) if (!is_dir($dir))
die($dir . ' is not a dir' . PHP_EOL); die($dir . ' is not a dir' . PHP_EOL);
$func = function($name) use ($dir) $func = function($name) use ($dir, $config)
{ {
echo $name . PHP_EOL; echo $name . PHP_EOL;
static $filesPath = null; static $filesPath = null;
if ($filesPath == null) if ($filesPath == null)
$filesPath = configFactory()->main->filesPath; $filesPath = $config->main->filesPath;
rename($filesPath . DS . $name, $dir . DS . $name); rename($filesPath . DS . $name, $dir . DS . $name);
}; };
break; break;
case '-purge': case '-purge':
$func = function($name) use ($dir) $func = function($name) use ($dir, $config)
{ {
echo $name . PHP_EOL; echo $name . PHP_EOL;
static $filesPath = null; static $filesPath = null;
if ($filesPath == null) if ($filesPath == null)
$filesPath = configFactory()->main->filesPath; $filesPath = $config->main->filesPath;
unlink($filesPath . DS . $name); unlink($filesPath . DS . $name);
}; };
break; break;
@ -62,7 +63,6 @@ foreach (R::findAll('post') as $post)
} }
$names = array_flip($names); $names = array_flip($names);
$config = configFactory();
$filesPath = $config->main->filesPath; $filesPath = $config->main->filesPath;
foreach (glob($filesPath . DS . '*') as $name) foreach (glob($filesPath . DS . '*') as $name)
{ {

View file

@ -96,7 +96,7 @@
<footer> <footer>
<div class="main-wrapper"> <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> <span>Queries: <?php echo count(queryLogger()->getLogs()) ?></span>
<?php if ($this->config->misc->debugQueries): ?> <?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> <pre class="debug"><?php echo join('<br>', array_map(function($x) { return preg_replace('/\s+/', ' ', $x); }, queryLogger()->getLogs())) ?></pre>

View file

@ -2,14 +2,7 @@
define('SZURU_VERSION', '0.3.0'); define('SZURU_VERSION', '0.3.0');
define('SZURU_LINK', 'http://github.com/rr-/szurubooru'); define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
function trueStartTime() $startTime = microtime(true);
{
static $time = null;
if ($time === null)
$time = microtime(true);
return $time;
}
trueStartTime();
$requiredExtensions = ['pdo', 'pdo_sqlite', 'gd', 'openssl']; $requiredExtensions = ['pdo', 'pdo_sqlite', 'gd', 'openssl'];
foreach ($requiredExtensions as $ext) 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/php-markdown/Michelf/Markdown.php';
require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php'; require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php';
require_once __DIR__ . '/../lib/chibi-core/Facade.php'; require_once __DIR__ . '/../lib/chibi-core/Facade.php';
require_once __DIR__ . '/../lib/chibi-core/Registry.php';
function configFactory() \Chibi\AutoLoader::init(__DIR__);
{ \Chibi\Facade::init();
static $config = null; $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::setup('sqlite:' . $config->main->dbPath);
R::freeze(true); R::freeze(true);
R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]); R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]);
//wire models //wire models
\Chibi\AutoLoader::init([__DIR__ . '/../' . $config->chibi->userCodeDir, __DIR__]);
foreach (\Chibi\AutoLoader::getAllIncludablePaths() as $path) foreach (\Chibi\AutoLoader::getAllIncludablePaths() as $path)
if (preg_match('/Model/', $path)) if (preg_match('/Model/', $path))
\Chibi\AutoLoader::safeInclude($path); \Chibi\AutoLoader::safeInclude($path);