Skip to content

Commit b88631c

Browse files
authored
Improved AfterExecute event of hyperf/command (#6233)
1 parent 20731f3 commit b88631c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
445445

446446
$this->eventDispatcher->dispatch(new Event\FailToHandle($this, $exception));
447447
} finally {
448-
$this->eventDispatcher?->dispatch(new Event\AfterExecute($this));
448+
$this->eventDispatcher?->dispatch(new Event\AfterExecute($this, $exception ?? null));
449449
}
450450

451451
return $this->exitCode;

src/Event/AfterExecute.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
*/
1212
namespace Hyperf\Command\Event;
1313

14+
use Hyperf\Command\Command;
15+
use Throwable;
16+
1417
class AfterExecute extends Event
1518
{
19+
public function __construct(Command $command, protected ?Throwable $throwable = null)
20+
{
21+
parent::__construct($command);
22+
}
23+
24+
public function getThrowable(): ?Throwable
25+
{
26+
return $this->throwable;
27+
}
1628
}

0 commit comments

Comments
 (0)