Skip to content

Commit e819b6b

Browse files
committed
refactor(events): enhance OutputtedEvent to include outputter
- Add `CommandFinished|Response $outputter` as a new parameter to the OutputtedEvent constructor. - Update `OutputManager` to pass the correct $outputter parameter when raising OutputtedEvent. - Improve event handling by enabling more contextual information with the additional parameter. - Include necessary imports for `CommandFinished` and `Response` to support the changes.
1 parent c0fec88 commit e819b6b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Events/OutputtedEvent.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
namespace Guanguans\LaravelSoar\Events;
1515

1616
use Guanguans\LaravelSoar\Contracts\OutputContract;
17+
use Illuminate\Console\Events\CommandFinished;
1718
use Illuminate\Support\Collection;
19+
use Symfony\Component\HttpFoundation\Response;
1820

1921
class OutputtedEvent
2022
{
2123
public function __construct(
2224
public OutputContract $output,
2325
public Collection $scores,
26+
public CommandFinished|Response $outputter,
2427
public mixed $result
2528
) {}
2629
}

src/Middleware/OutputSoarScoresMiddleware.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ public function __construct(
3737
*/
3838
public function handle(Request $request, \Closure $next): SymfonyResponse
3939
{
40-
return tap($next($request), fn (SymfonyResponse $symfonyResponse): mixed => $this->outputManager->output(
41-
$this->bootstrapper->getScores(),
42-
$symfonyResponse
43-
));
40+
return tap(
41+
$next($request),
42+
fn (SymfonyResponse $symfonyResponse): mixed => $this->outputManager->output(
43+
$this->bootstrapper->getScores(),
44+
$symfonyResponse
45+
)
46+
);
4447
}
4548
}

src/OutputManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function output(Collection $scores, CommandFinished|Response $outputter):
5353
$output instanceof SanitizerContract and $scores = $output->sanitize($scores);
5454
event(new OutputtingEvent($output, $scores, $outputter));
5555
$result = $output->output($scores, $outputter);
56-
event(new OutputtedEvent($output, $scores, $result));
56+
event(new OutputtedEvent($output, $scores, $outputter, $result));
5757
}
5858

5959
return null;

0 commit comments

Comments
 (0)