This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): Set-up hooks on lifecycle events
- Loading branch information
Showing
22 changed files
with
443 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Configurator; | ||
|
||
use K911\Swoole\Server\LifecycleHandler\ServerManagerStartHandlerInterface; | ||
use Swoole\Http\Server; | ||
|
||
final class WithServerManagerStartHandler implements ConfiguratorInterface | ||
{ | ||
private $handler; | ||
|
||
public function __construct(ServerManagerStartHandlerInterface $handler) | ||
{ | ||
$this->handler = $handler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(Server $server): void | ||
{ | ||
$server->on('ManagerStart', [$this->handler, 'handle']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Configurator; | ||
|
||
use K911\Swoole\Server\LifecycleHandler\ServerManagerStopHandlerInterface; | ||
use Swoole\Http\Server; | ||
|
||
final class WithServerManagerStopHandler implements ConfiguratorInterface | ||
{ | ||
private $handler; | ||
|
||
public function __construct(ServerManagerStopHandlerInterface $handler) | ||
{ | ||
$this->handler = $handler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(Server $server): void | ||
{ | ||
$server->on('ManagerStop', [$this->handler, 'handle']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Configurator; | ||
|
||
use K911\Swoole\Server\LifecycleHandler\ServerShutdownHandlerInterface; | ||
use Swoole\Http\Server; | ||
|
||
final class WithServerShutdownHandler implements ConfiguratorInterface | ||
{ | ||
private $handler; | ||
|
||
public function __construct(ServerShutdownHandlerInterface $handler) | ||
{ | ||
$this->handler = $handler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(Server $server): void | ||
{ | ||
$server->on('shutdown', [$this->handler, 'handle']); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Server/LifecycleHandler/NoOpServerManagerStartHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
final class NoOpServerManagerStartHandler implements ServerManagerStartHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $server): void | ||
{ | ||
// noop | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Server/LifecycleHandler/NoOpServerManagerStopHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
final class NoOpServerManagerStopHandler implements ServerManagerStopHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $server): void | ||
{ | ||
// noop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
final class NoOpServerShutdownHandler implements ServerShutdownHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $server): void | ||
{ | ||
// noop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
final class NoOpServerStartHandler implements ServerStartHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $server): void | ||
{ | ||
// noop | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Server/LifecycleHandler/ServerManagerStartHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
interface ServerManagerStartHandlerInterface | ||
{ | ||
/** | ||
* Handle "OnManagerStart" event. | ||
* | ||
* Info: Handler is executed in manager process | ||
* | ||
* @param Server $server | ||
*/ | ||
public function handle(Server $server): void; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Server/LifecycleHandler/ServerManagerStopHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
interface ServerManagerStopHandlerInterface | ||
{ | ||
/** | ||
* Handle "OnManagerStop" event. | ||
* | ||
* Info: Handler is executed in manager process | ||
* | ||
* @param Server $server | ||
*/ | ||
public function handle(Server $server): void; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Server/LifecycleHandler/ServerShutdownHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
interface ServerShutdownHandlerInterface | ||
{ | ||
/** | ||
* Handle "OnShutdown" event. | ||
* | ||
* @param Server $server | ||
*/ | ||
public function handle(Server $server): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\WorkerHandler; | ||
|
||
use Swoole\Server; | ||
|
||
final class NoOpWorkerStartHandler implements WorkerStartHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $worker, int $workerId): void | ||
{ | ||
// noop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.