$commands * @param callable(string):int|null $runner * @param string|null $cwd Directorio de trabajo del proyecto: los * comandos se ejecutan alli, no donde arranco * el instalador. * @return list comandos ejecutados */ public static function run( array $commands, Console $console, bool $assumeYes = false, ?callable $runner = null, ?string $cwd = null ): array { $executed = []; $previous = null; if ($cwd !== null && is_dir($cwd)) { $previous = getcwd(); chdir($cwd); } try { foreach ($commands as $command) { $console->out(' post-install: ' . $command); if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) { $console->warn('post-install omitido: ' . $command); continue; } if ($runner !== null) { $runner($command); } else { passthru($command, $code); if (($code ?? 0) !== 0) { throw new ToolboxException("post-install falló: {$command}"); } } $executed[] = $command; } } finally { if ($previous !== null) { chdir($previous); } } return $executed; } }