2022-05-23 04:50:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Radio;
|
|
|
|
|
|
|
|
use App\Entity;
|
|
|
|
use App\Environment;
|
2022-07-01 07:41:04 +00:00
|
|
|
use RuntimeException;
|
2022-05-23 04:50:55 +00:00
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
2022-05-23 07:50:52 +00:00
|
|
|
final class StereoTool
|
2022-05-23 04:50:55 +00:00
|
|
|
{
|
2022-05-23 07:50:52 +00:00
|
|
|
public static function isInstalled(): bool
|
2022-05-23 04:50:55 +00:00
|
|
|
{
|
2022-05-23 07:50:52 +00:00
|
|
|
return file_exists(self::getBinaryPath());
|
2022-05-23 04:50:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 07:50:52 +00:00
|
|
|
public static function getBinaryPath(): string
|
2022-05-23 04:50:55 +00:00
|
|
|
{
|
2022-05-23 07:50:52 +00:00
|
|
|
$environment = Environment::getInstance();
|
|
|
|
return $environment->getParentDirectory() . '/servers/stereo_tool/stereo_tool';
|
2022-05-23 04:50:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 07:50:52 +00:00
|
|
|
public static function isReady(Entity\Station $station): bool
|
2022-05-23 04:50:55 +00:00
|
|
|
{
|
2022-05-23 07:50:52 +00:00
|
|
|
if (!self::isInstalled()) {
|
2022-05-23 04:50:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$backendConfig = $station->getBackendConfig();
|
|
|
|
return !empty($backendConfig->getStereoToolConfigurationPath());
|
|
|
|
}
|
|
|
|
|
2022-05-23 07:50:52 +00:00
|
|
|
public static function getVersion(): ?string
|
2022-05-23 04:50:55 +00:00
|
|
|
{
|
2022-05-23 07:50:52 +00:00
|
|
|
if (!self::isInstalled()) {
|
2022-05-23 04:50:55 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-05-23 07:50:52 +00:00
|
|
|
$binaryPath = self::getBinaryPath();
|
2022-05-23 04:50:55 +00:00
|
|
|
|
|
|
|
$process = new Process([$binaryPath, '--help']);
|
|
|
|
$process->setWorkingDirectory(dirname($binaryPath));
|
2022-05-23 20:13:27 +00:00
|
|
|
$process->setTimeout(5.0);
|
2022-06-17 15:37:40 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$process->run();
|
2022-07-01 07:41:04 +00:00
|
|
|
} catch (RuntimeException) {
|
2022-06-17 15:37:40 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-05-23 04:50:55 +00:00
|
|
|
|
|
|
|
if (!$process->isSuccessful()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
preg_match('/STEREO TOOL ([.\d]+) CONSOLE APPLICATION/i', $process->getErrorOutput(), $matches);
|
|
|
|
return $matches[1] ?? null;
|
|
|
|
}
|
|
|
|
}
|