43 lines
943 B
PHP
43 lines
943 B
PHP
<?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';
|
|
}
|
|
}
|