diff --git a/src/Pool.php b/src/Pool.php index 730954b..eba0ce8 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -66,10 +66,10 @@ public function __get($key) public static function pullPoolConfig(&$config) { return [ - 'minActive' => Arr::pull($config, 'min_active', 0), - 'maxActive' => Arr::pull($config, 'max_active', 10), - 'maxWaitTime' => Arr::pull($config, 'max_wait_time', 5), - 'maxIdleTime' => Arr::pull($config, 'max_idle_time', 20), + 'minActive' => Arr::pull($config, 'min_active', 0), + 'maxActive' => Arr::pull($config, 'max_active', 10), + 'maxWaitTime' => Arr::pull($config, 'max_wait_time', 5), + 'maxIdleTime' => Arr::pull($config, 'max_idle_time', 20), 'idleCheckInterval' => Arr::pull($config, 'idle_check_interval', 10), ]; } diff --git a/src/Sandbox.php b/src/Sandbox.php index b50aa1e..b454565 100644 --- a/src/Sandbox.php +++ b/src/Sandbox.php @@ -45,7 +45,7 @@ class Sandbox /** @var ResetterInterface[] */ protected $resetters = []; - protected $services = []; + protected $services = []; public function __construct(Container $app) { @@ -152,7 +152,7 @@ public function setInstance(Container $app) $app->instance('app', $app); $app->instance(Container::class, $app); - $reflectObject = new ReflectionObject($app); + $reflectObject = new ReflectionObject($app); $reflectProperty = $reflectObject->getProperty('services'); $reflectProperty->setAccessible(true); $services = $reflectProperty->getValue($app); @@ -201,7 +201,7 @@ protected function setInitialServices() foreach ($services as $service) { if (class_exists($service) && !in_array($service, $this->services)) { - $serviceObj = new $service($app); + $serviceObj = new $service($app); $this->services[$service] = $serviceObj; } } diff --git a/src/Websocket.php b/src/Websocket.php index 5d01d95..e3e95b5 100644 --- a/src/Websocket.php +++ b/src/Websocket.php @@ -47,8 +47,8 @@ class Websocket */ public function __construct(\think\App $app, Room $room, Event $event) { - $this->app = $app; - $this->room = $room; + $this->app = $app; + $this->room = $room; $this->event = $event; } diff --git a/src/concerns/InteractsWithHttp.php b/src/concerns/InteractsWithHttp.php index 2f69a52..04e3509 100644 --- a/src/concerns/InteractsWithHttp.php +++ b/src/concerns/InteractsWithHttp.php @@ -36,8 +36,8 @@ public function createHttpServer() { $this->preloadHttp(); - $host = $this->getConfig('http.host'); - $port = $this->getConfig('http.port'); + $host = $this->getConfig('http.host'); + $port = $this->getConfig('http.port'); $options = $this->getConfig('http.options', []); $server = new Server($host, $port, false, true); @@ -203,11 +203,11 @@ protected function getFiles(Request $req) if (!Arr::isAssoc($file)) { $files = []; foreach ($file as $f) { - $files['name'][] = $f['name']; - $files['type'][] = $f['type']; + $files['name'][] = $f['name']; + $files['type'][] = $f['type']; $files['tmp_name'][] = $f['tmp_name']; - $files['error'][] = $f['error']; - $files['size'][] = $f['size']; + $files['error'][] = $f['error']; + $files['size'][] = $f['size']; } return $files; } @@ -264,16 +264,16 @@ protected function sendIterator(Response $res, IteratorResponse $response) protected function sendFile(Response $res, \think\Request $request, FileResponse $response) { $ifNoneMatch = $request->header('If-None-Match'); - $ifRange = $request->header('If-Range'); + $ifRange = $request->header('If-Range'); - $code = $response->getCode(); - $file = $response->getFile(); - $eTag = $response->getHeader('ETag'); + $code = $response->getCode(); + $file = $response->getFile(); + $eTag = $response->getHeader('ETag'); $lastModified = $response->getHeader('Last-Modified'); $fileSize = $file->getSize(); - $offset = 0; - $length = -1; + $offset = 0; + $length = -1; if ($ifNoneMatch == $eTag) { $code = 304; @@ -286,7 +286,7 @@ protected function sendFile(Response $res, \think\Request $request, FileResponse if ('' === $start) { $start = $fileSize - $end; - $end = $fileSize - 1; + $end = $fileSize - 1; } else { $start = (int) $start; } @@ -301,9 +301,9 @@ protected function sendFile(Response $res, \think\Request $request, FileResponse } elseif ($end - $start < $fileSize - 1) { $length = $end < $fileSize ? $end - $start + 1 : -1; $offset = $start; - $code = 206; + $code = 206; $response->header([ - 'Content-Range' => sprintf('bytes %s-%s/%s', $start, $end, $fileSize), + 'Content-Range' => sprintf('bytes %s-%s/%s', $start, $end, $fileSize), 'Content-Length' => $end - $start + 1, ]); } @@ -329,7 +329,7 @@ protected function sendContent(Response $res, \think\Response $response) $content = $response->getContent(); if ($content) { $contentSize = strlen($content); - $chunkSize = 8192; + $chunkSize = 8192; if ($contentSize > $chunkSize) { $sendSize = 0; diff --git a/src/concerns/InteractsWithQueue.php b/src/concerns/InteractsWithQueue.php index 68c518c..88300c1 100644 --- a/src/concerns/InteractsWithQueue.php +++ b/src/concerns/InteractsWithQueue.php @@ -25,9 +25,9 @@ protected function createQueueWorkers() $workerNum = Arr::get($options, 'worker_num', 1); $this->addBatchWorker($workerNum, function (Process\Pool $pool) use ($options, $connection, $queue) { - $delay = Arr::get($options, 'delay', 0); - $sleep = Arr::get($options, 'sleep', 3); - $tries = Arr::get($options, 'tries', 0); + $delay = Arr::get($options, 'delay', 0); + $sleep = Arr::get($options, 'sleep', 3); + $tries = Arr::get($options, 'tries', 0); $timeout = Arr::get($options, 'timeout', 60); /** @var Worker $worker */ diff --git a/src/concerns/InteractsWithRpcClient.php b/src/concerns/InteractsWithRpcClient.php index 0fe30ba..f955667 100644 --- a/src/concerns/InteractsWithRpcClient.php +++ b/src/concerns/InteractsWithRpcClient.php @@ -40,10 +40,10 @@ protected function bindRpcInterface() try { foreach ($rpcServices as $name => $abstracts) { $parserClass = $this->getConfig("rpc.client.{$name}.parser", JsonParser::class); - $tries = $this->getConfig("rpc.client.{$name}.tries", 2); - $middleware = $this->getConfig("rpc.client.{$name}.middleware", []); + $tries = $this->getConfig("rpc.client.{$name}.tries", 2); + $middleware = $this->getConfig("rpc.client.{$name}.middleware", []); - $parser = $this->getApplication()->make($parserClass); + $parser = $this->getApplication()->make($parserClass); $gateway = new Gateway($this->createRpcConnector($name), $parser, $tries); foreach ($abstracts as $abstract) { diff --git a/src/concerns/InteractsWithRpcConnector.php b/src/concerns/InteractsWithRpcConnector.php index d64eb6c..728f072 100644 --- a/src/concerns/InteractsWithRpcConnector.php +++ b/src/concerns/InteractsWithRpcConnector.php @@ -16,7 +16,7 @@ abstract protected function runWithClient($callback); protected function recv(Client $client, callable $decoder) { $handler = null; - $file = null; + $file = null; while ($data = $client->recv()) { begin: diff --git a/src/concerns/InteractsWithRpcServer.php b/src/concerns/InteractsWithRpcServer.php index 6010a23..34b3dcc 100644 --- a/src/concerns/InteractsWithRpcServer.php +++ b/src/concerns/InteractsWithRpcServer.php @@ -96,7 +96,7 @@ protected function prepareRpcServer() protected function bindRpcDispatcher() { - $services = $this->getConfig('rpc.server.services', []); + $services = $this->getConfig('rpc.server.services', []); $middleware = $this->getConfig('rpc.server.middleware', []); $this->app->make(Dispatcher::class, [$services, $middleware]); diff --git a/src/concerns/InteractsWithServer.php b/src/concerns/InteractsWithServer.php index 1f71204..1bcdbb8 100644 --- a/src/concerns/InteractsWithServer.php +++ b/src/concerns/InteractsWithServer.php @@ -73,7 +73,7 @@ public function start(string $envName): void Runtime::enableCoroutine(); - $this->pool = $pool; + $this->pool = $pool; $this->workerId = $workerId; [$func, $name] = $this->startFuncMap[$workerId]; diff --git a/src/concerns/InteractsWithSwooleTable.php b/src/concerns/InteractsWithSwooleTable.php index 6ce7fb0..71b48a9 100644 --- a/src/concerns/InteractsWithSwooleTable.php +++ b/src/concerns/InteractsWithSwooleTable.php @@ -51,7 +51,7 @@ protected function registerTables() $tables = $this->container->make('config')->get('swoole.tables', []); foreach ($tables as $key => $value) { - $table = new SwooleTable($value['size']); + $table = new SwooleTable($value['size']); $columns = $value['columns'] ?? []; foreach ($columns as $column) { if (isset($column['size'])) { diff --git a/src/concerns/InteractsWithTracing.php b/src/concerns/InteractsWithTracing.php index 07c34af..de19e9e 100644 --- a/src/concerns/InteractsWithTracing.php +++ b/src/concerns/InteractsWithTracing.php @@ -17,7 +17,7 @@ trait InteractsWithTracing protected function prepareTracing() { if (class_exists(Tracer::class)) { - $tracers = $this->container->config->get('tracing.tracers'); + $tracers = $this->container->config->get('tracing.tracers'); $hasAsync = false; foreach ($tracers as $name => $tracer) { if (Arr::get($tracer, 'async', false)) { diff --git a/src/concerns/InteractsWithWebsocket.php b/src/concerns/InteractsWithWebsocket.php index 61058b6..f4afe06 100644 --- a/src/concerns/InteractsWithWebsocket.php +++ b/src/concerns/InteractsWithWebsocket.php @@ -91,9 +91,9 @@ public function onHandShake($req, $res) $this->runWithBarrier(function () use ($handler, $res) { - $cid = Coroutine::getCid(); + $cid = Coroutine::getCid(); $messages = 0; - $wait = false; + $wait = false; $frame = null; while (true) { @@ -104,10 +104,10 @@ public function onHandShake($req, $res) } if (empty($frame)) { - $frame = new Frame(); + $frame = new Frame(); $frame->opcode = $recv->opcode; - $frame->flags = $recv->flags; - $frame->fd = $recv->fd; + $frame->flags = $recv->flags; + $frame->fd = $recv->fd; $frame->finish = false; } diff --git a/src/concerns/WithMiddleware.php b/src/concerns/WithMiddleware.php index 0f41780..696d501 100644 --- a/src/concerns/WithMiddleware.php +++ b/src/concerns/WithMiddleware.php @@ -16,7 +16,7 @@ protected function middleware($middleware, ...$params) $this->middleware[] = [ 'middleware' => [$middleware, $params], - 'options' => &$options, + 'options' => &$options, ]; return new class($options) { diff --git a/src/concerns/WithRpcClient.php b/src/concerns/WithRpcClient.php index 62babb7..18fb373 100644 --- a/src/concerns/WithRpcClient.php +++ b/src/concerns/WithRpcClient.php @@ -48,10 +48,10 @@ protected function bindRpcInterface() $config = $this->app->config->get("swoole.rpc.client.{$name}", []); $parserClass = Arr::pull($config, 'parser', JsonParser::class); - $tries = Arr::pull($config, 'tries', 2); - $middleware = Arr::pull($config, 'middleware', []); + $tries = Arr::pull($config, 'tries', 2); + $middleware = Arr::pull($config, 'middleware', []); - $parser = $this->app->make($parserClass); + $parser = $this->app->make($parserClass); $gateway = new Gateway($config, $parser, $tries); foreach ($abstracts as $abstract) { diff --git a/src/config/swoole.php b/src/config/swoole.php index fdff932..e0b3857 100644 --- a/src/config/swoole.php +++ b/src/config/swoole.php @@ -1,98 +1,98 @@ [ - 'enable' => true, - 'host' => '0.0.0.0', - 'port' => 8080, + 'http' => [ + 'enable' => true, + 'host' => '0.0.0.0', + 'port' => 8080, 'worker_num' => swoole_cpu_num(), - 'options' => [], + 'options' => [], ], - 'websocket' => [ - 'enable' => false, - 'handler' => \think\swoole\websocket\Handler::class, + 'websocket' => [ + 'enable' => false, + 'handler' => \think\swoole\websocket\Handler::class, 'ping_interval' => 25000, - 'ping_timeout' => 60000, - 'room' => [ - 'type' => 'table', + 'ping_timeout' => 60000, + 'room' => [ + 'type' => 'table', 'table' => [ - 'room_rows' => 8192, - 'room_size' => 2048, + 'room_rows' => 8192, + 'room_size' => 2048, 'client_rows' => 4096, 'client_size' => 2048, ], 'redis' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'max_active' => 3, + 'host' => '127.0.0.1', + 'port' => 6379, + 'max_active' => 3, 'max_wait_time' => 5, ], ], - 'listen' => [], - 'subscribe' => [], + 'listen' => [], + 'subscribe' => [], ], - 'rpc' => [ + 'rpc' => [ 'server' => [ - 'enable' => false, - 'host' => '0.0.0.0', - 'port' => 9000, + 'enable' => false, + 'host' => '0.0.0.0', + 'port' => 9000, 'worker_num' => swoole_cpu_num(), - 'services' => [], + 'services' => [], ], 'client' => [], ], //队列 - 'queue' => [ - 'enable' => false, + 'queue' => [ + 'enable' => false, 'workers' => [], ], 'hot_update' => [ - 'enable' => env('APP_DEBUG', false), - 'name' => ['*.php'], + 'enable' => env('APP_DEBUG', false), + 'name' => ['*.php'], 'include' => [app_path()], 'exclude' => [], ], //连接池 - 'pool' => [ - 'db' => [ - 'enable' => true, - 'max_active' => 3, + 'pool' => [ + 'db' => [ + 'enable' => true, + 'max_active' => 3, 'max_wait_time' => 5, ], 'cache' => [ - 'enable' => true, - 'max_active' => 3, + 'enable' => true, + 'max_active' => 3, 'max_wait_time' => 5, ], //自定义连接池 ], - 'ipc' => [ - 'type' => 'unix_socket', + 'ipc' => [ + 'type' => 'unix_socket', 'redis' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'max_active' => 3, + 'host' => '127.0.0.1', + 'port' => 6379, + 'max_active' => 3, 'max_wait_time' => 5, ], ], //锁 - 'lock' => [ + 'lock' => [ 'enable' => false, - 'type' => 'table', - 'redis' => [ + 'type' => 'table', + 'redis' => [ 'host' => '127.0.0.1', - 'port' => 6379, - 'max_active' => 3, + 'port' => 6379, + 'max_active' => 3, 'max_wait_time' => 5, ], ], - 'tables' => [], + 'tables' => [], //每个worker里需要预加载以共用的实例 - 'concretes' => [], + 'concretes' => [], //重置器 - 'resetters' => [], + 'resetters' => [], //每次请求前需要清空的实例 - 'instances' => [], + 'instances' => [], //每次请求前需要重新执行的服务 - 'services' => [], + 'services' => [], ]; diff --git a/src/ipc/Driver.php b/src/ipc/Driver.php index 7ac72a5..d44ce18 100644 --- a/src/ipc/Driver.php +++ b/src/ipc/Driver.php @@ -17,7 +17,7 @@ abstract class Driver public function __construct(Manager $manager, array $config) { $this->manager = $manager; - $this->config = $config; + $this->config = $config; } public function listenMessage($workerId) diff --git a/src/middleware/TraceRpcClient.php b/src/middleware/TraceRpcClient.php index a82cdbb..792a414 100644 --- a/src/middleware/TraceRpcClient.php +++ b/src/middleware/TraceRpcClient.php @@ -22,7 +22,7 @@ public function __construct(Tracer $tracer) public function handle(Protocol $protocol, $next) { - $scope = $this->tracer->startActiveSpan( + $scope = $this->tracer->startActiveSpan( 'rpc.client:' . $protocol->getInterface() . '@' . $protocol->getMethod(), [ 'tags' => [ @@ -30,7 +30,7 @@ public function handle(Protocol $protocol, $next) ], ] ); - $span = $scope->getSpan(); + $span = $scope->getSpan(); $context = $protocol->getContext(); $this->tracer->inject($span->getContext(), TEXT_MAP, $context); $protocol->setContext($context); diff --git a/src/middleware/TraceRpcServer.php b/src/middleware/TraceRpcServer.php index b5e6cae..b88cb17 100644 --- a/src/middleware/TraceRpcServer.php +++ b/src/middleware/TraceRpcServer.php @@ -22,16 +22,16 @@ public function __construct(Tracer $tracer) public function handle(Protocol $protocol, $next) { $context = $this->tracer->extract(TEXT_MAP, $protocol->getContext()); - $scope = $this->tracer->startActiveSpan( + $scope = $this->tracer->startActiveSpan( 'rpc.server:' . $protocol->getInterface() . '@' . $protocol->getMethod(), [ 'child_of' => $context, - 'tags' => [ + 'tags' => [ SPAN_KIND => SPAN_KIND_RPC_SERVER, ], ] ); - $span = $scope->getSpan(); + $span = $scope->getSpan(); try { return $next($protocol); diff --git a/src/pool/Client.php b/src/pool/Client.php index b3dd378..8a98d6c 100644 --- a/src/pool/Client.php +++ b/src/pool/Client.php @@ -17,8 +17,8 @@ public function connect(array $config) { $client = new \Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); - $host = Arr::pull($config, 'host'); - $port = Arr::pull($config, 'port'); + $host = Arr::pull($config, 'host'); + $port = Arr::pull($config, 'port'); $timeout = Arr::pull($config, 'timeout', 5); $client->set($config); diff --git a/src/pool/Proxy.php b/src/pool/Proxy.php index b85c9fa..11fd4dd 100644 --- a/src/pool/Proxy.php +++ b/src/pool/Proxy.php @@ -32,7 +32,7 @@ abstract class Proxy */ public function __construct($connector, $config, array $connectionConfig = []) { - $this->released = new WeakMap(); + $this->released = new WeakMap(); $this->disconnected = new WeakMap(); if ($connector instanceof Closure) { diff --git a/src/response/File.php b/src/response/File.php index b8c2669..1f6a923 100644 --- a/src/response/File.php +++ b/src/response/File.php @@ -10,10 +10,10 @@ class File extends Response { public const DISPOSITION_ATTACHMENT = 'attachment'; - public const DISPOSITION_INLINE = 'inline'; + public const DISPOSITION_INLINE = 'inline'; protected $header = [ - 'Content-Type' => 'application/octet-stream', + 'Content-Type' => 'application/octet-stream', 'Accept-Ranges' => 'bytes', ]; diff --git a/src/rpc/Error.php b/src/rpc/Error.php index cbef217..24b6e53 100644 --- a/src/rpc/Error.php +++ b/src/rpc/Error.php @@ -30,9 +30,9 @@ public static function make(int $code, string $message, $data = null): self { $instance = new static(); - $instance->code = $code; + $instance->code = $code; $instance->message = $message; - $instance->data = $data; + $instance->data = $data; return $instance; } @@ -65,9 +65,9 @@ public function getData() public function jsonSerialize() { return [ - 'code' => $this->code, + 'code' => $this->code, 'message' => $this->message, - 'data' => $this->data, + 'data' => $this->data, ]; } } diff --git a/src/rpc/JsonParser.php b/src/rpc/JsonParser.php index 87556ca..a23237c 100644 --- a/src/rpc/JsonParser.php +++ b/src/rpc/JsonParser.php @@ -22,16 +22,16 @@ class JsonParser implements ParserInterface */ public function encode(Protocol $protocol): string { - $interface = $protocol->getInterface(); + $interface = $protocol->getInterface(); $methodName = $protocol->getMethod(); $method = $interface . self::DELIMITER . $methodName; - $data = [ + $data = [ 'jsonrpc' => self::VERSION, - 'method' => $method, - 'params' => $protocol->getParams(), + 'method' => $method, + 'params' => $protocol->getParams(), 'context' => $protocol->getContext(), - 'id' => '', + 'id' => '', ]; return json_encode($data, JSON_UNESCAPED_UNICODE); @@ -54,8 +54,8 @@ public function decode(string $string): Protocol ); } - $method = $data['method'] ?? ''; - $params = $data['params'] ?? []; + $method = $data['method'] ?? ''; + $params = $data['params'] ?? []; $context = $data['context'] ?? []; if (empty($method)) { @@ -98,9 +98,9 @@ public function decodeResponse(string $string) return $data['result']; } - $code = $data['error']['code'] ?? 0; + $code = $data['error']['code'] ?? 0; $message = $data['error']['message'] ?? ''; - $data = $data['error']['data'] ?? null; + $data = $data['error']['data'] ?? null; return Error::make($code, $message, $data); } @@ -114,7 +114,7 @@ public function encodeResponse($result): string { $data = [ 'jsonrpc' => self::VERSION, - 'id' => '', + 'id' => '', ]; if ($result instanceof Error) { diff --git a/src/rpc/Packer.php b/src/rpc/Packer.php index 46c4318..63d2f9f 100644 --- a/src/rpc/Packer.php +++ b/src/rpc/Packer.php @@ -8,12 +8,12 @@ class Packer { - public const HEADER_SIZE = 8; + public const HEADER_SIZE = 8; public const HEADER_STRUCT = 'Nlength/Ntype'; - public const HEADER_PACK = 'NN'; + public const HEADER_PACK = 'NN'; public const TYPE_BUFFER = 0; - public const TYPE_FILE = 1; + public const TYPE_FILE = 1; public static function pack($data, $type = self::TYPE_BUFFER) { diff --git a/src/rpc/Protocol.php b/src/rpc/Protocol.php index 1f843b5..0c38510 100644 --- a/src/rpc/Protocol.php +++ b/src/rpc/Protocol.php @@ -5,7 +5,7 @@ class Protocol { const ACTION_INTERFACE = '@action_interface'; - const FILE = '@file'; + const FILE = '@file'; /** * @var string @@ -41,9 +41,9 @@ public static function make(string $interface, string $method, array $params, ar $instance = new static(); $instance->interface = $interface; - $instance->method = $method; - $instance->params = $params; - $instance->context = $context; + $instance->method = $method; + $instance->params = $params; + $instance->context = $context; return $instance; } diff --git a/src/rpc/client/Gateway.php b/src/rpc/client/Gateway.php index fd96dda..ecc50d3 100644 --- a/src/rpc/client/Gateway.php +++ b/src/rpc/client/Gateway.php @@ -38,8 +38,8 @@ public function __construct($connector, ParserInterface $parser, $tries = 2) $connector = $this->createDefaultConnector($connector); } $this->connector = $connector; - $this->parser = $parser; - $this->tries = $tries; + $this->parser = $parser; + $this->tries = $tries; } protected function encodeData(Protocol $protocol) @@ -134,8 +134,8 @@ protected function getClient() $config = $this->config; - $host = Arr::pull($config, 'host'); - $port = Arr::pull($config, 'port'); + $host = Arr::pull($config, 'host'); + $port = Arr::pull($config, 'port'); $timeout = Arr::pull($config, 'timeout', 5); $client->set($config); diff --git a/src/rpc/client/Proxy.php b/src/rpc/client/Proxy.php index 9e175d6..6bb2f30 100644 --- a/src/rpc/client/Proxy.php +++ b/src/rpc/client/Proxy.php @@ -26,8 +26,8 @@ abstract class Proxy implements Service final public function __construct(App $app, Gateway $gateway, $middleware) { - $this->app = $app; - $this->gateway = $gateway; + $this->app = $app; + $this->gateway = $gateway; $this->middleware = $middleware; } @@ -79,7 +79,7 @@ final public static function getClassName($client, $interface) continue; } $method = (new Factory)->fromMethodReflection($methodRef); - $body = "\$this->proxyCall('{$methodRef->getName()}', func_get_args());"; + $body = "\$this->proxyCall('{$methodRef->getName()}', func_get_args());"; if ($method->getReturnType() != 'void') { $body = "return {$body}"; } diff --git a/src/rpc/packer/Buffer.php b/src/rpc/packer/Buffer.php index e84d279..68ec862 100644 --- a/src/rpc/packer/Buffer.php +++ b/src/rpc/packer/Buffer.php @@ -14,7 +14,7 @@ public function __construct($length) public function write(&$data) { - $size = strlen($this->data); + $size = strlen($this->data); $string = substr($data, 0, $this->length - $size); $this->data .= $string; diff --git a/src/rpc/packer/File.php b/src/rpc/packer/File.php index 8afd93f..7cd8685 100644 --- a/src/rpc/packer/File.php +++ b/src/rpc/packer/File.php @@ -16,11 +16,11 @@ public function __construct($length) public function write(&$data) { if (!$this->handle) { - $this->name = tempnam(sys_get_temp_dir(), 'swoole_rpc_'); + $this->name = tempnam(sys_get_temp_dir(), 'swoole_rpc_'); $this->handle = fopen($this->name, 'ab'); } - $size = fstat($this->handle)['size']; + $size = fstat($this->handle)['size']; $string = substr($data, 0, $this->length - $size); fwrite($this->handle, $string); diff --git a/src/rpc/server/Dispatcher.php b/src/rpc/server/Dispatcher.php index 2524fdd..2ad66a5 100644 --- a/src/rpc/server/Dispatcher.php +++ b/src/rpc/server/Dispatcher.php @@ -68,18 +68,18 @@ protected function prepareServices($services) { foreach ($services as $className) { $reflectionClass = new ReflectionClass($className); - $interfaces = $reflectionClass->getInterfaceNames(); + $interfaces = $reflectionClass->getInterfaceNames(); if (!empty($interfaces)) { foreach ($interfaces as $interface) { $this->services[class_basename($interface)] = [ 'interface' => $interface, - 'class' => $className, + 'class' => $className, ]; } } else { $this->services[class_basename($className)] = [ 'interface' => $className, - 'class' => $className, + 'class' => $className, ]; } } @@ -114,7 +114,7 @@ protected function getMethods($interface) $methods[$method->getName()] = [ 'parameters' => $this->getParameters($method), 'returnType' => $returnType, - 'comment' => $method->getDocComment(), + 'comment' => $method->getDocComment(), ]; } return $methods; @@ -165,7 +165,7 @@ public function dispatch(App $app, Connection $conn, $data, $files = []) break; default: $protocol = $this->parser->decode($data); - $result = $this->dispatchWithMiddleware($app, $protocol, $files); + $result = $this->dispatchWithMiddleware($app, $protocol, $files); } } catch (Throwable $e) { $result = Error::make($e->getCode(), $e->getMessage()); @@ -189,8 +189,8 @@ public function dispatch(App $app, Connection $conn, $data, $files = []) protected function dispatchWithMiddleware(App $app, Protocol $protocol, $files) { $interface = $protocol->getInterface(); - $method = $protocol->getMethod(); - $params = $protocol->getParams(); + $method = $protocol->getMethod(); + $params = $protocol->getParams(); //文件参数 foreach ($params as $index => $param) { @@ -207,7 +207,7 @@ protected function dispatchWithMiddleware(App $app, Protocol $protocol, $files) ); } - $instance = $app->make($service['class']); + $instance = $app->make($service['class']); $middlewares = array_merge($this->middleware, $this->getServiceMiddlewares($instance, $method)); return Middleware::make($app, $middlewares) @@ -231,13 +231,13 @@ protected function getServiceMiddlewares($service, $method) foreach ($reflectionProperty->getValue($service) as $key => $val) { if (!is_int($key)) { $middleware = $key; - $options = $val; + $options = $val; } elseif (isset($val['middleware'])) { $middleware = $val['middleware']; - $options = $val['options'] ?? []; + $options = $val['options'] ?? []; } else { $middleware = $val; - $options = []; + $options = []; } if ((isset($options['only']) && !in_array($method, (array) $options['only'])) || diff --git a/src/watcher/Find.php b/src/watcher/Find.php index 5eda275..32b629a 100644 --- a/src/watcher/Find.php +++ b/src/watcher/Find.php @@ -25,19 +25,19 @@ public function __construct($directory, $exclude, $name) } $this->directory = $directory; - $this->exclude = $exclude; - $this->name = $name; + $this->exclude = $exclude; + $this->name = $name; } public function watch(callable $callback) { - $ms = 2000; + $ms = 2000; $seconds = ceil(($ms + 1000) / 1000); $minutes = sprintf('-%.2f', $seconds / 60); $dest = implode(' ', $this->directory); - $name = empty($this->name) ? '' : ' \( ' . join(' -o ', array_map(fn ($v) => "-name \"{$v}\"", $this->name)) . ' \)'; + $name = empty($this->name) ? '' : ' \( ' . join(' -o ', array_map(fn ($v) => "-name \"{$v}\"", $this->name)) . ' \)'; $notName = ''; $notPath = ''; if (!empty($this->exclude)) { diff --git a/src/websocket/Pusher.php b/src/websocket/Pusher.php index 8da0e86..919e9e4 100644 --- a/src/websocket/Pusher.php +++ b/src/websocket/Pusher.php @@ -26,7 +26,7 @@ class Pusher public function __construct(Manager $manager, Room $room, HandlerInterface $handler) { $this->manager = $manager; - $this->room = $room; + $this->room = $room; $this->handler = $handler; } diff --git a/src/websocket/message/PushMessage.php b/src/websocket/message/PushMessage.php index 46fa407..1e5a691 100644 --- a/src/websocket/message/PushMessage.php +++ b/src/websocket/message/PushMessage.php @@ -9,7 +9,7 @@ class PushMessage public function __construct($fd, $data) { - $this->fd = $fd; + $this->fd = $fd; $this->data = $data; } } diff --git a/src/websocket/middleware/SessionInit.php b/src/websocket/middleware/SessionInit.php index b57597d..4eec1ba 100644 --- a/src/websocket/middleware/SessionInit.php +++ b/src/websocket/middleware/SessionInit.php @@ -18,7 +18,7 @@ class SessionInit public function __construct(App $app, Session $session) { - $this->app = $app; + $this->app = $app; $this->session = $session; } @@ -33,7 +33,7 @@ public function handle($request, Closure $next) { // Session初始化 $varSessionId = $this->app->config->get('session.var_session_id'); - $cookieName = $this->session->getName(); + $cookieName = $this->session->getName(); if ($varSessionId && $request->request($varSessionId)) { $sessionId = $request->request($varSessionId); diff --git a/src/websocket/room/Redis.php b/src/websocket/room/Redis.php index 9696027..13b89de 100644 --- a/src/websocket/room/Redis.php +++ b/src/websocket/room/Redis.php @@ -41,7 +41,7 @@ class Redis implements RoomInterface public function __construct(Manager $manager, array $config) { $this->manager = $manager; - $this->config = $config; + $this->config = $config; if ($prefix = Arr::get($this->config, 'prefix')) { $this->prefix = $prefix; @@ -61,7 +61,7 @@ public function prepare(): RoomInterface protected function prepareRedis() { $this->manager->onEvent('workerStart', function () { - $config = $this->config; + $config = $this->config; $this->pool = new ConnectionPool( Pool::pullPoolConfig($config), new PhpRedisConnector(), diff --git a/src/websocket/room/Table.php b/src/websocket/room/Table.php index 7b5fbe6..6a8f002 100644 --- a/src/websocket/room/Table.php +++ b/src/websocket/room/Table.php @@ -12,8 +12,8 @@ class Table implements RoomInterface * @var array */ protected $config = [ - 'room_rows' => 8192, - 'room_size' => 2048, + 'room_rows' => 8192, + 'room_size' => 2048, 'client_rows' => 4096, 'client_size' => 2048, ]; @@ -59,7 +59,7 @@ public function prepare(): RoomInterface */ public function add($fd, $roomNames) { - $rooms = $this->getRooms($fd); + $rooms = $this->getRooms($fd); $roomNames = is_array($roomNames) ? $roomNames : [$roomNames]; foreach ($roomNames as $room) { @@ -69,7 +69,7 @@ public function add($fd, $roomNames) continue; } - $fds[] = $fd; + $fds[] = $fd; $rooms[] = $room; $this->setClients($room, $fds); @@ -86,9 +86,9 @@ public function add($fd, $roomNames) */ public function delete($fd, $roomNames = []) { - $allRooms = $this->getRooms($fd); + $allRooms = $this->getRooms($fd); $roomNames = is_array($roomNames) ? $roomNames : [$roomNames]; - $rooms = count($roomNames) ? $roomNames : $allRooms; + $rooms = count($roomNames) ? $roomNames : $allRooms; $removeRooms = []; foreach ($rooms as $room) { diff --git a/src/websocket/socketio/Handler.php b/src/websocket/socketio/Handler.php index 4c7ac8a..3046cb8 100644 --- a/src/websocket/socketio/Handler.php +++ b/src/websocket/socketio/Handler.php @@ -31,11 +31,11 @@ class Handler implements HandlerInterface public function __construct(Event $event, Config $config, Websocket $websocket) { - $this->event = $event; - $this->config = $config; - $this->websocket = $websocket; + $this->event = $event; + $this->config = $config; + $this->websocket = $websocket; $this->pingInterval = $this->config->get('swoole.websocket.ping_interval', 25000); - $this->pingTimeout = $this->config->get('swoole.websocket.ping_timeout', 60000); + $this->pingTimeout = $this->config->get('swoole.websocket.ping_timeout', 60000); } /** @@ -49,10 +49,10 @@ public function onOpen(Request $request) $payload = json_encode( [ - 'sid' => base64_encode(uniqid()), - 'upgrades' => [], + 'sid' => base64_encode(uniqid()), + 'upgrades' => [], 'pingInterval' => $this->pingInterval, - 'pingTimeout' => $this->pingTimeout, + 'pingTimeout' => $this->pingTimeout, ] ); @@ -95,8 +95,8 @@ public function onMessage(Frame $frame) if ($packet->id !== null) { $responsePacket = Packet::create(Packet::ACK, [ - 'id' => $packet->id, - 'nsp' => $packet->nsp, + 'id' => $packet->id, + 'nsp' => $packet->nsp, 'data' => $result, ]); diff --git a/src/websocket/socketio/Packet.php b/src/websocket/socketio/Packet.php index bf6f6ae..bc83580 100644 --- a/src/websocket/socketio/Packet.php +++ b/src/websocket/socketio/Packet.php @@ -43,9 +43,9 @@ class Packet const BINARY_ACK = 6; public $type; - public $nsp = '/'; + public $nsp = '/'; public $data = null; - public $id = null; + public $id = null; public function __construct(int $type) { @@ -54,7 +54,7 @@ public function __construct(int $type) public static function create($type, array $decoded = []) { - $new = new static($type); + $new = new static($type); $new->id = $decoded['id'] ?? null; if (isset($decoded['nsp'])) { $new->nsp = $decoded['nsp'] ?: '/';