diff --git a/.gitignore b/.gitignore index 71bcd31..646c542 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # General /tmp /_tmp +/VERSION # PHP /.composer diff --git a/Dockerfile b/Dockerfile index eae1737..695e69b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini && \ pecl install xdebug && \ docker-php-ext-enable xdebug +ENV APP_ENV=development # TODO: production image untested #FROM base AS production diff --git a/Makefile b/Makefile index 54b343a..f0ffbb1 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ DOCKER_RUN = $(DOCKER_COMPOSE) run --rm app COMPOSER = $(DOCKER_RUN) composer PHPUNIT = $(DOCKER_RUN) vendor/bin/phpunit -.PHONY: all clean \ +.PHONY: all clean VERSION \ docker-up docker-up-detached docker-down docker-restart docker-build docker-rebuild docker-purge docker-logs docker-run \ composer-install composer-install-no-dev composer-update composer-cmd \ test phpunit open-coverage @@ -94,9 +94,17 @@ open-coverage: $(or $(BROWSER),firefox) coverage/index.html +# Version management +# ------------------ + +# Create VERSION file from current git tag +version: + git describe | tee VERSION + + # Clean up # -------- # Remove vendor directory, phpunit caches and other files that have been generated clean: docker-down - rm -rf .composer vendor .phpunit.cache coverage + rm -rf .composer vendor .phpunit.cache coverage VERSION diff --git a/public/static/style.css b/public/static/style.css index 61cb271..3806bf2 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -57,15 +57,32 @@ header { margin: 1rem; padding: 0 1rem; display: flex; + flex-flow: row wrap; justify-content: space-between; align-content: center; - align-items: center; + align-items: baseline; } -header h1 { +header > * { margin: 1rem; } +header > .header_appversion { + font-size: 0.75rem; + color: #767676; +} + +header > .header_appversion > a { + color: inherit; +} + +header > .header_spacer { + width: 0; + margin: 0; + padding: 0; + flex: 1 0 0; +} + /* -- Navigation bar -- */ nav { } diff --git a/src/AppInfo.php b/src/AppInfo.php new file mode 100644 index 0000000..42c14a4 --- /dev/null +++ b/src/AppInfo.php @@ -0,0 +1,33 @@ +title = $title; + $this->version = $version; + } + + public function getTitle(): string + { + return $this->title; + } + + public function getVersion(): string + { + return $this->version; + } + + public function getRepositoryUrl(): string + { + return self::REPOSITORY_URL; + } +} diff --git a/src/Dependencies.php b/src/Dependencies.php index 53d21f1..94c0d64 100644 --- a/src/Dependencies.php +++ b/src/Dependencies.php @@ -35,6 +35,18 @@ class Dependencies // App settings $container->set(self::SETTINGS, $settings); + // App information + $container->set(AppInfo::class, function (ContainerInterface $c) { + /** @var Settings $settings */ + $settings = $c->get(self::SETTINGS); + $versionHelper = new VersionHelper(); + + return new AppInfo( + $settings->getAppTitle(), + $versionHelper->getAppVersion(), + ); + }); + // Twig template engine $container->set(self::TWIG, function (ContainerInterface $c) { /** @var Settings $settings */ @@ -49,6 +61,10 @@ class Dependencies $coreExtension->setDateFormat($settings->getDateFormat()); $coreExtension->setTimezone($settings->getTimezone()); + // Add app information to globals + $appInfo = $c->get(AppInfo::class); + $twig->getEnvironment()->addGlobal('app_info', $appInfo); + // Return Twig view return $twig; }); diff --git a/src/Frontend/BaseController.php b/src/Frontend/BaseController.php index eadc069..56f115f 100644 --- a/src/Frontend/BaseController.php +++ b/src/Frontend/BaseController.php @@ -21,6 +21,7 @@ class BaseController // Register globals $twigEnv = $view->getEnvironment(); + $twigEnv->addGlobal('logged_in', $userHelper->isLoggedIn()); $twigEnv->addGlobal('current_user_name', $userHelper->isLoggedIn() ? $userHelper->getCurrentUser()->getUsername() : null); } diff --git a/src/Settings.php b/src/Settings.php index 1aecf4b..4d1b989 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -5,6 +5,11 @@ namespace MailAccountAdmin; class Settings { + public function getAppTitle(): string + { + return getenv('APP_TITLE') ?: 'MailAccountAdmin'; + } + public function isDebugMode(): bool { return getenv('APP_DEBUG') === 'true'; diff --git a/src/VersionHelper.php b/src/VersionHelper.php new file mode 100644 index 0000000..4fd370a --- /dev/null +++ b/src/VersionHelper.php @@ -0,0 +1,42 @@ +loadFromVersionFile(); + if (!empty($version)) { + $this->version = $version; + } elseif ($this->inDevelopmentMode()) { + $this->version = '[dev version]'; + } else { + $this->version = '[undefined version]'; + } + } + + public function getAppVersion(): string + { + return $this->version; + } + + private function loadFromVersionFile(): ?string + { + $versionFilePath = __DIR__ . '/../VERSION'; + + if (file_exists($versionFilePath)) { + $fileContent = file($versionFilePath); + return $fileContent[0] ?? null; + } + return null; + } + + private function inDevelopmentMode(): bool + { + return getenv('APP_ENV') === 'development'; + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index 852e9ff..c364b6d 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -2,7 +2,7 @@ - {% block title %}Untitled page{% endblock %} - MailAccountAdmin + {% block title %}Untitled page{% endblock %} - {{ app_info.getTitle() }} @@ -10,27 +10,37 @@
-

MailAccountAdmin

+

{{ app_info.getTitle() }}

+
+ {{ app_info.getVersion() }} +
+
- Hello, {{ current_user_name }}. | Logout + {% if logged_in | default() %} + Hello, {{ current_user_name }}. | Logout + {% else %} + Login + {% endif %}
- +{% endif %} -
+ {% block content %} Nothing to see here... {% endblock %} diff --git a/templates/login.html.twig b/templates/login.html.twig index ffe297e..fdba78f 100644 --- a/templates/login.html.twig +++ b/templates/login.html.twig @@ -1,19 +1,9 @@ - - - - - Login - MailAccountAdmin - - - +{% extends "base.html.twig" %} - +{% block title %}Login{% endblock %} +{% set main_classes = 'login_page' %} -
-

MailAccountAdmin

-
- -
+{% block content %}

Login

@@ -38,7 +28,4 @@
-
- - - +{% endblock %}