Compare commits

..

1 Commits

Author SHA1 Message Date
Lexi / Zoe 60066746ff
[WIP] 2021-09-24 20:45:36 +02:00
12 changed files with 11 additions and 108 deletions

View File

@ -10,7 +10,6 @@ MYSQL_USER=mailaccountadmin
MYSQL_PASSWORD=mailaccountadmin MYSQL_PASSWORD=mailaccountadmin
# App settings # App settings
APP_TITLE="MailAccountAdmin [dev]"
APP_ENV=development APP_ENV=development
APP_DEBUG=true APP_DEBUG=true
APP_TIMEZONE=Europe/Berlin APP_TIMEZONE=Europe/Berlin

4
.gitignore vendored
View File

@ -10,9 +10,5 @@
# PHP # PHP
/.composer /.composer
/.phpunit.cache /.phpunit.cache
/.twig.cache
/coverage /coverage
/vendor /vendor
# Production settings
/config/app.yml

View File

@ -3,10 +3,8 @@ FROM php:7.4-apache AS base
WORKDIR /var/www WORKDIR /var/www
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y git unzip libyaml-dev libzip-dev && \ apt-get install -y libzip-dev unzip git && \
docker-php-ext-install pdo pdo_mysql zip && \ docker-php-ext-install pdo pdo_mysql zip
pecl install yaml && \
docker-php-ext-enable yaml
RUN a2enmod rewrite && \ RUN a2enmod rewrite && \
sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf

View File

@ -4,6 +4,7 @@
## General ## General
- Settings from a config file
- Database migrations - Database migrations
- Documentation - Documentation
- App deployment - App deployment
@ -11,7 +12,6 @@
- Refactor auth and session handling - Refactor auth and session handling
## Admin user management ## Admin user management
- Create/edit/delete admins - Create/edit/delete admins
- Change own password - Change own password

View File

@ -14,7 +14,6 @@
"require": { "require": {
"php": "^7.4", "php": "^7.4",
"ext-pdo": "*", "ext-pdo": "*",
"ext-yaml": "*",
"slim/slim": "^4.8", "slim/slim": "^4.8",
"slim/psr7": "^1.3", "slim/psr7": "^1.3",
"php-di/php-di": "^6.3", "php-di/php-di": "^6.3",

View File

@ -1,19 +0,0 @@
# Config file for local development (same settings as .env.develop)
# -- App settings
appTitle: "MailAccountAdmin [dev]"
environment: development
debug: true
timezone: Europe/Berlin
# -- Twig settings
twig:
cacheDir:
# -- Database settings
database:
host: db
port: 3306
name: mailusers
username: mailaccountadmin
password: mailaccountadmin

View File

@ -1,23 +0,0 @@
# This is an example config file for MailAccountAdmin.
# Copy this file to /config/app.yml and change as needed.
# Settings that are commented out represent the default values.
# -- App settings
# appTitle: MailAccountAdmin
# environment: production
# debug: false
# timezone: UTC
# dateTimeFormat: r
# -- Twig settings
twig:
# Cache directory for Twig templates (default: unset, which means no cache is used)
cacheDir: .twig.cache
# -- Database settings
database:
host: localhost
port: 3306
name: mailusers
username: mailaccountadmin
password: very_secret_password

View File

@ -9,11 +9,9 @@ use MailAccountAdmin\Middlewares;
use MailAccountAdmin\Routes; use MailAccountAdmin\Routes;
use Slim\Factory\AppFactory; use Slim\Factory\AppFactory;
const ROOT_DIR = __DIR__ . '/..';
session_start(); session_start();
// Load application config (from config file or environment variables) // Load application config (from environment or config file)
$configLoader = new AutoConfigLoader(); $configLoader = new AutoConfigLoader();
$config = $configLoader->loadConfig(); $config = $configLoader->loadConfig();

View File

@ -70,23 +70,10 @@ class AppConfig
return $this->dateTimeFormat; return $this->dateTimeFormat;
} }
public function getTwigCacheDir(): ?string
{
if (empty($this->twigCacheDir)) {
return null;
} elseif (substr($this->twigCacheDir, 0, 1) === '/') {
// Absolute path
return $this->twigCacheDir;
} else {
// Relative path
return ROOT_DIR . '/' . $this->twigCacheDir;
}
}
public function getTwigSettings(): array public function getTwigSettings(): array
{ {
return [ return [
'cache' => $this->getTwigCacheDir() ?: false, 'cache' => $this->twigCacheDir ?: false,
'debug' => $this->isDebugMode(), 'debug' => $this->isDebugMode(),
'strict_variables' => $this->isDebugMode(), 'strict_variables' => $this->isDebugMode(),
]; ];

View File

@ -11,15 +11,10 @@ class AutoConfigLoader implements ConfigLoaderInterface
public function __construct() public function __construct()
{ {
$yamlFilePath = ROOT_DIR . '/config/app.yml'; // TODO determine configloader
// (first check if yml file exists, fallback to env?)
// Check if yml config file exists
if (file_exists($yamlFilePath)) {
$this->configLoader = new YamlConfigLoader($yamlFilePath);
} else {
$this->configLoader = new EnvConfigLoader(); $this->configLoader = new EnvConfigLoader();
} }
}
public function loadConfig(): AppConfig public function loadConfig(): AppConfig
{ {

View File

@ -11,38 +11,15 @@ class YamlConfigLoader implements ConfigLoaderInterface
public function __construct(string $filePath) public function __construct(string $filePath)
{ {
assert(file_exists($filePath));
$this->filePath = $filePath; $this->filePath = $filePath;
} }
public function loadConfig(): AppConfig public function loadConfig(): AppConfig
{ {
// Parse yml config file // TODO implement
$parsedConfig = yaml_parse_file($this->filePath);
// Check datatypes
assert(is_array($parsedConfig));
assert(!isset($parsedConfig['twig']) || is_array($parsedConfig['twig']));
assert(!isset($parsedConfig['database']) || is_array($parsedConfig['database']));
return AppConfig::createFromArray([ return AppConfig::createFromArray([
// App settings // TODO
'appTitle' => $parsedConfig['appTitle'] ?? null,
'environment' => $parsedConfig['environment'] ?? null,
'debug' => (bool)$parsedConfig['debug'] ?? null,
'timezone' => $parsedConfig['timezone'] ?? null,
'dateTimeFormat' => $parsedConfig['dateTimeFormat'] ?? null,
// Twig settings
'twigCacheDir' => $parsedConfig['twig']['cacheDir'] ?? null,
// Database settings
'databaseHost' => $parsedConfig['database']['host'] ?? null,
'databasePort' => (int)$parsedConfig['database']['port'] ?? null,
'databaseName' => $parsedConfig['database']['name'] ?? null,
'databaseUsername' => $parsedConfig['database']['username'] ?? null,
'databasePassword' => $parsedConfig['database']['password'] ?? null,
]); ]);
} }
} }

View File

@ -12,11 +12,7 @@
<header> <header>
<h1>{{ app_info.getTitle() }}</h1> <h1>{{ app_info.getTitle() }}</h1>
<div class="header_appversion"> <div class="header_appversion">
{% if logged_in | default() %}
<a href="{{ app_info.getRepositoryUrl() }}">{{ app_info.getVersion() }}</a> <a href="{{ app_info.getRepositoryUrl() }}">{{ app_info.getVersion() }}</a>
{% else %}
{{ app_info.getVersion() }}
{% endif %}
</div> </div>
<div class="header_spacer"></div> <div class="header_spacer"></div>
<div class="header_userstatus"> <div class="header_userstatus">