diff --git a/src/Assets/AbstractCustomAsset.php b/src/Assets/AbstractCustomAsset.php index f8f1a4173..40a628974 100644 --- a/src/Assets/AbstractCustomAsset.php +++ b/src/Assets/AbstractCustomAsset.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace App\Assets; +use App\Container\EnvironmentAwareTrait; use App\Entity\Station; -use App\Environment; use GuzzleHttp\Psr7\Uri; use Psr\Http\Message\UriInterface; use Symfony\Component\Filesystem\Filesystem; abstract class AbstractCustomAsset implements CustomAssetInterface { + use EnvironmentAwareTrait; + public function __construct( - protected readonly Environment $environment, protected readonly ?Station $station = null ) { } diff --git a/src/Assets/AssetTypes.php b/src/Assets/AssetTypes.php index c62cbfefc..c7303af37 100644 --- a/src/Assets/AssetTypes.php +++ b/src/Assets/AssetTypes.php @@ -17,10 +17,12 @@ enum AssetTypes: string Environment $environment, ?Station $station = null ): CustomAssetInterface { - return match ($this) { - self::AlbumArt => new AlbumArtCustomAsset($environment, $station), - self::Background => new BackgroundCustomAsset($environment, $station), - self::BrowserIcon => new BrowserIconCustomAsset($environment, $station), + $instance = match ($this) { + self::AlbumArt => new AlbumArtCustomAsset($station), + self::Background => new BackgroundCustomAsset($station), + self::BrowserIcon => new BrowserIconCustomAsset($station), }; + $instance->setEnvironment($environment); + return $instance; } } diff --git a/src/Auth.php b/src/Auth.php index 319f10ef3..a686cfcdb 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App; +use App\Container\EnvironmentAwareTrait; use App\Entity\Repository\UserRepository; use App\Entity\User; use App\Exception\NotLoggedInException; @@ -11,6 +12,8 @@ use Mezzio\Session\SessionInterface; final class Auth { + use EnvironmentAwareTrait; + public const SESSION_IS_LOGIN_COMPLETE_KEY = 'is_login_complete'; public const SESSION_USER_ID_KEY = 'user_id'; public const SESSION_MASQUERADE_USER_ID_KEY = 'masquerade_user_id'; @@ -24,8 +27,7 @@ final class Auth public function __construct( private readonly UserRepository $userRepo, - private readonly SessionInterface $session, - private readonly Environment $environment + private readonly SessionInterface $session ) { } diff --git a/src/Console/Command/AbstractDatabaseCommand.php b/src/Console/Command/AbstractDatabaseCommand.php index 32805be81..1102aa35b 100644 --- a/src/Console/Command/AbstractDatabaseCommand.php +++ b/src/Console/Command/AbstractDatabaseCommand.php @@ -6,19 +6,14 @@ namespace App\Console\Command; use App\Console\Command\Traits\PassThruProcess; use App\Container\EntityManagerAwareTrait; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use Symfony\Component\Console\Style\SymfonyStyle; abstract class AbstractDatabaseCommand extends CommandAbstract { use PassThruProcess; use EntityManagerAwareTrait; - - public function __construct( - protected Environment $environment - ) { - parent::__construct(); - } + use EnvironmentAwareTrait; protected function getDatabaseSettingsAsCliFlags(): array { diff --git a/src/Console/Command/Backup/BackupCommand.php b/src/Console/Command/Backup/BackupCommand.php index 52e2fcd9a..f334da6eb 100644 --- a/src/Console/Command/Backup/BackupCommand.php +++ b/src/Console/Command/Backup/BackupCommand.php @@ -6,7 +6,6 @@ namespace App\Console\Command\Backup; use App\Console\Command\AbstractDatabaseCommand; use App\Entity; -use App\Environment; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -26,10 +25,9 @@ use const PATHINFO_EXTENSION; final class BackupCommand extends AbstractDatabaseCommand { public function __construct( - Environment $environment, private readonly Entity\Repository\StorageLocationRepository $storageLocationRepo ) { - parent::__construct($environment); + parent::__construct(); } protected function configure(): void diff --git a/src/Console/Command/GenerateApiDocsCommand.php b/src/Console/Command/GenerateApiDocsCommand.php index 3d64f40ba..644594473 100644 --- a/src/Console/Command/GenerateApiDocsCommand.php +++ b/src/Console/Command/GenerateApiDocsCommand.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Console\Command; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; -use App\Environment; use App\Version; use OpenApi\Annotations\OpenApi; use OpenApi\Generator; @@ -22,9 +22,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; final class GenerateApiDocsCommand extends CommandAbstract { use LoggerAwareTrait; + use EnvironmentAwareTrait; public function __construct( - private readonly Environment $environment, private readonly Version $version ) { parent::__construct(); diff --git a/src/Console/Command/Locale/GenerateCommand.php b/src/Console/Command/Locale/GenerateCommand.php index ad82cb8b3..21ce8d86d 100644 --- a/src/Console/Command/Locale/GenerateCommand.php +++ b/src/Console/Command/Locale/GenerateCommand.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Console\Command\Locale; use App\Console\Command\CommandAbstract; +use App\Container\EnvironmentAwareTrait; use App\Enums\SupportedLocales; -use App\Environment; use Gettext\Generator\PoGenerator; use Gettext\Loader\PoLoader; use Gettext\Scanner\PhpScanner; @@ -26,11 +26,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; )] final class GenerateCommand extends CommandAbstract { - public function __construct( - private readonly Environment $environment - ) { - parent::__construct(); - } + use EnvironmentAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/Console/Command/Locale/ImportCommand.php b/src/Console/Command/Locale/ImportCommand.php index c93e647ed..0d3b09e60 100644 --- a/src/Console/Command/Locale/ImportCommand.php +++ b/src/Console/Command/Locale/ImportCommand.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Console\Command\Locale; use App\Console\Command\CommandAbstract; +use App\Container\EnvironmentAwareTrait; use App\Enums\SupportedLocales; -use App\Environment; use Gettext\Generator\MoGenerator; use Gettext\Loader\PoLoader; use Symfony\Component\Console\Attribute\AsCommand; @@ -21,11 +21,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; )] final class ImportCommand extends CommandAbstract { - public function __construct( - private readonly Environment $environment - ) { - parent::__construct(); - } + use EnvironmentAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/Console/Command/MessageQueue/ProcessCommand.php b/src/Console/Command/MessageQueue/ProcessCommand.php index 5f0fd9b72..b6837f07c 100644 --- a/src/Console/Command/MessageQueue/ProcessCommand.php +++ b/src/Console/Command/MessageQueue/ProcessCommand.php @@ -6,9 +6,9 @@ namespace App\Console\Command\MessageQueue; use App\CallableEventDispatcherInterface; use App\Console\Command\CommandAbstract; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Doctrine\Messenger\ClearEntityManagerSubscriber; -use App\Environment; use App\MessageQueue\LogWorkerExceptionSubscriber; use App\MessageQueue\QueueManagerInterface; use App\MessageQueue\ResetArrayCacheSubscriber; @@ -33,12 +33,12 @@ use Throwable; final class ProcessCommand extends CommandAbstract { use LoggerAwareTrait; + use EnvironmentAwareTrait; public function __construct( private readonly MessageBus $messageBus, private readonly CallableEventDispatcherInterface $eventDispatcher, private readonly QueueManagerInterface $queueManager, - private readonly Environment $environment, ) { parent::__construct(); } diff --git a/src/Console/Command/MigrateConfigCommand.php b/src/Console/Command/MigrateConfigCommand.php index 0319ae928..eae88a41f 100644 --- a/src/Console/Command/MigrateConfigCommand.php +++ b/src/Console/Command/MigrateConfigCommand.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Console\Command; +use App\Container\EnvironmentAwareTrait; use App\Environment; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; @@ -16,11 +17,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; )] final class MigrateConfigCommand extends CommandAbstract { - public function __construct( - private readonly Environment $environment, - ) { - parent::__construct(); - } + use EnvironmentAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/Console/Command/SetupCommand.php b/src/Console/Command/SetupCommand.php index f044d0370..1f04861d9 100644 --- a/src/Console/Command/SetupCommand.php +++ b/src/Console/Command/SetupCommand.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Console\Command; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Service\AzuraCastCentral; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; @@ -19,8 +19,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; )] final class SetupCommand extends CommandAbstract { + use EnvironmentAwareTrait; + public function __construct( - private readonly Environment $environment, private readonly Entity\Repository\SettingsRepository $settingsRepo, private readonly AzuraCastCentral $acCentral, private readonly Entity\Repository\StorageLocationRepository $storageLocationRepo diff --git a/src/Console/Command/SetupFixturesCommand.php b/src/Console/Command/SetupFixturesCommand.php index 515724fbe..5102a38a0 100644 --- a/src/Console/Command/SetupFixturesCommand.php +++ b/src/Console/Command/SetupFixturesCommand.php @@ -6,7 +6,7 @@ namespace App\Console\Command; use App\Container\ContainerAwareTrait; use App\Container\EntityManagerAwareTrait; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Purger\ORMPurger; @@ -25,12 +25,7 @@ final class SetupFixturesCommand extends CommandAbstract { use ContainerAwareTrait; use EntityManagerAwareTrait; - - public function __construct( - private readonly Environment $environment, - ) { - parent::__construct(); - } + use EnvironmentAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/Console/Command/Sync/AbstractSyncCommand.php b/src/Console/Command/Sync/AbstractSyncCommand.php index 51af0ee6a..c66607deb 100644 --- a/src/Console/Command/Sync/AbstractSyncCommand.php +++ b/src/Console/Command/Sync/AbstractSyncCommand.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Console\Command\Sync; use App\Console\Command\CommandAbstract; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; -use App\Environment; use App\Lock\LockFactory; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Lock\Lock; @@ -17,12 +17,12 @@ use function random_int; abstract class AbstractSyncCommand extends CommandAbstract { use LoggerAwareTrait; + use EnvironmentAwareTrait; protected array $processes = []; public function __construct( protected LockFactory $lockFactory, - protected Environment $environment, ) { parent::__construct(); } diff --git a/src/Console/Command/Sync/NowPlayingCommand.php b/src/Console/Command/Sync/NowPlayingCommand.php index be7d2af35..1bd6d51b2 100644 --- a/src/Console/Command/Sync/NowPlayingCommand.php +++ b/src/Console/Command/Sync/NowPlayingCommand.php @@ -7,7 +7,6 @@ namespace App\Console\Command\Sync; use App\Cache\NowPlayingCache; use App\Container\EntityManagerAwareTrait; use App\Entity\Repository\SettingsRepository; -use App\Environment; use App\Lock\LockFactory; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; @@ -31,9 +30,8 @@ final class NowPlayingCommand extends AbstractSyncCommand private readonly SettingsRepository $settingsRepo, private readonly NowPlayingCache $nowPlayingCache, LockFactory $lockFactory, - Environment $environment ) { - parent::__construct($lockFactory, $environment); + parent::__construct($lockFactory); } protected function configure(): void diff --git a/src/Console/Command/Sync/RunnerCommand.php b/src/Console/Command/Sync/RunnerCommand.php index 3b0d200dc..4fa20f5a4 100644 --- a/src/Console/Command/Sync/RunnerCommand.php +++ b/src/Console/Command/Sync/RunnerCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Console\Command\Sync; use App\Entity\Repository\SettingsRepository; -use App\Environment; use App\Event\GetSyncTasks; use App\Lock\LockFactory; use App\Sync\Task\AbstractTask; @@ -27,12 +26,11 @@ use function usleep; final class RunnerCommand extends AbstractSyncCommand { public function __construct( - LockFactory $lockFactory, - Environment $environment, private readonly EventDispatcherInterface $dispatcher, private readonly SettingsRepository $settingsRepo, + LockFactory $lockFactory ) { - parent::__construct($lockFactory, $environment); + parent::__construct($lockFactory); } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Container/EnvironmentAwareTrait.php b/src/Container/EnvironmentAwareTrait.php new file mode 100644 index 000000000..c0c69623b --- /dev/null +++ b/src/Container/EnvironmentAwareTrait.php @@ -0,0 +1,24 @@ +environment = $environment; + } + + public function getEnvironment(): Environment + { + return $this->environment; + } +} diff --git a/src/Controller/Admin/BackupsAction.php b/src/Controller/Admin/BackupsAction.php index 7e9dc466a..536f33827 100644 --- a/src/Controller/Admin/BackupsAction.php +++ b/src/Controller/Admin/BackupsAction.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace App\Controller\Admin; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class BackupsAction { + use EnvironmentAwareTrait; + public function __construct( - private readonly Environment $environment, private readonly Entity\Repository\StorageLocationRepository $storageLocationRepo ) { } diff --git a/src/Controller/Admin/UpdatesAction.php b/src/Controller/Admin/UpdatesAction.php index 5984d8046..f0747f074 100644 --- a/src/Controller/Admin/UpdatesAction.php +++ b/src/Controller/Admin/UpdatesAction.php @@ -2,8 +2,8 @@ namespace App\Controller\Admin; +use App\Container\EnvironmentAwareTrait; use App\Entity\Repository\SettingsRepository; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\Version; @@ -11,9 +11,10 @@ use Psr\Http\Message\ResponseInterface; final class UpdatesAction { + use EnvironmentAwareTrait; + public function __construct( private readonly SettingsRepository $settingsRepo, - private readonly Environment $environment, private readonly Version $version ) { } diff --git a/src/Controller/Api/Admin/CustomAssets/DeleteCustomAssetAction.php b/src/Controller/Api/Admin/CustomAssets/DeleteCustomAssetAction.php index a2314a542..a05e209b2 100644 --- a/src/Controller/Api/Admin/CustomAssets/DeleteCustomAssetAction.php +++ b/src/Controller/Api/Admin/CustomAssets/DeleteCustomAssetAction.php @@ -5,18 +5,15 @@ declare(strict_types=1); namespace App\Controller\Api\Admin\CustomAssets; use App\Assets\AssetTypes; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class DeleteCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Admin/CustomAssets/GetCustomAssetAction.php b/src/Controller/Api/Admin/CustomAssets/GetCustomAssetAction.php index b8bc68b0e..634b22165 100644 --- a/src/Controller/Api/Admin/CustomAssets/GetCustomAssetAction.php +++ b/src/Controller/Api/Admin/CustomAssets/GetCustomAssetAction.php @@ -5,17 +5,14 @@ declare(strict_types=1); namespace App\Controller\Api\Admin\CustomAssets; use App\Assets\AssetTypes; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class GetCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Admin/CustomAssets/PostCustomAssetAction.php b/src/Controller/Api/Admin/CustomAssets/PostCustomAssetAction.php index 509d8c82e..eff33c129 100644 --- a/src/Controller/Api/Admin/CustomAssets/PostCustomAssetAction.php +++ b/src/Controller/Api/Admin/CustomAssets/PostCustomAssetAction.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Controller\Api\Admin\CustomAssets; use App\Assets\AssetTypes; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\Media\AlbumArt; @@ -15,10 +15,7 @@ use Psr\Http\Message\ResponseInterface; final class PostCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Admin/LogsAction.php b/src/Controller/Api/Admin/LogsAction.php index 81335eb88..d2430b422 100644 --- a/src/Controller/Api/Admin/LogsAction.php +++ b/src/Controller/Api/Admin/LogsAction.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Controller\Api\Admin; +use App\Container\EnvironmentAwareTrait; use App\Controller\Api\Traits\HasLogViewer; -use App\Environment; use App\Exception; use App\Http\Response; use App\Http\ServerRequest; @@ -15,9 +15,9 @@ use Psr\Http\Message\ResponseInterface; final class LogsAction { use HasLogViewer; + use EnvironmentAwareTrait; public function __construct( - private readonly Environment $environment, private readonly ServiceControl $serviceControl, ) { } diff --git a/src/Controller/Api/Admin/ServerStatsAction.php b/src/Controller/Api/Admin/ServerStatsAction.php index fe79d1bb0..79fae7cac 100644 --- a/src/Controller/Api/Admin/ServerStatsAction.php +++ b/src/Controller/Api/Admin/ServerStatsAction.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Controller\Api\Admin; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use App\Http\Response; use App\Http\ServerRequest; use App\OpenApi; @@ -37,10 +37,7 @@ use Psr\Http\Message\ResponseInterface; ] final class ServerStatsAction { - public function __construct( - private readonly Environment $environment, - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Admin/Shoutcast/PostAction.php b/src/Controller/Api/Admin/Shoutcast/PostAction.php index 16dbc98d5..2e1c91a83 100644 --- a/src/Controller/Api/Admin/Shoutcast/PostAction.php +++ b/src/Controller/Api/Admin/Shoutcast/PostAction.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Controller\Api\Admin\Shoutcast; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\Service\Flow; @@ -15,10 +15,7 @@ use Symfony\Component\Process\Process; final class PostAction { - public function __construct( - private readonly Environment $environment, - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Admin/Stations/CloneAction.php b/src/Controller/Api/Admin/Stations/CloneAction.php index d350b27a9..840b2affb 100644 --- a/src/Controller/Api/Admin/Stations/CloneAction.php +++ b/src/Controller/Api/Admin/Stations/CloneAction.php @@ -4,21 +4,20 @@ declare(strict_types=1); namespace App\Controller\Api\Admin\Stations; +use App\Container\EnvironmentAwareTrait; use App\Controller\Api\Admin\StationsController; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; -use App\Radio\Configuration; use DeepCopy; use Doctrine\Common\Collections\Collection; use Psr\Http\Message\ResponseInterface; -use Symfony\Component\Serializer\Serializer; -use Symfony\Component\Validator\Validator\ValidatorInterface; use Throwable; final class CloneAction extends StationsController { + use EnvironmentAwareTrait; + public const CLONE_MEDIA_STORAGE = 'media_storage'; public const CLONE_RECORDINGS_STORAGE = 'recordings_storage'; public const CLONE_PODCASTS_STORAGE = 'podcasts_storage'; @@ -30,25 +29,6 @@ final class CloneAction extends StationsController public const CLONE_PERMISSIONS = 'permissions'; public const CLONE_WEBHOOKS = 'webhooks'; - public function __construct( - Entity\Repository\StationRepository $stationRepo, - Entity\Repository\StorageLocationRepository $storageLocationRepo, - Entity\Repository\StationQueueRepository $queueRepo, - Configuration $configuration, - Serializer $serializer, - ValidatorInterface $validator, - private readonly Environment $environment - ) { - parent::__construct( - $stationRepo, - $storageLocationRepo, - $queueRepo, - $configuration, - $serializer, - $validator - ); - } - public function __invoke( ServerRequest $request, Response $response, diff --git a/src/Controller/Api/Stations/CustomAssets/DeleteCustomAssetAction.php b/src/Controller/Api/Stations/CustomAssets/DeleteCustomAssetAction.php index bd09ad197..9d2e8ef01 100644 --- a/src/Controller/Api/Stations/CustomAssets/DeleteCustomAssetAction.php +++ b/src/Controller/Api/Stations/CustomAssets/DeleteCustomAssetAction.php @@ -5,18 +5,15 @@ declare(strict_types=1); namespace App\Controller\Api\Stations\CustomAssets; use App\Assets\AssetTypes; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class DeleteCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Stations/CustomAssets/GetCustomAssetAction.php b/src/Controller/Api/Stations/CustomAssets/GetCustomAssetAction.php index e7b3e58a1..8d808f4c2 100644 --- a/src/Controller/Api/Stations/CustomAssets/GetCustomAssetAction.php +++ b/src/Controller/Api/Stations/CustomAssets/GetCustomAssetAction.php @@ -5,17 +5,14 @@ declare(strict_types=1); namespace App\Controller\Api\Stations\CustomAssets; use App\Assets\AssetTypes; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; final class GetCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Stations/CustomAssets/PostCustomAssetAction.php b/src/Controller/Api/Stations/CustomAssets/PostCustomAssetAction.php index 7ba6b40a1..b0f71557f 100644 --- a/src/Controller/Api/Stations/CustomAssets/PostCustomAssetAction.php +++ b/src/Controller/Api/Stations/CustomAssets/PostCustomAssetAction.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Controller\Api\Stations\CustomAssets; use App\Assets\AssetTypes; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\Media\AlbumArt; @@ -15,10 +15,7 @@ use Psr\Http\Message\ResponseInterface; final class PostCustomAssetAction { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke( ServerRequest $request, diff --git a/src/Controller/Api/Stations/HistoryController.php b/src/Controller/Api/Stations/HistoryController.php index 86b50bde5..291e985be 100644 --- a/src/Controller/Api/Stations/HistoryController.php +++ b/src/Controller/Api/Stations/HistoryController.php @@ -6,10 +6,10 @@ namespace App\Controller\Api\Stations; use App; use App\Container\EntityManagerAwareTrait; +use App\Container\EnvironmentAwareTrait; use App\Controller\Api\Traits\AcceptsDateRange; use App\Doctrine\ReadOnlyBatchIteratorAggregate; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\OpenApi; @@ -63,10 +63,10 @@ final class HistoryController { use AcceptsDateRange; use EntityManagerAwareTrait; + use EnvironmentAwareTrait; public function __construct( - private readonly Entity\ApiGenerator\SongHistoryApiGenerator $songHistoryApiGenerator, - private readonly Environment $environment + private readonly Entity\ApiGenerator\SongHistoryApiGenerator $songHistoryApiGenerator ) { } diff --git a/src/Controller/Frontend/SetupController.php b/src/Controller/Frontend/SetupController.php index 156c1b2ca..fdfe2e618 100644 --- a/src/Controller/Frontend/SetupController.php +++ b/src/Controller/Frontend/SetupController.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Controller\Frontend; use App\Container\EntityManagerAwareTrait; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Exception\NotLoggedInException; use App\Exception\ValidationException; use App\Http\Response; @@ -21,10 +21,10 @@ use Throwable; final class SetupController { use EntityManagerAwareTrait; + use EnvironmentAwareTrait; public function __construct( private readonly Entity\Repository\SettingsRepository $settingsRepo, - private readonly Environment $environment, private readonly Entity\Repository\RolePermissionRepository $permissionRepo, private readonly ValidatorInterface $validator, private readonly StationFormComponent $stationFormComponent, diff --git a/src/Controller/Stations/SftpUsersAction.php b/src/Controller/Stations/SftpUsersAction.php index b7a8f427b..6161f12e4 100644 --- a/src/Controller/Stations/SftpUsersAction.php +++ b/src/Controller/Stations/SftpUsersAction.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Controller\Stations; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use App\Http\Response; use App\Http\ServerRequest; use App\Service\AzuraCastCentral; @@ -12,8 +12,9 @@ use Psr\Http\Message\ResponseInterface; final class SftpUsersAction { + use EnvironmentAwareTrait; + public function __construct( - private readonly Environment $environment, private readonly AzuraCastCentral $acCentral ) { } diff --git a/src/Customization.php b/src/Customization.php index 67427c1cf..e799e721a 100644 --- a/src/Customization.php +++ b/src/Customization.php @@ -4,8 +4,9 @@ declare(strict_types=1); namespace App; -use App\Assets\BackgroundCustomAsset; +use App\Assets\AssetTypes; use App\Assets\BrowserIconCustomAsset; +use App\Container\EnvironmentAwareTrait; use App\Entity; use App\Enums\SupportedLocales; use App\Enums\SupportedThemes; @@ -16,6 +17,7 @@ use Psr\Http\Message\ServerRequestInterface; final class Customization { use RequestAwareTrait; + use EnvironmentAwareTrait; private ?Entity\User $user; @@ -30,7 +32,6 @@ final class Customization private string $instanceName; public function __construct( - private readonly Environment $environment, Entity\Repository\SettingsRepository $settingsRepo ) { $this->settings = $settingsRepo->readSettings(); @@ -121,7 +122,7 @@ final class Customization { $publicCss = $this->settings->getPublicCustomCss() ?? ''; - $background = new BackgroundCustomAsset($this->environment); + $background = AssetTypes::Background->createObject($this->environment); if ($background->isUploaded()) { $backgroundUrl = $background->getUrl(); @@ -139,7 +140,8 @@ final class Customization { $publicCss = $station->getBrandingConfig()->getPublicCustomCss() ?? ''; - $background = new BackgroundCustomAsset($this->environment, $station); + $background = AssetTypes::Background->createObject($this->environment, $station); + if ($background->isUploaded()) { $backgroundUrl = $background->getUrl(); @@ -176,7 +178,10 @@ final class Customization public function getBrowserIconUrl(int $size = 256): string { - return (new BrowserIconCustomAsset($this->environment))->getUrlForSize($size); + /** @var BrowserIconCustomAsset $browserIcon */ + $browserIcon = AssetTypes::BrowserIcon->createObject($this->environment); + + return $browserIcon->getUrlForSize($size); } /** diff --git a/src/Entity/Repository/StationRepository.php b/src/Entity/Repository/StationRepository.php index 1589dc7df..1eef93fca 100644 --- a/src/Entity/Repository/StationRepository.php +++ b/src/Entity/Repository/StationRepository.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace App\Entity\Repository; -use App\Assets\AlbumArtCustomAsset; +use App\Assets\AssetTypes; +use App\Container\EnvironmentAwareTrait; use App\Doctrine\ReloadableEntityManagerInterface; use App\Doctrine\Repository; use App\Entity; -use App\Environment; use App\Flysystem\ExtendedFilesystemInterface; use App\Flysystem\StationFilesystems; use App\Radio\Enums\StreamFormats; @@ -21,10 +21,11 @@ use Psr\Http\Message\UriInterface; */ final class StationRepository extends Repository { + use EnvironmentAwareTrait; + public function __construct( ReloadableEntityManagerInterface $em, private readonly SettingsRepository $settingsRepo, - private readonly Environment $environment ) { parent::__construct($em); } @@ -188,7 +189,7 @@ final class StationRepository extends Repository public function getDefaultAlbumArtUrl(?Entity\Station $station = null): UriInterface { if (null !== $station) { - $stationAlbumArt = new AlbumArtCustomAsset($this->environment, $station); + $stationAlbumArt = AssetTypes::AlbumArt->createObject($this->environment, $station); if ($stationAlbumArt->isUploaded()) { return $stationAlbumArt->getUri(); } @@ -200,7 +201,7 @@ final class StationRepository extends Repository } $customUrl = $this->settingsRepo->readSettings()->getDefaultAlbumArtUrlAsUri(); - return $customUrl ?? (new AlbumArtCustomAsset($this->environment))->getUri(); + return $customUrl ?? AssetTypes::AlbumArt->createObject($this->environment)->getUri(); } public function setFallback( diff --git a/src/Entity/StorageLocationAdapter/LocalStorageLocationAdapter.php b/src/Entity/StorageLocationAdapter/LocalStorageLocationAdapter.php index df3217d27..f592df07f 100644 --- a/src/Entity/StorageLocationAdapter/LocalStorageLocationAdapter.php +++ b/src/Entity/StorageLocationAdapter/LocalStorageLocationAdapter.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Entity\StorageLocationAdapter; +use App\Container\EnvironmentAwareTrait; use App\Entity\Enums\StorageLocationAdapters; -use App\Environment; use App\Flysystem\Adapter\LocalAdapterInterface; use App\Flysystem\Adapter\LocalFilesystemAdapter; use App\Flysystem\ExtendedFilesystemInterface; @@ -14,10 +14,7 @@ use Symfony\Component\Filesystem\Path; final class LocalStorageLocationAdapter extends AbstractStorageLocationLocationAdapter { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function getType(): StorageLocationAdapters { diff --git a/src/Http/ErrorHandler.php b/src/Http/ErrorHandler.php index 7013c44f5..e2d9a88ba 100644 --- a/src/Http/ErrorHandler.php +++ b/src/Http/ErrorHandler.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace App\Http; +use App\Container\EnvironmentAwareTrait; use App\Entity; use App\Enums\SupportedLocales; -use App\Environment; use App\Exception; use App\Exception\NotLoggedInException; use App\Exception\PermissionDeniedException; @@ -26,6 +26,8 @@ use Whoops\Run; final class ErrorHandler extends \Slim\Handlers\ErrorHandler { + use EnvironmentAwareTrait; + private bool $returnJson = false; private bool $showDetailed = false; @@ -36,7 +38,6 @@ final class ErrorHandler extends \Slim\Handlers\ErrorHandler private readonly View $view, private readonly Router $router, private readonly InjectSession $injectSession, - private readonly Environment $environment, App $app, Logger $logger, ) { diff --git a/src/Installer/Command/InstallCommand.php b/src/Installer/Command/InstallCommand.php index 9214838b4..f9bbbd097 100644 --- a/src/Installer/Command/InstallCommand.php +++ b/src/Installer/Command/InstallCommand.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Installer\Command; +use App\Container\EnvironmentAwareTrait; use App\Enums\SupportedLocales; use App\Environment; use App\Installer\EnvFiles\AbstractEnvFile; @@ -26,13 +27,9 @@ use Symfony\Component\Yaml\Yaml; )] final class InstallCommand extends Command { - public const DEFAULT_BASE_DIRECTORY = '/installer'; + use EnvironmentAwareTrait; - public function __construct( - private readonly Environment $environment - ) { - parent::__construct(); - } + public const DEFAULT_BASE_DIRECTORY = '/installer'; protected function configure(): void { diff --git a/src/Middleware/Auth/AbstractAuth.php b/src/Middleware/Auth/AbstractAuth.php index f78472140..e7b75c940 100644 --- a/src/Middleware/Auth/AbstractAuth.php +++ b/src/Middleware/Auth/AbstractAuth.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace App\Middleware\Auth; use App\Acl; +use App\Container\EnvironmentAwareTrait; use App\Customization; use App\Entity; -use App\Environment; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -16,9 +16,10 @@ use Psr\Http\Server\RequestHandlerInterface; abstract class AbstractAuth implements MiddlewareInterface { + use EnvironmentAwareTrait; + public function __construct( protected readonly Entity\Repository\UserRepository $userRepo, - protected readonly Environment $environment, protected readonly Acl $acl, protected readonly Customization $customization ) { diff --git a/src/Middleware/Auth/ApiAuth.php b/src/Middleware/Auth/ApiAuth.php index 08dcbd6d6..aadf2c022 100644 --- a/src/Middleware/Auth/ApiAuth.php +++ b/src/Middleware/Auth/ApiAuth.php @@ -8,7 +8,6 @@ use App\Acl; use App\Auth; use App\Customization; use App\Entity; -use App\Environment; use App\Exception\CsrfValidationException; use App\Http\ServerRequest; use App\Security\SplitToken; @@ -24,11 +23,10 @@ final class ApiAuth extends AbstractAuth public function __construct( protected Entity\Repository\ApiKeyRepository $apiKeyRepo, Entity\Repository\UserRepository $userRepo, - Environment $environment, Acl $acl, Customization $customization ) { - parent::__construct($userRepo, $environment, $acl, $customization); + parent::__construct($userRepo, $acl, $customization); } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface @@ -56,8 +54,8 @@ final class ApiAuth extends AbstractAuth $auth = new Auth( userRepo: $this->userRepo, session: $request->getAttribute(ServerRequest::ATTR_SESSION), - environment: $this->environment, ); + $auth->setEnvironment($this->environment); if ($auth->isLoggedIn()) { $user = $auth->getLoggedInUser(); diff --git a/src/Middleware/Auth/StandardAuth.php b/src/Middleware/Auth/StandardAuth.php index d403196f6..2a794a7eb 100644 --- a/src/Middleware/Auth/StandardAuth.php +++ b/src/Middleware/Auth/StandardAuth.php @@ -18,8 +18,9 @@ final class StandardAuth extends AbstractAuth $auth = new Auth( userRepo: $this->userRepo, session: $request->getAttribute(ServerRequest::ATTR_SESSION), - environment: $this->environment, ); + $auth->setEnvironment($this->environment); + $user = ($auth->isLoggedIn()) ? $auth->getLoggedInUser() : null; $request = $request diff --git a/src/Middleware/GetCurrentUser.php b/src/Middleware/GetCurrentUser.php index 1ea309341..e4dff64e0 100644 --- a/src/Middleware/GetCurrentUser.php +++ b/src/Middleware/GetCurrentUser.php @@ -6,9 +6,9 @@ namespace App\Middleware; use App\Acl; use App\Auth; +use App\Container\EnvironmentAwareTrait; use App\Customization; use App\Entity; -use App\Environment; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -20,9 +20,10 @@ use Psr\Http\Server\RequestHandlerInterface; */ final class GetCurrentUser implements MiddlewareInterface { + use EnvironmentAwareTrait; + public function __construct( private readonly Entity\Repository\UserRepository $userRepo, - private readonly Environment $environment, private readonly Acl $acl, private readonly Customization $customization ) { @@ -34,8 +35,9 @@ final class GetCurrentUser implements MiddlewareInterface $auth = new Auth( userRepo: $this->userRepo, session: $request->getAttribute(ServerRequest::ATTR_SESSION), - environment: $this->environment, ); + $auth->setEnvironment($this->environment); + $user = ($auth->isLoggedIn()) ? $auth->getLoggedInUser() : null; $request = $request diff --git a/src/Middleware/Module/Api.php b/src/Middleware/Module/Api.php index d978589b5..b44b8757f 100644 --- a/src/Middleware/Module/Api.php +++ b/src/Middleware/Module/Api.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Middleware\Module; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Http\Response; use App\Http\ServerRequest; use App\Utilities\Urls; @@ -21,9 +21,10 @@ use Symfony\Component\VarDumper\VarDumper; */ final class Api { + use EnvironmentAwareTrait; + public function __construct( - private readonly Entity\Repository\SettingsRepository $settingsRepo, - private readonly Environment $environment + private readonly Entity\Repository\SettingsRepository $settingsRepo ) { } diff --git a/src/Middleware/ReopenEntityManagerMiddleware.php b/src/Middleware/ReopenEntityManagerMiddleware.php index 6f88b1c76..af17877c3 100644 --- a/src/Middleware/ReopenEntityManagerMiddleware.php +++ b/src/Middleware/ReopenEntityManagerMiddleware.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Middleware; +use App\Container\EnvironmentAwareTrait; use App\Doctrine\DecoratedEntityManager; -use App\Environment; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -13,9 +13,10 @@ use Psr\Http\Server\RequestHandlerInterface; final class ReopenEntityManagerMiddleware implements MiddlewareInterface { + use EnvironmentAwareTrait; + public function __construct( private readonly DecoratedEntityManager $em, - private readonly Environment $environment ) { } diff --git a/src/Notification/Check/ProfilerAdvisorCheck.php b/src/Notification/Check/ProfilerAdvisorCheck.php index 18b1ec24a..0a2983950 100644 --- a/src/Notification/Check/ProfilerAdvisorCheck.php +++ b/src/Notification/Check/ProfilerAdvisorCheck.php @@ -4,18 +4,15 @@ declare(strict_types=1); namespace App\Notification\Check; +use App\Container\EnvironmentAwareTrait; use App\Entity\Api\Notification; use App\Enums\GlobalPermissions; -use App\Environment; use App\Event\GetNotifications; use App\Session\FlashLevels; final class ProfilerAdvisorCheck { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function __invoke(GetNotifications $event): void { diff --git a/src/Notification/Check/RecentBackupCheck.php b/src/Notification/Check/RecentBackupCheck.php index 00845ddaf..b3698fcab 100644 --- a/src/Notification/Check/RecentBackupCheck.php +++ b/src/Notification/Check/RecentBackupCheck.php @@ -4,17 +4,18 @@ declare(strict_types=1); namespace App\Notification\Check; +use App\Container\EnvironmentAwareTrait; use App\Entity; use App\Enums\GlobalPermissions; -use App\Environment; use App\Event\GetNotifications; use App\Session\FlashLevels; use Carbon\CarbonImmutable; final class RecentBackupCheck { + use EnvironmentAwareTrait; + public function __construct( - private readonly Environment $environment, private readonly Entity\Repository\SettingsRepository $settingsRepo ) { } diff --git a/src/Radio/AbstractLocalAdapter.php b/src/Radio/AbstractLocalAdapter.php index c35d396e0..bdc12cc37 100644 --- a/src/Radio/AbstractLocalAdapter.php +++ b/src/Radio/AbstractLocalAdapter.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace App\Radio; use App\Container\EntityManagerAwareTrait; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Entity; -use App\Environment; use App\Exception\Supervisor\AlreadyRunningException; use App\Exception\Supervisor\NotRunningException; use App\Exception\SupervisorException; @@ -21,9 +21,9 @@ abstract class AbstractLocalAdapter { use LoggerAwareTrait; use EntityManagerAwareTrait; + use EnvironmentAwareTrait; public function __construct( - protected Environment $environment, protected SupervisorInterface $supervisor, protected EventDispatcherInterface $dispatcher, protected Router $router, diff --git a/src/Radio/Backend/Liquidsoap/ConfigWriter.php b/src/Radio/Backend/Liquidsoap/ConfigWriter.php index c9fe2ad4d..99bc96ba0 100644 --- a/src/Radio/Backend/Liquidsoap/ConfigWriter.php +++ b/src/Radio/Backend/Liquidsoap/ConfigWriter.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace App\Radio\Backend\Liquidsoap; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Event\Radio\WriteLiquidsoapConfiguration; use App\Radio\Backend\Liquidsoap; use App\Radio\Enums\AudioProcessingMethods; @@ -22,10 +22,11 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; final class ConfigWriter implements EventSubscriberInterface { + use EnvironmentAwareTrait; + public function __construct( private readonly Entity\Repository\SettingsRepository $settingsRepo, private readonly Liquidsoap $liquidsoap, - private readonly Environment $environment, private readonly FallbackFile $fallbackFile ) { } diff --git a/src/Radio/Configuration.php b/src/Radio/Configuration.php index f87361063..bd777ca4d 100644 --- a/src/Radio/Configuration.php +++ b/src/Radio/Configuration.php @@ -5,11 +5,11 @@ declare(strict_types=1); namespace App\Radio; use App\Container\EntityManagerAwareTrait; +use App\Container\EnvironmentAwareTrait; use App\Entity\Enums\PlaylistTypes; use App\Entity\Repository\StationPlaylistMediaRepository; use App\Entity\Station; use App\Entity\StationPlaylist; -use App\Environment; use App\Exception; use App\Radio\Enums\BackendAdapters; use App\Radio\Enums\FrontendAdapters; @@ -20,6 +20,7 @@ use Supervisor\SupervisorInterface; final class Configuration { use EntityManagerAwareTrait; + use EnvironmentAwareTrait; public const DEFAULT_PORT_MIN = 8000; public const DEFAULT_PORT_MAX = 8499; @@ -36,7 +37,6 @@ final class Configuration public function __construct( private readonly Adapters $adapters, private readonly SupervisorInterface $supervisor, - private readonly Environment $environment, private readonly StationPlaylistMediaRepository $spmRepo, ) { } @@ -400,7 +400,7 @@ final class Configuration */ public function removeConfiguration(Station $station): void { - if (Environment::getInstance()->isTesting()) { + if ($this->environment->isTesting()) { return; } diff --git a/src/Radio/FallbackFile.php b/src/Radio/FallbackFile.php index ecf9bd547..e36bd1dac 100644 --- a/src/Radio/FallbackFile.php +++ b/src/Radio/FallbackFile.php @@ -4,16 +4,13 @@ declare(strict_types=1); namespace App\Radio; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Flysystem\StationFilesystems; final class FallbackFile { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function getFallbackPathForStation(Entity\Station $station): string { diff --git a/src/Radio/Frontend/AbstractFrontend.php b/src/Radio/Frontend/AbstractFrontend.php index 2b03a6cf2..92bc5adbf 100644 --- a/src/Radio/Frontend/AbstractFrontend.php +++ b/src/Radio/Frontend/AbstractFrontend.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Radio\Frontend; use App\Entity; -use App\Environment; use App\Http\Router; use App\Nginx\CustomUrls; use App\Radio\AbstractLocalAdapter; @@ -29,12 +28,11 @@ abstract class AbstractFrontend extends AbstractLocalAdapter protected Client $http_client, protected Entity\Repository\SettingsRepository $settingsRepo, protected Entity\Repository\StationMountRepository $stationMountRepo, - Environment $environment, SupervisorInterface $supervisor, EventDispatcherInterface $dispatcher, Router $router ) { - parent::__construct($environment, $supervisor, $dispatcher, $router); + parent::__construct($supervisor, $dispatcher, $router); } /** diff --git a/src/Radio/Remote/AzuraRelay.php b/src/Radio/Remote/AzuraRelay.php index ec6cf99dc..9c2daa133 100644 --- a/src/Radio/Remote/AzuraRelay.php +++ b/src/Radio/Remote/AzuraRelay.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace App\Radio\Remote; use App\Cache\AzuraRelayCache; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use GuzzleHttp\Client; use GuzzleHttp\Promise\Create; use GuzzleHttp\Promise\PromiseInterface; @@ -18,6 +18,8 @@ use NowPlaying\Result\Result; final class AzuraRelay extends AbstractRemote { + use EnvironmentAwareTrait; + public function __construct( private readonly AzuraRelayCache $azuraRelayCache, Entity\Repository\SettingsRepository $settingsRepo, @@ -91,7 +93,7 @@ final class AzuraRelay extends AbstractRemote if ( $use_radio_proxy || 'https' === $base_url->getScheme() - || (!Environment::getInstance()->isProduction() && !Environment::getInstance()->isDocker()) + || (!$this->environment->isProduction() && !$this->environment->isDocker()) ) { // Web proxy support. return (string)$base_url diff --git a/src/RateLimit.php b/src/RateLimit.php index e1c3d1d99..ba879c368 100644 --- a/src/RateLimit.php +++ b/src/RateLimit.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App; +use App\Container\EnvironmentAwareTrait; use App\Entity\Repository\SettingsRepository; use App\Http\ServerRequest; use App\Lock\LockFactory; @@ -14,11 +15,12 @@ use Symfony\Component\RateLimiter\Storage\CacheStorage; final class RateLimit { + use EnvironmentAwareTrait; + private CacheItemPoolInterface $psr6Cache; public function __construct( private readonly LockFactory $lockFactory, - private readonly Environment $environment, private readonly SettingsRepository $settingsRepo, CacheItemPoolInterface $cacheItemPool ) { diff --git a/src/Service/Acme.php b/src/Service/Acme.php index da1ceecd2..3e6d8dc45 100644 --- a/src/Service/Acme.php +++ b/src/Service/Acme.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Service; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Entity\Repository\SettingsRepository; use App\Entity\Repository\StationRepository; @@ -22,6 +23,7 @@ use Symfony\Component\Filesystem\Filesystem; final class Acme { use LoggerAwareTrait; + use EnvironmentAwareTrait; public const LETSENCRYPT_PROD = 'https://acme-v02.api.letsencrypt.org/directory'; public const LETSENCRYPT_DEV = 'https://acme-staging-v02.api.letsencrypt.org/directory'; @@ -30,7 +32,6 @@ final class Acme public function __construct( private readonly SettingsRepository $settingsRepo, private readonly StationRepository $stationRepo, - private readonly Environment $environment, private readonly Nginx $nginx, private readonly Adapters $adapters, ) { diff --git a/src/Service/AzuraCastCentral.php b/src/Service/AzuraCastCentral.php index 7e78d3f80..1015f55b4 100644 --- a/src/Service/AzuraCastCentral.php +++ b/src/Service/AzuraCastCentral.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace App\Service; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Entity; -use App\Environment; use App\Version; use Exception; use GuzzleHttp\Client; @@ -14,11 +14,11 @@ use GuzzleHttp\Client; final class AzuraCastCentral { use LoggerAwareTrait; + use EnvironmentAwareTrait; private const BASE_URL = 'https://central.azuracast.com'; public function __construct( - private readonly Environment $environment, private readonly Version $version, private readonly Client $httpClient, private readonly Entity\Repository\SettingsRepository $settingsRepo diff --git a/src/Service/Centrifugo.php b/src/Service/Centrifugo.php index a2b7a35a7..bf4c9f8d8 100644 --- a/src/Service/Centrifugo.php +++ b/src/Service/Centrifugo.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace App\Service; +use App\Container\EnvironmentAwareTrait; use App\Entity\Station; -use App\Environment; use GuzzleHttp\Client; final class Centrifugo { + use EnvironmentAwareTrait; + public const GLOBAL_TIME_CHANNEL = 'global:time'; public function __construct( - private readonly Environment $environment, private readonly Client $client, ) { } diff --git a/src/Service/RedisFactory.php b/src/Service/RedisFactory.php index 87f5e70a0..45fc2bf02 100644 --- a/src/Service/RedisFactory.php +++ b/src/Service/RedisFactory.php @@ -4,16 +4,13 @@ declare(strict_types=1); namespace App\Service; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use Redis; use RuntimeException; final class RedisFactory { - public function __construct( - private readonly Environment $environment - ) { - } + use EnvironmentAwareTrait; public function isSupported(): bool { diff --git a/src/Service/ServiceControl.php b/src/Service/ServiceControl.php index ecafa6ea9..fa9cb5b93 100644 --- a/src/Service/ServiceControl.php +++ b/src/Service/ServiceControl.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Service; -use App\Environment; +use App\Container\EnvironmentAwareTrait; use App\Exception\SupervisorException; use App\Service\ServiceControl\ServiceData; use Supervisor\Exception\Fault\BadNameException; @@ -15,9 +15,10 @@ use Supervisor\SupervisorInterface; final class ServiceControl { + use EnvironmentAwareTrait; + public function __construct( private readonly SupervisorInterface $supervisor, - private readonly Environment $environment, private readonly Centrifugo $centrifugo ) { } diff --git a/src/Service/WebUpdater.php b/src/Service/WebUpdater.php index f3b7c7e04..37af16567 100644 --- a/src/Service/WebUpdater.php +++ b/src/Service/WebUpdater.php @@ -2,15 +2,16 @@ namespace App\Service; -use App\Environment; +use App\Container\EnvironmentAwareTrait; final class WebUpdater { + use EnvironmentAwareTrait; + // Don't worry that this is insecure; it's only ever used for internal communications. public const WATCHTOWER_TOKEN = 'azur4c457'; public function __construct( - private readonly Environment $environment, private readonly GuzzleFactory $guzzleFactory ) { } diff --git a/src/Sync/Task/CheckUpdatesTask.php b/src/Sync/Task/CheckUpdatesTask.php index 9f993adaa..54cdb1b58 100644 --- a/src/Sync/Task/CheckUpdatesTask.php +++ b/src/Sync/Task/CheckUpdatesTask.php @@ -4,13 +4,15 @@ declare(strict_types=1); namespace App\Sync\Task; +use App\Container\EnvironmentAwareTrait; use App\Entity; -use App\Environment; use App\Service\AzuraCastCentral; use GuzzleHttp\Exception\TransferException; final class CheckUpdatesTask extends AbstractTask { + use EnvironmentAwareTrait; + private const UPDATE_THRESHOLD = 3780; public function __construct( @@ -37,7 +39,7 @@ final class CheckUpdatesTask extends AbstractTask } } - if (Environment::getInstance()->isTesting()) { + if ($this->environment->isTesting()) { $this->logger->info('Update checks are currently disabled for this AzuraCast instance.'); return; } diff --git a/src/Webhook/Dispatcher.php b/src/Webhook/Dispatcher.php index 6dd938b24..a44c9143c 100644 --- a/src/Webhook/Dispatcher.php +++ b/src/Webhook/Dispatcher.php @@ -6,11 +6,11 @@ namespace App\Webhook; use App\Container\ContainerAwareTrait; use App\Container\EntityManagerAwareTrait; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Entity\ApiGenerator\NowPlayingApiGenerator; use App\Entity\Station; use App\Entity\StationWebhook; -use App\Environment; use App\Http\RouterInterface; use App\Message; use App\Webhook\Connector\AbstractConnector; @@ -23,9 +23,9 @@ final class Dispatcher use LoggerAwareTrait; use ContainerAwareTrait; use EntityManagerAwareTrait; + use EnvironmentAwareTrait; public function __construct( - private readonly Environment $environment, private readonly RouterInterface $router, private readonly LocalWebhookHandler $localHandler, private readonly NowPlayingApiGenerator $nowPlayingApiGen diff --git a/src/Webhook/LocalWebhookHandler.php b/src/Webhook/LocalWebhookHandler.php index b1adf9827..0d5d052d7 100644 --- a/src/Webhook/LocalWebhookHandler.php +++ b/src/Webhook/LocalWebhookHandler.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace App\Webhook; +use App\Container\EnvironmentAwareTrait; use App\Container\LoggerAwareTrait; use App\Entity; -use App\Environment; use App\Service\Centrifugo; use Symfony\Component\Filesystem\Filesystem; @@ -15,11 +15,11 @@ use const JSON_PRETTY_PRINT; final class LocalWebhookHandler { use LoggerAwareTrait; + use EnvironmentAwareTrait; public const NAME = 'local'; public function __construct( - private readonly Environment $environment, private readonly Centrifugo $centrifugo ) { }