Files
azuracast-on-demand-hls/src/Command/AbstractCorsCommand.php
T

58 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Plugin\AzuraCastOnDemandHls\Command;
use App\Console\Command\CommandAbstract;
use App\Entity\Repository\StationRepository;
use App\Entity\Station;
use App\Nginx\Nginx;
use Plugin\AzuraCastOnDemandHls\Repository\CorsConfigurationRepository;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
abstract class AbstractCorsCommand extends CommandAbstract
{
public function __construct(
protected readonly StationRepository $stationRepository,
protected readonly CorsConfigurationRepository $corsConfiguration,
private readonly Nginx $nginx,
) {
parent::__construct();
}
protected function configureStationArgument(): void
{
$this->addArgument('station', InputArgument::REQUIRED, 'Station ID or short name.');
}
protected function findStation(InputInterface $input, SymfonyStyle $io): ?Station
{
$station = $this->stationRepository->findByIdentifier((string)$input->getArgument('station'));
if (!$station instanceof Station) {
$io->error('Station not found.');
return null;
}
return $station;
}
protected function reloadNginx(Station $station, SymfonyStyle $io): void
{
$this->nginx->writeConfiguration($station, reloadIfChanged: true);
$io->note('Station Nginx configuration was regenerated; Nginx reloads only when it changed.');
}
/** @param list<string> $origins */
protected function renderOrigins(SymfonyStyle $io, array $origins): void
{
if ([] === $origins) {
$io->writeln('No cross-site origins are allowed. Same-origin playback remains available.');
return;
}
$io->listing($origins);
}
}