Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added event AfterExecute for command. #1335

Merged
merged 4 commits into from Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- [#1328](https://github.com/hyperf/hyperf/pull/1328) Added `ModelRewriteInheritanceVisitor` to rewrite the model inheritance for command `gen:model`.
- [#1331](https://github.com/hyperf/hyperf/pull/1331) Added `Hyperf\LoadBalancer\LoadBalancerInterface::getNodes()`.
- [#1335](https://github.com/hyperf/hyperf/pull/1335) Added event `AfterExecute` for `command`.

## Changed

Expand Down
2 changes: 2 additions & 0 deletions src/command/src/Command.php
Expand Up @@ -399,6 +399,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->eventDispatcher->dispatch(new Event\FailToHandle($this, $exception));
return $exception->getCode();
} finally {
$this->eventDispatcher && $this->eventDispatcher->dispatch(new Event\AfterExecute($this));
}

return 0;
Expand Down
17 changes: 17 additions & 0 deletions src/command/src/Event/AfterExecute.php
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\Command\Event;

class AfterExecute extends Event
{
}
32 changes: 32 additions & 0 deletions src/command/src/Listener/ClearTimerListener.php
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\Command\Listener;

use Hyperf\Command\Event\AfterExecute;
use Hyperf\Event\Contract\ListenerInterface;
use Swoole\Timer;

class ClearTimerListener implements ListenerInterface
{
public function listen(): array
{
return [
AfterExecute::class,
];
}

public function process(object $event)
{
Timer::clearAll();
}
}