Files
core/bin/composer-script/run.php
2021-02-15 16:04:38 +01:00

24 lines
680 B
PHP

<?php
declare(strict_types=1);
use Symfony\Component\Console\Style\SymfonyStyle;
function run(string $command, SymfonyStyle $symfonyStyle, bool $withOutput = false, string $message = ''): void
{
exec($command, $output, $return);
if ($return) {
// Some error occurred.
if (empty($message)) {
$message = sprintf("Command '%s' failed. %s", $command, implode("\n", $output));
}
$symfonyStyle->error($message);
} else {
if ($withOutput) {
$symfonyStyle->text($output);
}
$message = sprintf("Command '%s' executed successfully.", $command);
$symfonyStyle->success($message);
}
}