Skip to content

Commit 5fd26c9

Browse files
Removed Swoole Atomic dependency and useless restart counter in watcher.(#6946)
Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent 3ad2e1d commit 5fd26c9

2 files changed

Lines changed: 3 additions & 30 deletions

File tree

src/ConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Hyperf\Watcher;
1414

1515
use Hyperf\Watcher\Command\WatchCommand;
16-
use Hyperf\Watcher\Listener\ReloadDotenvAndConfigListener;
16+
use Hyperf\Watcher\Listener\ReloadDotenvListener;
1717

1818
class ConfigProvider
1919
{
@@ -26,7 +26,7 @@ public function __invoke(): array
2626
WatchCommand::class,
2727
],
2828
'listeners' => [
29-
ReloadDotenvAndConfigListener::class,
29+
ReloadDotenvListener::class,
3030
],
3131
'publish' => [
3232
[

src/Listener/ReloadDotenvAndConfigListener.php renamed to src/Listener/ReloadDotenvListener.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,27 @@
1212

1313
namespace Hyperf\Watcher\Listener;
1414

15-
use Hyperf\Contract\ConfigInterface;
1615
use Hyperf\Event\Contract\ListenerInterface;
17-
use Hyperf\Framework\Event\BeforeWorkerStart;
1816
use Hyperf\Support\DotenvManager;
1917
use Hyperf\Watcher\Event\BeforeServerRestart;
2018
use Psr\Container\ContainerInterface;
21-
use Swoole\Atomic;
2219

23-
class ReloadDotenvAndConfigListener implements ListenerInterface
20+
final class ReloadDotenvListener implements ListenerInterface
2421
{
25-
protected static Atomic $restartCounter;
26-
2722
public function __construct(protected ContainerInterface $container)
2823
{
29-
static::$restartCounter = new Atomic(0);
3024
}
3125

3226
public function listen(): array
3327
{
3428
return [
35-
BeforeWorkerStart::class,
3629
BeforeServerRestart::class,
3730
];
3831
}
3932

4033
public function process(object $event): void
4134
{
42-
if ($event instanceof BeforeWorkerStart
43-
&& $event->workerId === 0
44-
&& static::$restartCounter->get() === 0
45-
) {
46-
static::$restartCounter->add();
47-
return;
48-
}
49-
50-
static::$restartCounter->add();
51-
5235
$this->reloadDotenv();
53-
$this->reloadConfig();
54-
}
55-
56-
protected function reloadConfig(): void
57-
{
58-
if (! method_exists($this->container, 'unbind')) {
59-
return;
60-
}
61-
62-
$this->container->unbind(ConfigInterface::class);
6336
}
6437

6538
protected function reloadDotenv(): void

0 commit comments

Comments
 (0)