Skip to content

Commit 043fdeb

Browse files
committed
refactor(console-commands): enhance process handling with callback option
- Added Symfony Process as a dependency to improve command-line process management. - Introduced a callback method in WithSoarOptions trait for streamlined process output handling. - Updated RunCommand and ScoreCommand to utilize the new callback for process output. - Adjusted Facade methods to support optional callback parameters for enhanced flexibility.
1 parent 14b2471 commit 043fdeb

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

composer-dependency-analyser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'nesbot/carbon',
3939
'symfony/console',
4040
'symfony/http-foundation',
41+
'symfony/process',
4142
'symfony/var-dumper',
4243
],
4344
[ErrorType::SHADOW_DEPENDENCY]

src/Commands/Concerns/WithSoarOptions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Guanguans\LaravelSoar\Soar;
1919
use Illuminate\Support\Str;
2020
use Symfony\Component\Console\Input\InputOption;
21+
use Symfony\Component\Process\Process;
2122

2223
/**
2324
* @mixin \Illuminate\Console\Command
@@ -64,4 +65,11 @@ protected function normalizedOptions(): array
6465
})
6566
->all();
6667
}
68+
69+
protected function callback(): \Closure
70+
{
71+
return function (string $type, string $line): void {
72+
Process::ERR === $type ? $this->error($line) : $this->info($line);
73+
};
74+
}
6775
}

src/Commands/RunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class RunCommand extends Command
3131
*/
3232
public function handle(): void
3333
{
34-
$this->info($this->debugSoar()->run());
34+
$this->debugSoar()->run($this->callback());
3535
}
3636
}

src/Commands/ScoreCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function handle(): void
4747
}
4848
}
4949

50-
$this->info($this->debugSoar()->scores($query));
50+
$this->debugSoar()->scores($query, $this->callback());
5151
}
5252
}

src/Facades/Soar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
use Illuminate\Support\Facades\Facade;
1919

2020
/**
21-
* @method static string help()
22-
* @method static string version()
21+
* @method static string help(null|callable $callback = null)
22+
* @method static string version(null|callable $callback = null)
2323
* @method static \Guanguans\SoarPHP\Soar clone()
2424
* @method static array arrayScores(array|string $sqls, int $depth = 512, int $options = 0)
2525
* @method static string jsonScores(array|string $sqls)
2626
* @method static string htmlScores(array|string $sqls)
2727
* @method static string markdownScores(array|string $sqls)
28-
* @method static string scores(array|string $sqls)
28+
* @method static string scores(array|string $sqls, null|callable $callback = null)
2929
* @method static \Guanguans\SoarPHP\Soar flushOptions()
3030
* @method static \Guanguans\SoarPHP\Soar setOption(string $name, mixed $value)
3131
* @method static \Guanguans\SoarPHP\Soar setOptions(array $options)

0 commit comments

Comments
 (0)