dropkicked phpunit out, no longer expose Application to Twig and also defines.
This commit is contained in:
parent
a3fb32f65a
commit
1fe9a4fd92
13 changed files with 120 additions and 1615 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@
|
|||
|
||||
# Configuration
|
||||
/config/config.ini
|
||||
/.debug
|
||||
|
||||
# Storage
|
||||
/store
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
"twig/extensions": "^1.5",
|
||||
"filp/whoops": "^2.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"database"
|
||||
|
|
1571
composer.lock
generated
1571
composer.lock
generated
File diff suppressed because it is too large
Load diff
44
misuzu.php
44
misuzu.php
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
define('MSZ_STARTUP', microtime(true));
|
||||
define('MSZ_DEBUG', file_exists(__DIR__ . '/.debug'));
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
mb_internal_encoding('UTF-8');
|
||||
|
||||
define('MSZ_DEBUG', file_exists(__DIR__ . '/vendor/phpunit/phpunit/composer.json'));
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
if (MSZ_DEBUG) {
|
||||
|
@ -41,10 +42,7 @@ require_once __DIR__ . '/src/Users/session.php';
|
|||
require_once __DIR__ . '/src/Users/user.php';
|
||||
require_once __DIR__ . '/src/Users/validation.php';
|
||||
|
||||
$app = new Application(
|
||||
__DIR__ . '/config/config.ini',
|
||||
MSZ_DEBUG
|
||||
);
|
||||
$app = new Application(__DIR__ . '/config/config.ini');
|
||||
$app->startDatabase();
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
|
@ -204,7 +202,7 @@ MIG;
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (!$app->inDebugMode()) {
|
||||
if (!MSZ_DEBUG) {
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
|
||||
|
@ -217,7 +215,37 @@ MIG;
|
|||
}
|
||||
|
||||
$app->startCache();
|
||||
$app->startTemplating();
|
||||
|
||||
tpl_init(['debug' => MSZ_DEBUG]);
|
||||
|
||||
tpl_var('globals', $app->getSiteInfo());
|
||||
|
||||
tpl_add_function('json_decode', true);
|
||||
tpl_add_function('byte_symbol', true);
|
||||
tpl_add_function('html_link', true);
|
||||
tpl_add_function('html_colour', true);
|
||||
tpl_add_function('url_construct', true);
|
||||
tpl_add_function('country_name', true, 'get_country_name');
|
||||
tpl_add_function('flip', true, 'array_flip');
|
||||
tpl_add_function('first_paragraph', true);
|
||||
tpl_add_function('colour_get_css', true);
|
||||
tpl_add_function('colour_get_css_contrast', true);
|
||||
tpl_add_function('colour_get_inherit', true);
|
||||
tpl_add_function('colour_get_red', true);
|
||||
tpl_add_function('colour_get_green', true);
|
||||
tpl_add_function('colour_get_blue', true);
|
||||
tpl_add_function('parse_line', true);
|
||||
tpl_add_function('parse_text', true);
|
||||
tpl_add_function('asset_url', true);
|
||||
tpl_add_function('vsprintf', true);
|
||||
tpl_add_function('perms_check', true);
|
||||
|
||||
tpl_add_function('git_commit_hash');
|
||||
tpl_add_function('git_branch');
|
||||
tpl_add_function('csrf_token', false, 'tmp_csrf_token');
|
||||
tpl_add_function('startup_time', false, function (float $time = MSZ_STARTUP) {
|
||||
return microtime(true) - $time;
|
||||
});
|
||||
|
||||
tpl_add_path(__DIR__ . '/templates');
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ if (!array_key_exists($settingsMode, $settingsModes)) {
|
|||
|
||||
$settingsErrors = [];
|
||||
|
||||
$disableAccountOptions = !$app->inDebugMode() && $app->disableRegistration();
|
||||
$disableAccountOptions = !MSZ_DEBUG && $app->disableRegistration();
|
||||
$avatarFileName = "{$app->getUserId()}.msz";
|
||||
$avatarProps = $app->getAvatarProps();
|
||||
$backgroundProps = $app->getBackgroundProps();
|
||||
|
|
|
@ -19,12 +19,6 @@ final class Application
|
|||
{
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Whether the application is in debug mode, this should only be set in the constructor and never altered.
|
||||
* @var bool
|
||||
*/
|
||||
private $debugMode = false;
|
||||
|
||||
/**
|
||||
* Array of database connection names, first in the list is assumed to be the default.
|
||||
*/
|
||||
|
@ -52,32 +46,22 @@ final class Application
|
|||
|
||||
private $config = [];
|
||||
|
||||
/**
|
||||
* TemplatingEngine instance.
|
||||
* @var \Misuzu\TemplateEngine
|
||||
*/
|
||||
private $templatingInstance = null;
|
||||
|
||||
private $mailerInstance = null;
|
||||
|
||||
private $geoipInstance = null;
|
||||
|
||||
private $startupTime = 0;
|
||||
|
||||
/**
|
||||
* Constructor, called by ApplicationBase::start() which also passes the arguments through.
|
||||
* @param null|string $configFile
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct(?string $configFile = null, bool $debug = false)
|
||||
public function __construct(?string $configFile = null)
|
||||
{
|
||||
if (!empty(self::$instance)) {
|
||||
throw new UnexpectedValueException('An Application has already been set up.');
|
||||
}
|
||||
|
||||
self::$instance = $this;
|
||||
$this->startupTime = microtime(true);
|
||||
$this->debugMode = $debug;
|
||||
$this->config = is_file($configFile) ? parse_ini_file($configFile, true, INI_SCANNER_TYPED) : [];
|
||||
|
||||
if ($this->config === false) {
|
||||
|
@ -85,7 +69,7 @@ final class Application
|
|||
}
|
||||
|
||||
// only use this error handler in prod mode, dev uses Whoops now
|
||||
if (!$debug) {
|
||||
if (!MSZ_DEBUG) {
|
||||
ExceptionHandler::register(
|
||||
false,
|
||||
$this->config['Exceptions']['report_url'] ?? null,
|
||||
|
@ -94,20 +78,6 @@ final class Application
|
|||
}
|
||||
}
|
||||
|
||||
public function getTimeSinceStart(): float
|
||||
{
|
||||
return microtime(true) - $this->startupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether we're in debug mode or not.
|
||||
* @return bool
|
||||
*/
|
||||
public function inDebugMode(): bool
|
||||
{
|
||||
return $this->debugMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a storage path.
|
||||
* @param string $path
|
||||
|
@ -224,53 +194,6 @@ final class Application
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the templating engine module.
|
||||
*/
|
||||
public function startTemplating(): void
|
||||
{
|
||||
if (!is_null($this->templatingInstance)) {
|
||||
throw new UnexpectedValueException('Templating module has already been started.');
|
||||
}
|
||||
|
||||
tpl_init([
|
||||
'debug' => $this->debugMode,
|
||||
]);
|
||||
|
||||
tpl_var('globals', [
|
||||
'site_name' => $this->config['Site']['name'] ?? 'Flashii',
|
||||
'site_description' => $this->config['Site']['description'] ?? '',
|
||||
'site_twitter' => $this->config['Site']['twitter'] ?? '',
|
||||
'site_url' => $this->config['Site']['url'] ?? '',
|
||||
]);
|
||||
|
||||
tpl_add_function('json_decode', true);
|
||||
tpl_add_function('byte_symbol', true);
|
||||
tpl_add_function('html_link', true);
|
||||
tpl_add_function('html_colour', true);
|
||||
tpl_add_function('url_construct', true);
|
||||
tpl_add_function('country_name', true, 'get_country_name');
|
||||
tpl_add_function('flip', true, 'array_flip');
|
||||
tpl_add_function('first_paragraph', true);
|
||||
tpl_add_function('colour_get_css', true);
|
||||
tpl_add_function('colour_get_css_contrast', true);
|
||||
tpl_add_function('colour_get_inherit', true);
|
||||
tpl_add_function('colour_get_red', true);
|
||||
tpl_add_function('colour_get_green', true);
|
||||
tpl_add_function('colour_get_blue', true);
|
||||
tpl_add_function('parse_line', true);
|
||||
tpl_add_function('parse_text', true);
|
||||
tpl_add_function('asset_url', true);
|
||||
tpl_add_function('vsprintf', true);
|
||||
tpl_add_function('perms_check', true);
|
||||
|
||||
tpl_add_function('git_commit_hash');
|
||||
tpl_add_function('git_branch');
|
||||
tpl_add_function('csrf_token', false, 'tmp_csrf_token');
|
||||
|
||||
tpl_var('app', $this);
|
||||
}
|
||||
|
||||
public function startMailer(): void
|
||||
{
|
||||
if (!empty($this->mailerInstance)) {
|
||||
|
@ -403,6 +326,16 @@ final class Application
|
|||
];
|
||||
}
|
||||
|
||||
public function getSiteInfo(): array
|
||||
{
|
||||
return [
|
||||
'site_name' => $this->config['Site']['name'] ?? 'Flashii',
|
||||
'site_description' => $this->config['Site']['description'] ?? '',
|
||||
'site_twitter' => $this->config['Site']['twitter'] ?? '',
|
||||
'site_url' => $this->config['Site']['url'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultAvatar(): string
|
||||
{
|
||||
return $this->getPath($this->config['Avatar']['default_path'] ?? 'public/images/no-avatar.png');
|
||||
|
|
|
@ -76,5 +76,9 @@ function tpl_render(string $path, array $vars = []): string
|
|||
tpl_vars($vars);
|
||||
}
|
||||
|
||||
if (!defined('MSZ_TPL_RENDER')) {
|
||||
define('MSZ_TPL_RENDER', microtime(true));
|
||||
}
|
||||
|
||||
return $twig->render($path, $GLOBALS[MSZ_TPL_VARS_STORE]);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{{ globals.site_name }}
|
||||
</a>
|
||||
|
||||
<label style="background-image:url('/profile.php?u={{ app.hasActiveSession ? current_user.user_id : 0 }}&m=avatar');"
|
||||
<label style="background-image:url('/profile.php?u={{ current_user.user_id|default(0) }}&m=avatar');"
|
||||
class="avatar header__icon header__icon--user"
|
||||
for="toggle-mobile-header-user"></label>
|
||||
</div>
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
<input type="checkbox" class="header__user-toggle" id="toggle-mobile-header-user">
|
||||
<div class="header__user">
|
||||
{% if app.hasActiveSession %}
|
||||
{% if current_user is defined %}
|
||||
<a href="/profile.php?u={{ current_user.user_id }}"
|
||||
class="avatar header__user__avatar"
|
||||
style="background-image:url('/profile.php?u={{ current_user.user_id }}&m=avatar');"></a>
|
||||
|
@ -49,7 +49,7 @@
|
|||
{% endif %}
|
||||
|
||||
<div class="header__user__info">
|
||||
{% if app.hasActiveSession %}
|
||||
{% if current_user is defined %}
|
||||
<a href="/profile.php?u={{ current_user.user_id }}"
|
||||
class="header__user__name"
|
||||
style="{{ current_user.user_colour|html_colour({
|
||||
|
@ -66,7 +66,7 @@
|
|||
{% endif %}
|
||||
|
||||
<ul class="header__user__actions">
|
||||
{% if app.hasActiveSession %}
|
||||
{% if current_user is defined %}
|
||||
<li class="header__user__action">
|
||||
<a class="header__user__link" href="/profile.php?u={{ current_user.user_id }}">Profile</a>
|
||||
</li>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if forum_info.forum_type == 0 %}
|
||||
{% set fcbuttons = app.hasActiveSession ? forum_category_buttons(forum_info, forum_perms) : '' %}
|
||||
{% set fcbuttons = current_user is defined ? forum_category_buttons(forum_info, forum_perms) : '' %}
|
||||
{% set fcpagination = pagination(
|
||||
forum_info.forum_topic_count,
|
||||
forum_range,
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
'o': topic_offset,
|
||||
}) %}
|
||||
|
||||
{% set can_reply = app.hasActiveSession and topic_info.topic_locked is null and not topic_info.topic_archived %}
|
||||
{% set can_reply = current_user is defined and topic_info.topic_locked is null and not topic_info.topic_archived %}
|
||||
{% set ftbuttons = can_reply ? forum_topic_buttons(topic_info) : '' %}
|
||||
{% set ftpagination = pagination(
|
||||
topic_info.topic_post_count,
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</div>
|
||||
|
||||
<div class="index__main">
|
||||
{% if app.hasActiveSession %}
|
||||
{% if current_user is defined %}
|
||||
<div class="container">
|
||||
<div class="container__title">Welcome</div>
|
||||
<div class="container__content">
|
||||
|
|
|
@ -48,7 +48,8 @@
|
|||
# {{ ('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true))|html_link(git_commit_hash(), 'footer__link') }}
|
||||
{% if query_count is defined %}
|
||||
/ SQL Queries: {{ query_count|number_format }}
|
||||
/ Took: {{ app.timeSinceStart|number_format(5) }} seconds
|
||||
/ Took: {{ startup_time()|number_format(5) }} seconds
|
||||
/ Render: {{ startup_time(constant('MSZ_TPL_RENDER'))|number_format(5) }} seconds
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endautoescape %}
|
||||
|
|
|
@ -167,7 +167,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if app.hasActiveSession %}
|
||||
{% if current_user is defined %}
|
||||
{% spaceless %}
|
||||
<div class="profile__info__section">
|
||||
<div class="profile__info__block profile__info__block--links">
|
||||
|
|
Loading…
Add table
Reference in a new issue