]> BookStack Code Mirror - system-cli/blob - src/Services/ArtisanRunner.php
Bumped version
[system-cli] / src / Services / ArtisanRunner.php
1 <?php declare(strict_types=1);
2
3 namespace Cli\Services;
4
5 use Exception;
6
7 class ArtisanRunner
8 {
9     public function __construct(
10         protected string $appDir
11     ) {
12     }
13
14     public function run(array $commandArgs)
15     {
16         $errors = (new ProgramRunner('php', '/usr/bin/php'))
17             ->withTimeout(600)
18             ->withIdleTimeout(600)
19             ->withEnvironment(EnvironmentLoader::load($this->appDir))
20             ->runCapturingAllOutput([
21                 $this->appDir . DIRECTORY_SEPARATOR . 'artisan',
22                 '-n', '-q',
23                 ...$commandArgs
24             ]);
25
26         if ($errors) {
27             $cmdString = implode(' ', $commandArgs);
28             throw new Exception("Failed 'php artisan {$cmdString}' with errors:\n" . $errors);
29         }
30     }
31 }