diff --git a/.env.develop b/.env.develop index f6a431d..07b491f 100644 --- a/.env.develop +++ b/.env.develop @@ -10,7 +10,6 @@ MYSQL_USER=mailaccountadmin MYSQL_PASSWORD=mailaccountadmin # App settings -APP_TITLE="MailAccountAdmin [dev]" APP_ENV=development APP_DEBUG=true APP_TIMEZONE=Europe/Berlin diff --git a/.gitignore b/.gitignore index 37cecc0..646c542 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,5 @@ # PHP /.composer /.phpunit.cache -/.twig.cache /coverage /vendor - -# Production settings -/config/app.yml diff --git a/Dockerfile b/Dockerfile index 89effb8..9f9d176 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,8 @@ FROM php:7.4-apache AS base WORKDIR /var/www RUN apt-get update && \ - apt-get install -y git unzip libyaml-dev libzip-dev && \ - docker-php-ext-install pdo pdo_mysql zip && \ - pecl install yaml && \ - docker-php-ext-enable yaml + apt-get install -y libzip-dev unzip git && \ + docker-php-ext-install pdo pdo_mysql zip RUN a2enmod rewrite && \ sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf diff --git a/TODO.md b/TODO.md index 4697f74..2226cf1 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,7 @@ ## General +- Settings from a config file - Database migrations - Documentation - App deployment @@ -11,7 +12,6 @@ - Refactor auth and session handling ## Admin user management - - Create/edit/delete admins - Change own password diff --git a/composer.json b/composer.json index aa59362..93dcd53 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,6 @@ "require": { "php": "^7.4", "ext-pdo": "*", - "ext-yaml": "*", "slim/slim": "^4.8", "slim/psr7": "^1.3", "php-di/php-di": "^6.3", diff --git a/config/app.develop.yml b/config/app.develop.yml deleted file mode 100644 index 923ceb4..0000000 --- a/config/app.develop.yml +++ /dev/null @@ -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 diff --git a/config/app.example.yml b/config/app.example.yml deleted file mode 100644 index 2683c29..0000000 --- a/config/app.example.yml +++ /dev/null @@ -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 diff --git a/public/index.php b/public/index.php index c918330..0de28b3 100644 --- a/public/index.php +++ b/public/index.php @@ -9,11 +9,9 @@ use MailAccountAdmin\Middlewares; use MailAccountAdmin\Routes; use Slim\Factory\AppFactory; -const ROOT_DIR = __DIR__ . '/..'; - session_start(); -// Load application config (from config file or environment variables) +// Load application config (from environment or config file) $configLoader = new AutoConfigLoader(); $config = $configLoader->loadConfig(); diff --git a/src/Config/AppConfig.php b/src/Config/AppConfig.php index ce94e39..4735a10 100644 --- a/src/Config/AppConfig.php +++ b/src/Config/AppConfig.php @@ -70,23 +70,10 @@ class AppConfig 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 { return [ - 'cache' => $this->getTwigCacheDir() ?: false, + 'cache' => $this->twigCacheDir ?: false, 'debug' => $this->isDebugMode(), 'strict_variables' => $this->isDebugMode(), ]; diff --git a/src/Config/Loaders/AutoConfigLoader.php b/src/Config/Loaders/AutoConfigLoader.php index 6ba336c..4090b93 100644 --- a/src/Config/Loaders/AutoConfigLoader.php +++ b/src/Config/Loaders/AutoConfigLoader.php @@ -11,14 +11,9 @@ class AutoConfigLoader implements ConfigLoaderInterface public function __construct() { - $yamlFilePath = ROOT_DIR . '/config/app.yml'; - - // Check if yml config file exists - if (file_exists($yamlFilePath)) { - $this->configLoader = new YamlConfigLoader($yamlFilePath); - } else { - $this->configLoader = new EnvConfigLoader(); - } + // TODO determine configloader + // (first check if yml file exists, fallback to env?) + $this->configLoader = new EnvConfigLoader(); } public function loadConfig(): AppConfig diff --git a/src/Config/Loaders/YamlConfigLoader.php b/src/Config/Loaders/YamlConfigLoader.php index c4370d3..ee25fbd 100644 --- a/src/Config/Loaders/YamlConfigLoader.php +++ b/src/Config/Loaders/YamlConfigLoader.php @@ -11,38 +11,15 @@ class YamlConfigLoader implements ConfigLoaderInterface public function __construct(string $filePath) { - assert(file_exists($filePath)); - $this->filePath = $filePath; } public function loadConfig(): AppConfig { - // Parse yml config file - $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'])); + // TODO implement return AppConfig::createFromArray([ - // App settings - '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, + // TODO ]); } } diff --git a/templates/base.html.twig b/templates/base.html.twig index bd0d091..c364b6d 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -12,11 +12,7 @@

{{ app_info.getTitle() }}

- {% if logged_in | default() %} - {{ app_info.getVersion() }} - {% else %} - {{ app_info.getVersion() }} - {% endif %} + {{ app_info.getVersion() }}