Format code. (#1876)

This commit is contained in:
李铭昕 2020-06-08 11:04:26 +08:00 committed by GitHub
parent db0d74b0e2
commit dd0b262dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 30 additions and 14 deletions

View File

@ -66,7 +66,7 @@
"php-amqplib/php-amqplib": "^2.7",
"php-di/php-di": "^6.0",
"php-di/phpdoc-reader": "^2.0.1",
"phpstan/phpstan": "^0.12.18",
"phpstan/phpstan": "0.12.25",
"phpunit/phpunit": "^7.0.0",
"predis/predis": "^1.1",
"roave/better-reflection": "^4.0",

View File

@ -4,6 +4,8 @@
parameters:
bootstrap: "bootstrap.php"
# bootstrapFiles:
# - "bootstrap.php"
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: true
reportUnmatchedIgnoredErrors: false

View File

@ -103,7 +103,7 @@ abstract class AbstractProcess implements ProcessInterface
public function bind($server): void
{
if (CoroutineServer::isCoroutineServer($server)) {
$this->bindCoServer($server);
$this->bindCoroutineServer($server);
return;
}

View File

@ -45,7 +45,7 @@ class CoroutineServer implements ServerInterface
protected $config;
/**
* @var Coroutine\Server
* @var Coroutine\Http\Server|Coroutine\Server
*/
protected $server;
@ -83,13 +83,18 @@ class CoroutineServer implements ServerInterface
}
/**
* @return \Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server
* @return \Swoole\Coroutine\Http\Server|\Swoole\Coroutine\Server
*/
public function getServer()
{
return $this->server;
}
public static function isCoroutineServer($server): bool
{
return $server instanceof Coroutine\Http\Server || $server instanceof Coroutine\Server;
}
protected function initServer(ServerConfig $config): void
{
$servers = $config->getServers();
@ -129,9 +134,4 @@ class CoroutineServer implements ServerInterface
throw new RuntimeException('Server type is invalid.');
}
public static function isCoroutineServer($server): bool
{
return $server instanceof Coroutine\Http\Server || $server instanceof Coroutine\Server;
}
}

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
*/
namespace Hyperf\Server\Event;
use Hyperf\Server\ServerConfig;
use Swoole\Coroutine\Server;
class CoroutineServerStart

View File

@ -11,6 +11,17 @@ declare(strict_types=1);
*/
namespace Hyperf\Server\Event;
use Swoole\Coroutine\Server;
class CoroutineServerStop
{
/**
* @var object|Server
*/
public $server;
public function __construct($server)
{
$this->server = $server;
}
}

View File

@ -54,10 +54,10 @@ class AfterWorkerStartListener implements ListenerInterface
/** @var Port $server */
foreach (ServerManager::list() as $name => [$type, $server]) {
$listen = $server->host . ':' . $server->port;
$sockType = $server->type;
$type = value(function () use ($type, $sockType) {
$type = value(function () use ($type, $server) {
switch ($type) {
case Server::SERVER_BASE:
$sockType = $server->type;
if (($sockType === SWOOLE_SOCK_TCP) || ($sockType === SWOOLE_SOCK_TCP6)) {
return 'TCP';
}

View File

@ -14,6 +14,7 @@ namespace Hyperf\Signal\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\OnWorkerExit;
use Hyperf\Process\Event\AfterProcessHandle;
use Hyperf\Server\Event\CoroutineServerStop;
use Hyperf\Signal\SignalManager;
use Psr\Container\ContainerInterface;
@ -34,6 +35,7 @@ class SignalDeregisterListener implements ListenerInterface
return [
OnWorkerExit::class,
AfterProcessHandle::class,
CoroutineServerStop::class,
];
}

View File

@ -14,6 +14,7 @@ namespace Hyperf\Signal\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BeforeWorkerStart;
use Hyperf\Process\Event\BeforeProcessHandle;
use Hyperf\Server\Event\CoroutineServerStart;
use Hyperf\Signal\SignalHandlerInterface as SignalHandler;
use Hyperf\Signal\SignalManager;
use Psr\Container\ContainerInterface;
@ -35,6 +36,7 @@ class SignalRegisterListener implements ListenerInterface
return [
BeforeWorkerStart::class,
BeforeProcessHandle::class,
CoroutineServerStart::class,
];
}
@ -44,7 +46,7 @@ class SignalRegisterListener implements ListenerInterface
$manager->init();
$manager->listen(value(function () use ($event) {
if ($event instanceof BeforeWorkerStart) {
if ($event instanceof BeforeWorkerStart || $event instanceof CoroutineServerStart) {
return SignalHandler::WORKER;
}

View File

@ -66,7 +66,7 @@ if (! function_exists('retry')) {
/**
* Retry an operation a given number of times.
*
* @param int|float $times
* @param float|int $times
* @param int $sleep millisecond
* @throws \Throwable
*/