Introduce two new enums.
This commit is contained in:
parent
d237e92479
commit
ce0e9cc78d
|
@ -231,7 +231,8 @@ return [
|
|||
Environment $environment
|
||||
) {
|
||||
$console = new App\Console\Application(
|
||||
$environment->getAppName() . ' Command Line Tools (' . $environment->getAppEnvironment() . ')',
|
||||
$environment->getAppName() . ' Command Line Tools ('
|
||||
. $environment->getAppEnvironmentEnum()->getName() . ')',
|
||||
$version->getVersion()
|
||||
);
|
||||
$console->setDispatcher($dispatcher);
|
||||
|
|
|
@ -36,7 +36,7 @@ class BrowserIconCustomAsset extends AbstractCustomAsset
|
|||
protected function getDefaultUrl(): string
|
||||
{
|
||||
$assetUrl = $this->environment->getAssetUrl();
|
||||
return $assetUrl . '/icons/' . $this->environment->getAppEnvironment() . '/original.png';
|
||||
return $assetUrl . '/icons/' . $this->environment->getAppEnvironmentEnum()->value . '/original.png';
|
||||
}
|
||||
|
||||
public function upload(Image $image): void
|
||||
|
@ -75,6 +75,6 @@ class BrowserIconCustomAsset extends AbstractCustomAsset
|
|||
return $assetUrl . '/uploads/browser_icon/' . $size . '.' . $mtime . '.png';
|
||||
}
|
||||
|
||||
return $assetUrl . '/icons/' . $this->environment->getAppEnvironment() . '/' . $size . '.png';
|
||||
return $assetUrl . '/icons/' . $this->environment->getAppEnvironmentEnum()->value . '/' . $size . '.png';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class InitializeCommand extends CommandAbstract
|
|||
|
||||
$io->listing(
|
||||
[
|
||||
__('Environment: %s', ucfirst($this->environment->getAppEnvironment())),
|
||||
__('Environment: %s', $this->environment->getAppEnvironmentEnum()->getName()),
|
||||
__('Installation Method: %s', $this->environment->isDocker() ? 'Docker' : 'Ansible'),
|
||||
]
|
||||
);
|
||||
|
|
|
@ -28,7 +28,7 @@ class SettingsAction
|
|||
'apiUrl' => (string)$router->named('api:admin:settings', [
|
||||
'group' => Settings::GROUP_GENERAL,
|
||||
]),
|
||||
'releaseChannel' => $version->getReleaseChannel(),
|
||||
'releaseChannel' => $version->getReleaseChannelEnum()->value,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ class SetupController
|
|||
'apiUrl' => (string)$router->named('api:admin:settings', [
|
||||
'group' => Entity\Settings::GROUP_GENERAL,
|
||||
]),
|
||||
'releaseChannel' => $version->getReleaseChannel(),
|
||||
'releaseChannel' => $version->getReleaseChannelEnum()->value,
|
||||
'continueUrl' => (string)$router->named('dashboard'),
|
||||
],
|
||||
);
|
||||
|
|
|
@ -168,7 +168,7 @@ class Customization
|
|||
}
|
||||
|
||||
if (!$this->environment->isProduction()) {
|
||||
$title = '(' . ucfirst($this->environment->getAppEnvironment()) . ') ' . $title;
|
||||
$title = '(' . $this->environment->getAppEnvironmentEnum()->getName() . ') ' . $title;
|
||||
}
|
||||
|
||||
return $title ?? '';
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// phpcs:ignoreFile
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ApplicationEnvironment: string
|
||||
{
|
||||
case Production = 'production';
|
||||
case Testing = 'testing';
|
||||
case Development = 'development';
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return ucfirst($this->value);
|
||||
}
|
||||
|
||||
public static function default(): self
|
||||
{
|
||||
return self::Production;
|
||||
}
|
||||
|
||||
public static function toSelect(): array
|
||||
{
|
||||
$values = [];
|
||||
foreach (self::cases() as $case) {
|
||||
$values[$case->value] = $case->getName();
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
// phpcs:ignoreFile
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ReleaseChannel: string
|
||||
{
|
||||
case RollingRelease = 'latest';
|
||||
case Stable = 'stable';
|
||||
|
||||
public static function default(): self
|
||||
{
|
||||
return self::RollingRelease;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Enums\ApplicationEnvironment;
|
||||
use App\Enums\ReleaseChannel;
|
||||
use App\Radio\Configuration;
|
||||
use App\Traits\AvailableStaticallyTrait;
|
||||
use Psr\Log\LogLevel;
|
||||
|
@ -14,11 +16,6 @@ class Environment
|
|||
|
||||
protected array $data = [];
|
||||
|
||||
// Environments
|
||||
public const ENV_DEVELOPMENT = 'development';
|
||||
public const ENV_TESTING = 'testing';
|
||||
public const ENV_PRODUCTION = 'production';
|
||||
|
||||
// Core settings values
|
||||
public const APP_NAME = 'APP_NAME';
|
||||
public const APP_ENV = 'APPLICATION_ENV';
|
||||
|
@ -69,7 +66,6 @@ class Environment
|
|||
// Default settings
|
||||
protected array $defaults = [
|
||||
self::APP_NAME => 'AzuraCast',
|
||||
self::APP_ENV => self::ENV_PRODUCTION,
|
||||
|
||||
self::LOG_LEVEL => LogLevel::NOTICE,
|
||||
self::IS_DOCKER => true,
|
||||
|
@ -103,24 +99,25 @@ class Environment
|
|||
return $this->data;
|
||||
}
|
||||
|
||||
public function getAppEnvironment(): string
|
||||
public function getAppEnvironmentEnum(): ApplicationEnvironment
|
||||
{
|
||||
return $this->data[self::APP_ENV] ?? self::ENV_PRODUCTION;
|
||||
return ApplicationEnvironment::tryFrom($this->data[self::APP_ENV] ?? '')
|
||||
?? ApplicationEnvironment::default();
|
||||
}
|
||||
|
||||
public function isProduction(): bool
|
||||
{
|
||||
return self::ENV_PRODUCTION === $this->getAppEnvironment();
|
||||
return ApplicationEnvironment::Production === $this->getAppEnvironmentEnum();
|
||||
}
|
||||
|
||||
public function isTesting(): bool
|
||||
{
|
||||
return self::ENV_TESTING === $this->getAppEnvironment();
|
||||
return ApplicationEnvironment::Testing === $this->getAppEnvironmentEnum();
|
||||
}
|
||||
|
||||
public function isDevelopment(): bool
|
||||
{
|
||||
return self::ENV_DEVELOPMENT === $this->getAppEnvironment();
|
||||
return ApplicationEnvironment::Development === $this->getAppEnvironmentEnum();
|
||||
}
|
||||
|
||||
public function isDocker(): bool
|
||||
|
@ -214,13 +211,10 @@ class Environment
|
|||
return $this->data[self::LANG];
|
||||
}
|
||||
|
||||
public function getReleaseChannel(): string
|
||||
public function getReleaseChannelEnum(): ReleaseChannel
|
||||
{
|
||||
$channel = $this->data[self::RELEASE_CHANNEL] ?? 'latest';
|
||||
|
||||
return ('stable' === $channel)
|
||||
? Version::RELEASE_CHANNEL_STABLE
|
||||
: Version::RELEASE_CHANNEL_ROLLING;
|
||||
return ReleaseChannel::tryFrom($this->data[self::RELEASE_CHANNEL] ?? '')
|
||||
?? ReleaseChannel::default();
|
||||
}
|
||||
|
||||
public function getSftpPort(): int
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Installer\EnvFiles;
|
||||
|
||||
use App\Enums\ApplicationEnvironment;
|
||||
use App\Enums\SupportedLocales;
|
||||
use App\Environment;
|
||||
use Psr\Log\LogLevel;
|
||||
|
@ -42,11 +43,7 @@ class AzuraCastEnvFile extends AbstractEnvFile
|
|||
'name' => __(
|
||||
'The application environment.',
|
||||
),
|
||||
'options' => [
|
||||
Environment::ENV_PRODUCTION,
|
||||
Environment::ENV_DEVELOPMENT,
|
||||
Environment::ENV_TESTING,
|
||||
],
|
||||
'options' => ApplicationEnvironment::toSelect(),
|
||||
'required' => true,
|
||||
],
|
||||
Environment::LOG_LEVEL => [
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Notification\Check;
|
|||
|
||||
use App\Entity;
|
||||
use App\Enums\GlobalPermissions;
|
||||
use App\Enums\ReleaseChannel;
|
||||
use App\Event\GetNotifications;
|
||||
use App\Session\Flash;
|
||||
use App\Version;
|
||||
|
@ -41,9 +42,9 @@ class UpdateCheck
|
|||
$actionLabel = __('Update Instructions');
|
||||
$actionUrl = Version::UPDATE_URL;
|
||||
|
||||
$releaseChannel = $this->version->getReleaseChannel();
|
||||
$releaseChannel = $this->version->getReleaseChannelEnum();
|
||||
|
||||
if (Version::RELEASE_CHANNEL_STABLE === $releaseChannel && $updateData['needs_release_update']) {
|
||||
if (ReleaseChannel::Stable === $releaseChannel && $updateData['needs_release_update']) {
|
||||
$notificationParts = [
|
||||
'<b>' . __(
|
||||
'AzuraCast <a href="%s" target="_blank">version %s</a> is now available.',
|
||||
|
@ -67,7 +68,7 @@ class UpdateCheck
|
|||
return;
|
||||
}
|
||||
|
||||
if (Version::RELEASE_CHANNEL_ROLLING === $releaseChannel && $updateData['needs_rolling_update']) {
|
||||
if (ReleaseChannel::RollingRelease === $releaseChannel && $updateData['needs_rolling_update']) {
|
||||
$notificationParts = [];
|
||||
|
||||
$notificationParts[] = '<b>' . __(
|
||||
|
|
|
@ -32,10 +32,10 @@ class AzuraCastCentral
|
|||
public function checkForUpdates(): ?array
|
||||
{
|
||||
$request_body = [
|
||||
'id' => $this->getUniqueIdentifier(),
|
||||
'is_docker' => $this->environment->isDocker(),
|
||||
'environment' => $this->environment->getAppEnvironment(),
|
||||
'release_channel' => $this->version->getReleaseChannel(),
|
||||
'id' => $this->getUniqueIdentifier(),
|
||||
'is_docker' => $this->environment->isDocker(),
|
||||
'environment' => $this->environment->getAppEnvironmentEnum()->value,
|
||||
'release_channel' => $this->version->getReleaseChannelEnum()->value,
|
||||
];
|
||||
|
||||
$commit_hash = $this->version->getCommitHash();
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
namespace App\Tests;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Enums\ApplicationEnvironment;
|
||||
use App\Environment;
|
||||
use Codeception\Configuration;
|
||||
use Codeception\Lib\Framework;
|
||||
|
@ -46,7 +47,7 @@ class Module extends Framework implements DoctrineProvider
|
|||
$autoloader,
|
||||
[
|
||||
Environment::BASE_DIR => Configuration::projectDir(),
|
||||
Environment::APP_ENV => Environment::ENV_TESTING,
|
||||
Environment::APP_ENV => ApplicationEnvironment::Testing->value,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App;
|
||||
|
||||
use App\Enums\ReleaseChannel;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
@ -17,9 +18,6 @@ class Version
|
|||
/** @var string Version that is displayed if no Git repository information is present. */
|
||||
public const FALLBACK_VERSION = '0.15.0';
|
||||
|
||||
public const RELEASE_CHANNEL_ROLLING = 'rolling';
|
||||
public const RELEASE_CHANNEL_STABLE = 'stable';
|
||||
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
public const LATEST_COMPOSE_REVISION = 12;
|
||||
public const LATEST_COMPOSE_URL = 'https://raw.githubusercontent.com/AzuraCast/AzuraCast/main/docker-compose.sample.yml';
|
||||
|
@ -37,17 +35,16 @@ class Version
|
|||
$this->repoDir = $environment->getBaseDirectory();
|
||||
}
|
||||
|
||||
public function getReleaseChannel(): string
|
||||
public function getReleaseChannelEnum(): ReleaseChannel
|
||||
{
|
||||
if ($this->environment->isDocker()) {
|
||||
return $this->environment->getReleaseChannel();
|
||||
return $this->environment->getReleaseChannelEnum();
|
||||
}
|
||||
|
||||
$details = $this->getDetails();
|
||||
|
||||
return ('stable' === $details['branch'])
|
||||
? self::RELEASE_CHANNEL_STABLE
|
||||
: self::RELEASE_CHANNEL_ROLLING;
|
||||
? ReleaseChannel::Stable
|
||||
: ReleaseChannel::RollingRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,8 +159,8 @@ class Version
|
|||
$details['commit_date']
|
||||
);
|
||||
|
||||
$releaseChannel = $this->getReleaseChannel();
|
||||
if (self::RELEASE_CHANNEL_ROLLING === $releaseChannel) {
|
||||
$releaseChannel = $this->getReleaseChannelEnum();
|
||||
if (ReleaseChannel::RollingRelease === $releaseChannel) {
|
||||
return 'Rolling Release ' . $commitText;
|
||||
}
|
||||
return 'v' . $details['tag'] . ' Stable';
|
||||
|
|
Loading…
Reference in New Issue