41 lines
1.8 KiB
PHP
41 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Process\Tester\EffectLedger;
|
||
use App\Process\Tester\ProcessSandboxDriver;
|
||
use App\Process\Tester\SandboxBootstrapper;
|
||
use Illuminate\Console\Attributes\Description;
|
||
use Illuminate\Console\Attributes\Signature;
|
||
use Illuminate\Console\Command;
|
||
use Throwable;
|
||
|
||
/**
|
||
* Entry of a tester run – only inside the process ProcessSandbox starts for it (environment FEWO_SANDBOX_RUN, so the
|
||
* SandboxBootstrapper has turned the process into a sandbox before anything was resolved). Reads input.json of the run
|
||
* and writes report.json; never touches anything outside the run's directory.
|
||
*/
|
||
#[Signature('process:sandbox-run {run : id of the prepared run}')]
|
||
#[Description('Play a process tester scenario inside its isolated process (started by the process tester only)')]
|
||
class ProcessSandboxRun extends Command
|
||
{
|
||
public function handle(ProcessSandboxDriver $driver): int
|
||
{
|
||
if (! SandboxBootstrapper::active() || (string) getenv(SandboxBootstrapper::ENV) !== (string) $this->argument('run') || config('sandbox.run') !== $this->argument('run')) {
|
||
$this->error('Nur innerhalb eines vom Prozess-Tester gestarteten Laufs.');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$directory = (string) config('sandbox.directory');
|
||
try {
|
||
$report = $driver->run((array) json_decode((string) file_get_contents($directory.'/input.json'), true));
|
||
} catch (Throwable $exception) {
|
||
$report = ['aborted' => 'Lauf abgebrochen: '.class_basename($exception).': '.$exception->getMessage(), 'timeline' => [], 'violations' => EffectLedger::violations()];
|
||
}
|
||
file_put_contents($directory.'/report.json', json_encode($report, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|