Add version numbers; make app title configurable
This commit is contained in:
parent
186dcdc0cb
commit
8df2684e5c
11 changed files with 159 additions and 38 deletions
42
src/VersionHelper.php
Normal file
42
src/VersionHelper.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin;
|
||||
|
||||
class VersionHelper
|
||||
{
|
||||
private string $version;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$version = $this->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';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue