Added NullDisableEventDispatcher to disable event dispatcher by default. (#4852)

Co-authored-by: huangdijia <huangdijia@gmail.com>
This commit is contained in:
李铭昕 2022-06-16 22:54:21 +08:00 committed by GitHub
parent 624f0d158f
commit c8d4d666aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 2 deletions

View File

@ -48,6 +48,7 @@ composer analyse
- [#4523](https://github.com/hyperf/hyperf/pull/4523) Support callback conditions for `Conditionable::when()` and `Conditionable::unless()`.
- [#4663](https://github.com/hyperf/hyperf/pull/4663) Make `Hyperf\Utils\Stringable` implements `Stringable`.
- [#4700](https://github.com/hyperf/hyperf/pull/4700) Support coroutine style server for `socketio-server`.
- [#4852](https://github.com/hyperf/hyperf/pull/4852) Added `NullDisableEventDispatcher` to disable event dispatcher by default.
## Optimized

View File

@ -18,7 +18,7 @@ use Symfony\Component\Console\Input\InputOption;
trait DisableEventDispatcher
{
public function addDisableDispatcherOption()
public function addDisableDispatcherOption(): void
{
$this->addOption('disable-event-dispatcher', null, InputOption::VALUE_NONE, 'Whether disable event dispatcher.');
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Command;
use Symfony\Component\Console\Input\InputInterface;
trait NullDisableEventDispatcher
{
public function addDisableDispatcherOption(): void
{
}
public function disableDispatcher(InputInterface $input)
{
}
}

View File

@ -103,7 +103,7 @@ class MetricFactory implements MetricFactoryInterface
$port = $this->config->get("metric.metric.{$this->name}.scrape_port");
$path = $this->config->get("metric.metric.{$this->name}.scrape_path");
$renderer = new RenderTextFormat();
$server = new Server($host, (int) $port, false);
$server = new Server($host, (int) $port, false, true);
Coroutine::create(static function () use ($server) {
CoordinatorManager::until(Coord::WORKER_EXIT)->yield();
$server->shutdown();

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Hyperf\Watcher\Command;
use Hyperf\Command\Command;
use Hyperf\Command\NullDisableEventDispatcher;
use Hyperf\Watcher\Option;
use Hyperf\Watcher\Watcher;
use Psr\Container\ContainerInterface;
@ -19,6 +20,8 @@ use Symfony\Component\Console\Input\InputOption;
class WatchCommand extends Command
{
use NullDisableEventDispatcher;
public function __construct(protected ContainerInterface $container)
{
parent::__construct('server:watch');