Quellcode durchsuchen

Remove prefix of protection properties

walkor vor 2 Jahren
Ursprung
Commit
7cf8b19c2d

+ 76 - 76
src/Connection/AsyncTcpConnection.php

@@ -57,49 +57,49 @@ class AsyncTcpConnection extends TcpConnection
      *
      * @var int
      */
-    protected $_status = self::STATUS_INITIAL;
+    protected $status = self::STATUS_INITIAL;
 
     /**
      * Remote host.
      *
      * @var string
      */
-    protected $_remoteHost = '';
+    protected $remoteHost = '';
 
     /**
      * Remote port.
      *
      * @var int
      */
-    protected $_remotePort = 80;
+    protected $remotePort = 80;
 
     /**
      * Connect start time.
      *
      * @var float
      */
-    protected $_connectStartTime = 0;
+    protected $connectStartTime = 0;
 
     /**
      * Remote URI.
      *
      * @var string
      */
-    protected $_remoteURI = '';
+    protected $remoteURI = '';
 
     /**
      * Context option.
      *
      * @var array
      */
-    protected $_contextOption = null;
+    protected $contextOption = null;
 
     /**
      * Reconnect timer.
      *
      * @var int
      */
-    protected $_reconnectTimer = null;
+    protected $reconnectTimer = null;
 
 
     /**
@@ -128,11 +128,11 @@ class AsyncTcpConnection extends TcpConnection
     {
         $address_info = \parse_url($remote_address);
         if (!$address_info) {
-            list($scheme, $this->_remoteAddress) = \explode(':', $remote_address, 2);
+            list($scheme, $this->remoteAddress) = \explode(':', $remote_address, 2);
             if ('unix' === strtolower($scheme)) {
-                $this->_remoteAddress = substr($remote_address, strpos($remote_address, '/') + 2);
+                $this->remoteAddress = substr($remote_address, strpos($remote_address, '/') + 2);
             }
-            if (!$this->_remoteAddress) {
+            if (!$this->remoteAddress) {
                 Worker::safeEcho(new \Exception('bad remote_address'));
             }
         } else {
@@ -147,18 +147,18 @@ class AsyncTcpConnection extends TcpConnection
             } else {
                 $address_info['query'] = '?' . $address_info['query'];
             }
-            $this->_remoteHost = $address_info['host'];
-            $this->_remotePort = $address_info['port'];
-            $this->_remoteURI = "{$address_info['path']}{$address_info['query']}";
+            $this->remoteHost = $address_info['host'];
+            $this->remotePort = $address_info['port'];
+            $this->remoteURI = "{$address_info['path']}{$address_info['query']}";
             $scheme = $address_info['scheme'] ?? 'tcp';
-            $this->_remoteAddress = 'unix' === strtolower($scheme)
+            $this->remoteAddress = 'unix' === strtolower($scheme)
                 ? substr($remote_address, strpos($remote_address, '/') + 2)
-                : $this->_remoteHost . ':' . $this->_remotePort;
+                : $this->remoteHost . ':' . $this->remotePort;
         }
 
-        $this->id = $this->realId = self::$_idRecorder++;
-        if (\PHP_INT_MAX === self::$_idRecorder) {
-            self::$_idRecorder = 0;
+        $this->id = $this->realId = self::$idRecorder++;
+        if (\PHP_INT_MAX === self::$idRecorder) {
+            self::$idRecorder = 0;
         }
         // Check application layer protocol class.
         if (!isset(self::BUILD_IN_TRANSPORTS[$scheme])) {
@@ -178,7 +178,7 @@ class AsyncTcpConnection extends TcpConnection
         ++self::$statistics['connection_count'];
         $this->maxSendBufferSize = self::$defaultMaxSendBufferSize;
         $this->maxPackageSize = self::$defaultMaxPackageSize;
-        $this->_contextOption = $context_option;
+        $this->contextOption = $context_option;
         static::$connections[$this->realId] = $this;
     }
 
@@ -189,64 +189,64 @@ class AsyncTcpConnection extends TcpConnection
      */
     public function connect()
     {
-        if ($this->_status !== self::STATUS_INITIAL && $this->_status !== self::STATUS_CLOSING &&
-            $this->_status !== self::STATUS_CLOSED) {
+        if ($this->status !== self::STATUS_INITIAL && $this->status !== self::STATUS_CLOSING &&
+            $this->status !== self::STATUS_CLOSED) {
             return;
         }
 
-        $this->_status = self::STATUS_CONNECTING;
-        $this->_connectStartTime = \microtime(true);
+        $this->status = self::STATUS_CONNECTING;
+        $this->connectStartTime = \microtime(true);
         if ($this->transport !== 'unix') {
-            if (!$this->_remotePort) {
-                $this->_remotePort = $this->transport === 'ssl' ? 443 : 80;
-                $this->_remoteAddress = $this->_remoteHost . ':' . $this->_remotePort;
+            if (!$this->remotePort) {
+                $this->remotePort = $this->transport === 'ssl' ? 443 : 80;
+                $this->remoteAddress = $this->remoteHost . ':' . $this->remotePort;
             }
             // Open socket connection asynchronously.
             if ($this->proxySocks5){
-                $this->_contextOption['ssl']['peer_name'] = $this->_remoteHost;
-                $context = \stream_context_create($this->_contextOption);
-                $this->_socket = \stream_socket_client("tcp://{$this->proxySocks5}", $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
-                fwrite($this->_socket,chr(5) . chr(1) . chr(0));
-                fread($this->_socket, 512);
-                fwrite($this->_socket,chr(5) . chr(1) . chr(0) . chr(3) . chr(strlen($this->_remoteHost)) . $this->_remoteHost .  pack("n", $this->_remotePort));
-                fread($this->_socket, 512);
+                $this->contextOption['ssl']['peer_name'] = $this->remoteHost;
+                $context = \stream_context_create($this->contextOption);
+                $this->socket = \stream_socket_client("tcp://{$this->proxySocks5}", $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
+                fwrite($this->socket,chr(5) . chr(1) . chr(0));
+                fread($this->socket, 512);
+                fwrite($this->socket,chr(5) . chr(1) . chr(0) . chr(3) . chr(strlen($this->remoteHost)) . $this->remoteHost .  pack("n", $this->remotePort));
+                fread($this->socket, 512);
             }else if($this->proxyHttp){
-                $this->_contextOption['ssl']['peer_name'] = $this->_remoteHost;
-                $context = \stream_context_create($this->_contextOption);
-                $this->_socket = \stream_socket_client("tcp://{$this->proxyHttp}", $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
-                $str = "CONNECT {$this->_remoteHost}:{$this->_remotePort} HTTP/1.1\n";
-                $str .= "Host: {$this->_remoteHost}:{$this->_remotePort}\n";
+                $this->contextOption['ssl']['peer_name'] = $this->remoteHost;
+                $context = \stream_context_create($this->contextOption);
+                $this->socket = \stream_socket_client("tcp://{$this->proxyHttp}", $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
+                $str = "CONNECT {$this->remoteHost}:{$this->remotePort} HTTP/1.1\n";
+                $str .= "Host: {$this->remoteHost}:{$this->remotePort}\n";
                 $str .= "Proxy-Connection: keep-alive\n";
-                fwrite($this->_socket,$str);
-                fread($this->_socket, 512);
-            } else if ($this->_contextOption) {
-                $context = \stream_context_create($this->_contextOption);
-                $this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
+                fwrite($this->socket,$str);
+                fread($this->socket, 512);
+            } else if ($this->contextOption) {
+                $context = \stream_context_create($this->contextOption);
+                $this->socket = \stream_socket_client("tcp://{$this->remoteHost}:{$this->remotePort}",
                     $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
             } else {
-                $this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
+                $this->socket = \stream_socket_client("tcp://{$this->remoteHost}:{$this->remotePort}",
                     $errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT);
             }
         } else {
-            $this->_socket = \stream_socket_client("{$this->transport}://{$this->_remoteAddress}", $errno, $errstr, 0,
+            $this->socket = \stream_socket_client("{$this->transport}://{$this->remoteAddress}", $errno, $errstr, 0,
                 \STREAM_CLIENT_ASYNC_CONNECT);
         }
         // If failed attempt to emit onError callback.
-        if (!$this->_socket || !\is_resource($this->_socket)) {
+        if (!$this->socket || !\is_resource($this->socket)) {
             $this->emitError(static::CONNECT_FAIL, $errstr);
-            if ($this->_status === self::STATUS_CLOSING) {
+            if ($this->status === self::STATUS_CLOSING) {
                 $this->destroy();
             }
-            if ($this->_status === self::STATUS_CLOSED) {
+            if ($this->status === self::STATUS_CLOSED) {
                 $this->onConnect = null;
             }
             return;
         }
         // Add socket to global event loop waiting connection is successfully established or faild.
-        Worker::$globalEvent->onWritable($this->_socket, [$this, 'checkConnection']);
+        Worker::$globalEvent->onWritable($this->socket, [$this, 'checkConnection']);
         // For windows.
         if (\DIRECTORY_SEPARATOR === '\\') {
-            Worker::$globalEvent->onExcept($this->_socket, [$this, 'checkConnection']);
+            Worker::$globalEvent->onExcept($this->socket, [$this, 'checkConnection']);
         }
     }
 
@@ -258,13 +258,13 @@ class AsyncTcpConnection extends TcpConnection
      */
     public function reconnect($after = 0)
     {
-        $this->_status = self::STATUS_INITIAL;
+        $this->status = self::STATUS_INITIAL;
         static::$connections[$this->realId] = $this;
-        if ($this->_reconnectTimer) {
-            Timer::del($this->_reconnectTimer);
+        if ($this->reconnectTimer) {
+            Timer::del($this->reconnectTimer);
         }
         if ($after > 0) {
-            $this->_reconnectTimer = Timer::add($after, [$this, 'connect'], null, false);
+            $this->reconnectTimer = Timer::add($after, [$this, 'connect'], null, false);
             return;
         }
         $this->connect();
@@ -275,8 +275,8 @@ class AsyncTcpConnection extends TcpConnection
      */
     public function cancelReconnect()
     {
-        if ($this->_reconnectTimer) {
-            Timer::del($this->_reconnectTimer);
+        if ($this->reconnectTimer) {
+            Timer::del($this->reconnectTimer);
         }
     }
 
@@ -287,7 +287,7 @@ class AsyncTcpConnection extends TcpConnection
      */
     public function getRemoteHost()
     {
-        return $this->_remoteHost;
+        return $this->remoteHost;
     }
 
     /**
@@ -297,7 +297,7 @@ class AsyncTcpConnection extends TcpConnection
      */
     public function getRemoteURI()
     {
-        return $this->_remoteURI;
+        return $this->remoteURI;
     }
 
     /**
@@ -309,7 +309,7 @@ class AsyncTcpConnection extends TcpConnection
      */
     protected function emitError($code, $msg)
     {
-        $this->_status = self::STATUS_CLOSING;
+        $this->status = self::STATUS_CLOSING;
         if ($this->onError) {
             try {
                 ($this->onError)($this, $code, $msg);
@@ -329,46 +329,46 @@ class AsyncTcpConnection extends TcpConnection
     {
         // Remove EV_EXPECT for windows.
         if (\DIRECTORY_SEPARATOR === '\\') {
-            Worker::$globalEvent->offExcept($this->_socket);
+            Worker::$globalEvent->offExcept($this->socket);
         }
         // Remove write listener.
-        Worker::$globalEvent->offWritable($this->_socket);
+        Worker::$globalEvent->offWritable($this->socket);
 
-        if ($this->_status !== self::STATUS_CONNECTING) {
+        if ($this->status !== self::STATUS_CONNECTING) {
             return;
         }
 
         // Check socket state.
-        if ($address = \stream_socket_get_name($this->_socket, true)) {
+        if ($address = \stream_socket_get_name($this->socket, true)) {
             // Nonblocking.
-            \stream_set_blocking($this->_socket, false);
+            \stream_set_blocking($this->socket, false);
             // Compatible with hhvm
             if (\function_exists('stream_set_read_buffer')) {
-                \stream_set_read_buffer($this->_socket, 0);
+                \stream_set_read_buffer($this->socket, 0);
             }
             // Try to open keepalive for tcp and disable Nagle algorithm.
             if (\function_exists('socket_import_stream') && $this->transport === 'tcp') {
-                $raw_socket = \socket_import_stream($this->_socket);
+                $raw_socket = \socket_import_stream($this->socket);
                 \socket_set_option($raw_socket, \SOL_SOCKET, \SO_KEEPALIVE, 1);
                 \socket_set_option($raw_socket, \SOL_TCP, \TCP_NODELAY, 1);
             }
             // SSL handshake.
             if ($this->transport === 'ssl') {
-                $this->_sslHandshakeCompleted = $this->doSslHandshake($this->_socket);
-                if ($this->_sslHandshakeCompleted === false) {
+                $this->sslHandshakeCompleted = $this->doSslHandshake($this->socket);
+                if ($this->sslHandshakeCompleted === false) {
                     return;
                 }
             } else {
                 // There are some data waiting to send.
-                if ($this->_sendBuffer) {
-                    Worker::$globalEvent->onWritable($this->_socket, [$this, 'baseWrite']);
+                if ($this->sendBuffer) {
+                    Worker::$globalEvent->onWritable($this->socket, [$this, 'baseWrite']);
                 }
             }
             // Register a listener waiting read event.
-            Worker::$globalEvent->onReadable($this->_socket, [$this, 'baseRead']);
+            Worker::$globalEvent->onReadable($this->socket, [$this, 'baseRead']);
 
-            $this->_status = self::STATUS_ESTABLISHED;
-            $this->_remoteAddress = $address;
+            $this->status = self::STATUS_ESTABLISHED;
+            $this->remoteAddress = $address;
 
             // Try to emit onConnect callback.
             if ($this->onConnect) {
@@ -388,11 +388,11 @@ class AsyncTcpConnection extends TcpConnection
             }
         } else {
             // Connection failed.
-            $this->emitError(static::CONNECT_FAIL, 'connect ' . $this->_remoteAddress . ' fail after ' . round(\microtime(true) - $this->_connectStartTime, 4) . ' seconds');
-            if ($this->_status === self::STATUS_CLOSING) {
+            $this->emitError(static::CONNECT_FAIL, 'connect ' . $this->remoteAddress . ' fail after ' . round(\microtime(true) - $this->connectStartTime, 4) . ' seconds');
+            if ($this->status === self::STATUS_CLOSING) {
                 $this->destroy();
             }
-            if ($this->_status === self::STATUS_CLOSED) {
+            if ($this->status === self::STATUS_CLOSED) {
                 $this->onConnect = null;
             }
         }

+ 13 - 13
src/Connection/AsyncUdpConnection.php

@@ -49,7 +49,7 @@ class AsyncUdpConnection extends UdpConnection
      *
      * @var array
      */
-    protected $_contextOption = null;
+    protected $contextOption = null;
 
     /**
      * Construct.
@@ -73,8 +73,8 @@ class AsyncUdpConnection extends UdpConnection
             }
         }
 
-        $this->_remoteAddress = \substr($address, 2);
-        $this->_contextOption = $context_option;
+        $this->remoteAddress = \substr($address, 2);
+        $this->contextOption = $context_option;
     }
 
     /**
@@ -123,7 +123,7 @@ class AsyncUdpConnection extends UdpConnection
         if ($this->connected === false) {
             $this->connect();
         }
-        return \strlen($send_buffer) === \stream_socket_sendto($this->_socket, $send_buffer, 0);
+        return \strlen($send_buffer) === \stream_socket_sendto($this->socket, $send_buffer, 0);
     }
 
 
@@ -140,8 +140,8 @@ class AsyncUdpConnection extends UdpConnection
         if ($data !== null) {
             $this->send($data, $raw);
         }
-        Worker::$globalEvent->offReadable($this->_socket);
-        \fclose($this->_socket);
+        Worker::$globalEvent->offReadable($this->socket);
+        \fclose($this->socket);
         $this->connected = false;
         // Try to emit onClose callback.
         if ($this->onClose) {
@@ -165,23 +165,23 @@ class AsyncUdpConnection extends UdpConnection
         if ($this->connected === true) {
             return;
         }
-        if ($this->_contextOption) {
-            $context = \stream_context_create($this->_contextOption);
-            $this->_socket = \stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg,
+        if ($this->contextOption) {
+            $context = \stream_context_create($this->contextOption);
+            $this->socket = \stream_socket_client("udp://{$this->remoteAddress}", $errno, $errmsg,
                 30, \STREAM_CLIENT_CONNECT, $context);
         } else {
-            $this->_socket = \stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg);
+            $this->socket = \stream_socket_client("udp://{$this->remoteAddress}", $errno, $errmsg);
         }
 
-        if (!$this->_socket) {
+        if (!$this->socket) {
             Worker::safeEcho(new \Exception($errmsg));
             return;
         }
 
-        \stream_set_blocking($this->_socket, false);
+        \stream_set_blocking($this->socket, false);
 
         if ($this->onMessage) {
-            Worker::$globalEvent->onWritable($this->_socket, [$this, 'baseRead']);
+            Worker::$globalEvent->onWritable($this->socket, [$this, 'baseRead']);
         }
         $this->connected = true;
         // Try to emit onConnect callback.

+ 103 - 103
src/Connection/TcpConnection.php

@@ -148,7 +148,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      *
      * @var int
      */
-    protected $_id = 0;
+    protected $realId = 0;
 
     /**
      * Sets the maximum send buffer size for the current connection.
@@ -191,70 +191,70 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      *
      * @var int
      */
-    protected static $_idRecorder = 1;
+    protected static $idRecorder = 1;
 
     /**
      * Cache.
      *
      * @var bool.
      */
-    protected static $_enableCache = true;
+    protected static $enableCache = true;
 
     /**
      * Socket
      *
      * @var resource
      */
-    protected $_socket = null;
+    protected $socket = null;
 
     /**
      * Send buffer.
      *
      * @var string
      */
-    protected $_sendBuffer = '';
+    protected $sendBuffer = '';
 
     /**
      * Receive buffer.
      *
      * @var string
      */
-    protected $_recvBuffer = '';
+    protected $recvBuffer = '';
 
     /**
      * Current package length.
      *
      * @var int
      */
-    protected $_currentPackageLength = 0;
+    protected $currentPackageLength = 0;
 
     /**
      * Connection status.
      *
      * @var int
      */
-    protected $_status = self::STATUS_ESTABLISHED;
+    protected $status = self::STATUS_ESTABLISHED;
 
     /**
      * Remote address.
      *
      * @var string
      */
-    protected $_remoteAddress = '';
+    protected $remoteAddress = '';
 
     /**
      * Is paused.
      *
      * @var bool
      */
-    protected $_isPaused = false;
+    protected $isPaused = false;
 
     /**
      * SSL handshake completed or not.
      *
      * @var bool
      */
-    protected $_sslHandshakeCompleted = false;
+    protected $sslHandshakeCompleted = false;
 
     /**
      * All connection instances.
@@ -268,7 +268,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      *
      * @var array
      */
-    public static $_statusToString = [
+    public static $statusToString = [
         self::STATUS_INITIAL => 'INITIAL',
         self::STATUS_CONNECTING => 'CONNECTING',
         self::STATUS_ESTABLISHED => 'ESTABLISHED',
@@ -285,20 +285,20 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
     public function __construct($socket, $remote_address = '')
     {
         ++self::$statistics['connection_count'];
-        $this->id = $this->realId = self::$_idRecorder++;
-        if (self::$_idRecorder === \PHP_INT_MAX) {
-            self::$_idRecorder = 0;
+        $this->id = $this->realId = self::$idRecorder++;
+        if (self::$idRecorder === \PHP_INT_MAX) {
+            self::$idRecorder = 0;
         }
-        $this->_socket = $socket;
-        \stream_set_blocking($this->_socket, 0);
+        $this->socket = $socket;
+        \stream_set_blocking($this->socket, 0);
         // Compatible with hhvm
         if (\function_exists('stream_set_read_buffer')) {
-            \stream_set_read_buffer($this->_socket, 0);
+            \stream_set_read_buffer($this->socket, 0);
         }
-        Worker::$globalEvent->onReadable($this->_socket, [$this, 'baseRead']);
+        Worker::$globalEvent->onReadable($this->socket, [$this, 'baseRead']);
         $this->maxSendBufferSize = self::$defaultMaxSendBufferSize;
         $this->maxPackageSize = self::$defaultMaxPackageSize;
-        $this->_remoteAddress = $remote_address;
+        $this->remoteAddress = $remote_address;
         static::$connections[$this->id] = $this;
         $this->context = new \stdClass;
     }
@@ -313,9 +313,9 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
     public function getStatus($raw_output = true)
     {
         if ($raw_output) {
-            return $this->_status;
+            return $this->status;
         }
-        return self::$_statusToString[$this->_status];
+        return self::$statusToString[$this->status];
     }
 
     /**
@@ -327,7 +327,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function send($send_buffer, $raw = false)
     {
-        if ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
+        if ($this->status === self::STATUS_CLOSING || $this->status === self::STATUS_CLOSED) {
             return false;
         }
 
@@ -339,29 +339,29 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             }
         }
 
-        if ($this->_status !== self::STATUS_ESTABLISHED ||
-            ($this->transport === 'ssl' && $this->_sslHandshakeCompleted !== true)
+        if ($this->status !== self::STATUS_ESTABLISHED ||
+            ($this->transport === 'ssl' && $this->sslHandshakeCompleted !== true)
         ) {
-            if ($this->_sendBuffer && $this->bufferIsFull()) {
+            if ($this->sendBuffer && $this->bufferIsFull()) {
                 ++self::$statistics['send_fail'];
                 return false;
             }
-            $this->_sendBuffer .= $send_buffer;
+            $this->sendBuffer .= $send_buffer;
             $this->checkBufferWillFull();
             return;
         }
 
         // Attempt to send data directly.
-        if ($this->_sendBuffer === '') {
+        if ($this->sendBuffer === '') {
             if ($this->transport === 'ssl') {
-                Worker::$globalEvent->onWritable($this->_socket, [$this, 'baseWrite']);
-                $this->_sendBuffer = $send_buffer;
+                Worker::$globalEvent->onWritable($this->socket, [$this, 'baseWrite']);
+                $this->sendBuffer = $send_buffer;
                 $this->checkBufferWillFull();
                 return;
             }
             $len = 0;
             try {
-                $len = @\fwrite($this->_socket, $send_buffer);
+                $len = @\fwrite($this->socket, $send_buffer);
             } catch (\Throwable $e) {
                 Worker::log($e);
             }
@@ -372,11 +372,11 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             }
             // Send only part of the data.
             if ($len > 0) {
-                $this->_sendBuffer = \substr($send_buffer, $len);
+                $this->sendBuffer = \substr($send_buffer, $len);
                 $this->bytesWritten += $len;
             } else {
                 // Connection closed?
-                if (!\is_resource($this->_socket) || \feof($this->_socket)) {
+                if (!\is_resource($this->socket) || \feof($this->socket)) {
                     ++self::$statistics['send_fail'];
                     if ($this->onError) {
                         try {
@@ -388,9 +388,9 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
                     $this->destroy();
                     return false;
                 }
-                $this->_sendBuffer = $send_buffer;
+                $this->sendBuffer = $send_buffer;
             }
-            Worker::$globalEvent->onWritable($this->_socket, [$this, 'baseWrite']);
+            Worker::$globalEvent->onWritable($this->socket, [$this, 'baseWrite']);
             // Check if the send buffer will be full.
             $this->checkBufferWillFull();
             return;
@@ -401,7 +401,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             return false;
         }
 
-        $this->_sendBuffer .= $send_buffer;
+        $this->sendBuffer .= $send_buffer;
         // Check if the send buffer is full.
         $this->checkBufferWillFull();
     }
@@ -413,9 +413,9 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemoteIp()
     {
-        $pos = \strrpos($this->_remoteAddress, ':');
+        $pos = \strrpos($this->remoteAddress, ':');
         if ($pos) {
-            return (string)\substr($this->_remoteAddress, 0, $pos);
+            return (string)\substr($this->remoteAddress, 0, $pos);
         }
         return '';
     }
@@ -427,8 +427,8 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemotePort()
     {
-        if ($this->_remoteAddress) {
-            return (int)\substr(\strrchr($this->_remoteAddress, ':'), 1);
+        if ($this->remoteAddress) {
+            return (int)\substr(\strrchr($this->remoteAddress, ':'), 1);
         }
         return 0;
     }
@@ -440,7 +440,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemoteAddress()
     {
-        return $this->_remoteAddress;
+        return $this->remoteAddress;
     }
 
     /**
@@ -480,10 +480,10 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getLocalAddress()
     {
-        if (!\is_resource($this->_socket)) {
+        if (!\is_resource($this->socket)) {
             return '';
         }
-        return (string)@\stream_socket_get_name($this->_socket, false);
+        return (string)@\stream_socket_get_name($this->socket, false);
     }
 
     /**
@@ -493,7 +493,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getSendBufferQueueSize()
     {
-        return \strlen($this->_sendBuffer);
+        return \strlen($this->sendBuffer);
     }
 
     /**
@@ -503,7 +503,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRecvBufferQueueSize()
     {
-        return \strlen($this->_recvBuffer);
+        return \strlen($this->recvBuffer);
     }
 
     /**
@@ -539,8 +539,8 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function pauseRecv()
     {
-        Worker::$globalEvent->offReadable($this->_socket);
-        $this->_isPaused = true;
+        Worker::$globalEvent->offReadable($this->socket);
+        $this->isPaused = true;
     }
 
     /**
@@ -550,10 +550,10 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function resumeRecv()
     {
-        if ($this->_isPaused === true) {
-            Worker::$globalEvent->onReadable($this->_socket, [$this, 'baseRead']);
-            $this->_isPaused = false;
-            $this->baseRead($this->_socket, false);
+        if ($this->isPaused === true) {
+            Worker::$globalEvent->onReadable($this->socket, [$this, 'baseRead']);
+            $this->isPaused = false;
+            $this->baseRead($this->socket, false);
         }
     }
 
@@ -569,10 +569,10 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
     {
         static $requests = [];
         // SSL handshake.
-        if ($this->transport === 'ssl' && $this->_sslHandshakeCompleted !== true) {
+        if ($this->transport === 'ssl' && $this->sslHandshakeCompleted !== true) {
             if ($this->doSslHandshake($socket)) {
-                $this->_sslHandshakeCompleted = true;
-                if ($this->_sendBuffer) {
+                $this->sslHandshakeCompleted = true;
+                if ($this->sendBuffer) {
                     Worker::$globalEvent->onWritable($socket, [$this, 'baseWrite']);
                 }
             } else {
@@ -594,15 +594,15 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             }
         } else {
             $this->bytesRead += \strlen($buffer);
-            if ($this->_recvBuffer === '') {
-                if (static::$_enableCache && !isset($buffer[512]) && isset($requests[$buffer])) {
+            if ($this->recvBuffer === '') {
+                if (static::$enableCache && !isset($buffer[512]) && isset($requests[$buffer])) {
                     ++self::$statistics['total_request'];
                     $request = $requests[$buffer];
                     if ($request instanceof Request) {
                         $request = clone $request;
                         $requests[$buffer] = $request;
                         $request->connection = $this;
-                        $this->__request = $request;
+                        $this->request = $request;
                         $request->properties = [];
                     }
                     try {
@@ -612,38 +612,38 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
                     }
                     return;
                 }
-                $this->_recvBuffer = $buffer;
+                $this->recvBuffer = $buffer;
             } else {
-                $this->_recvBuffer .= $buffer;
+                $this->recvBuffer .= $buffer;
             }
         }
 
         // If the application layer protocol has been set up.
         if ($this->protocol !== null) {
-            while ($this->_recvBuffer !== '' && !$this->_isPaused) {
+            while ($this->recvBuffer !== '' && !$this->isPaused) {
                 // The current packet length is known.
-                if ($this->_currentPackageLength) {
+                if ($this->currentPackageLength) {
                     // Data is not enough for a package.
-                    if ($this->_currentPackageLength > \strlen($this->_recvBuffer)) {
+                    if ($this->currentPackageLength > \strlen($this->recvBuffer)) {
                         break;
                     }
                 } else {
                     // Get current package length.
                     try {
-                        $this->_currentPackageLength = $this->protocol::input($this->_recvBuffer, $this);
+                        $this->currentPackageLength = $this->protocol::input($this->recvBuffer, $this);
                     } catch (\Throwable $e) {
                     }
                     // The packet length is unknown.
-                    if ($this->_currentPackageLength === 0) {
+                    if ($this->currentPackageLength === 0) {
                         break;
-                    } elseif ($this->_currentPackageLength > 0 && $this->_currentPackageLength <= $this->maxPackageSize) {
+                    } elseif ($this->currentPackageLength > 0 && $this->currentPackageLength <= $this->maxPackageSize) {
                         // Data is not enough for a package.
-                        if ($this->_currentPackageLength > \strlen($this->_recvBuffer)) {
+                        if ($this->currentPackageLength > \strlen($this->recvBuffer)) {
                             break;
                         }
                     } // Wrong package.
                     else {
-                        Worker::safeEcho('Error package. package_length=' . \var_export($this->_currentPackageLength, true));
+                        Worker::safeEcho('Error package. package_length=' . \var_export($this->currentPackageLength, true));
                         $this->destroy();
                         return;
                     }
@@ -652,21 +652,21 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
                 // The data is enough for a packet.
                 ++self::$statistics['total_request'];
                 // The current packet length is equal to the length of the buffer.
-                if ($one = \strlen($this->_recvBuffer) === $this->_currentPackageLength) {
-                    $one_request_buffer = $this->_recvBuffer;
-                    $this->_recvBuffer = '';
+                if ($one = \strlen($this->recvBuffer) === $this->currentPackageLength) {
+                    $one_request_buffer = $this->recvBuffer;
+                    $this->recvBuffer = '';
                 } else {
                     // Get a full package from the buffer.
-                    $one_request_buffer = \substr($this->_recvBuffer, 0, $this->_currentPackageLength);
+                    $one_request_buffer = \substr($this->recvBuffer, 0, $this->currentPackageLength);
                     // Remove the current package from the receive buffer.
-                    $this->_recvBuffer = \substr($this->_recvBuffer, $this->_currentPackageLength);
+                    $this->recvBuffer = \substr($this->recvBuffer, $this->currentPackageLength);
                 }
                 // Reset the current packet length to 0.
-                $this->_currentPackageLength = 0;
+                $this->currentPackageLength = 0;
                 try {
                     // Decode request buffer before Emitting onMessage callback.
                     $request = $this->protocol::decode($one_request_buffer, $this);
-                    if (static::$_enableCache && (!\is_object($request) || $request instanceof Request) && $one && !isset($one_request_buffer[512])) {
+                    if (static::$enableCache && (!\is_object($request) || $request instanceof Request) && $one && !isset($one_request_buffer[512])) {
                         $requests[$one_request_buffer] = $request;
                         if (\count($requests) > 512) {
                             unset($requests[\key($requests)]);
@@ -680,19 +680,19 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             return;
         }
 
-        if ($this->_recvBuffer === '' || $this->_isPaused) {
+        if ($this->recvBuffer === '' || $this->isPaused) {
             return;
         }
 
         // Applications protocol is not set.
         ++self::$statistics['total_request'];
         try {
-            ($this->onMessage)($this, $this->_recvBuffer);
+            ($this->onMessage)($this, $this->recvBuffer);
         } catch (\Throwable $e) {
             Worker::stopAll(250, $e);
         }
         // Clean receive buffer.
-        $this->_recvBuffer = '';
+        $this->recvBuffer = '';
     }
 
     /**
@@ -705,15 +705,15 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
         \set_error_handler(function () {
         });
         if ($this->transport === 'ssl') {
-            $len = @\fwrite($this->_socket, $this->_sendBuffer, 8192);
+            $len = @\fwrite($this->socket, $this->sendBuffer, 8192);
         } else {
-            $len = @\fwrite($this->_socket, $this->_sendBuffer);
+            $len = @\fwrite($this->socket, $this->sendBuffer);
         }
         \restore_error_handler();
-        if ($len === \strlen($this->_sendBuffer)) {
+        if ($len === \strlen($this->sendBuffer)) {
             $this->bytesWritten += $len;
-            Worker::$globalEvent->offWritable($this->_socket);
-            $this->_sendBuffer = '';
+            Worker::$globalEvent->offWritable($this->socket);
+            $this->sendBuffer = '';
             // Try to emit onBufferDrain callback when the send buffer becomes empty.
             if ($this->onBufferDrain) {
                 try {
@@ -722,7 +722,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
                     Worker::stopAll(250, $e);
                 }
             }
-            if ($this->_status === self::STATUS_CLOSING) {
+            if ($this->status === self::STATUS_CLOSING) {
                 if ($this->context->streamSending) {
                     return true;
                 }
@@ -732,7 +732,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
         }
         if ($len > 0) {
             $this->bytesWritten += $len;
-            $this->_sendBuffer = \substr($this->_sendBuffer, $len);
+            $this->sendBuffer = \substr($this->sendBuffer, $len);
         } else {
             ++self::$statistics['send_fail'];
             $this->destroy();
@@ -826,7 +826,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function consumeRecvBuffer($length)
     {
-        $this->_recvBuffer = \substr($this->_recvBuffer, $length);
+        $this->recvBuffer = \substr($this->recvBuffer, $length);
     }
 
     /**
@@ -838,12 +838,12 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function close($data = null, $raw = false)
     {
-        if ($this->_status === self::STATUS_CONNECTING) {
+        if ($this->status === self::STATUS_CONNECTING) {
             $this->destroy();
             return;
         }
 
-        if ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
+        if ($this->status === self::STATUS_CLOSING || $this->status === self::STATUS_CLOSED) {
             return;
         }
 
@@ -851,9 +851,9 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
             $this->send($data, $raw);
         }
 
-        $this->_status = self::STATUS_CLOSING;
+        $this->status = self::STATUS_CLOSING;
 
-        if ($this->_sendBuffer === '') {
+        if ($this->sendBuffer === '') {
             $this->destroy();
         } else {
             $this->pauseRecv();
@@ -867,7 +867,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getSocket()
     {
-        return $this->_socket;
+        return $this->socket;
     }
 
     /**
@@ -877,7 +877,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     protected function checkBufferWillFull()
     {
-        if ($this->maxSendBufferSize <= \strlen($this->_sendBuffer)) {
+        if ($this->maxSendBufferSize <= \strlen($this->sendBuffer)) {
             if ($this->onBufferFull) {
                 try {
                     ($this->onBufferFull)($this);
@@ -896,7 +896,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
     protected function bufferIsFull()
     {
         // Buffer has been marked as full but still has data to send then the packet is discarded.
-        if ($this->maxSendBufferSize <= \strlen($this->_sendBuffer)) {
+        if ($this->maxSendBufferSize <= \strlen($this->sendBuffer)) {
             if ($this->onError) {
                 try {
                     ($this->onError)($this, static::SEND_FAIL, 'send buffer full and drop package');
@@ -916,7 +916,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function bufferIsEmpty()
     {
-        return empty($this->_sendBuffer);
+        return empty($this->sendBuffer);
     }
 
     /**
@@ -927,20 +927,20 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
     public function destroy()
     {
         // Avoid repeated calls.
-        if ($this->_status === self::STATUS_CLOSED) {
+        if ($this->status === self::STATUS_CLOSED) {
             return;
         }
         // Remove event listener.
-        Worker::$globalEvent->offReadable($this->_socket);
-        Worker::$globalEvent->offWritable($this->_socket);
+        Worker::$globalEvent->offReadable($this->socket);
+        Worker::$globalEvent->offWritable($this->socket);
 
         // Close socket.
         try {
-            @\fclose($this->_socket);
+            @\fclose($this->socket);
         } catch (\Throwable $e) {
         }
 
-        $this->_status = self::STATUS_CLOSED;
+        $this->status = self::STATUS_CLOSED;
         // Try to emit onClose callback.
         if ($this->onClose) {
             try {
@@ -957,10 +957,10 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
                 Worker::stopAll(250, $e);
             }
         }
-        $this->_sendBuffer = $this->_recvBuffer = '';
-        $this->_currentPackageLength = 0;
-        $this->_isPaused = $this->_sslHandshakeCompleted = false;
-        if ($this->_status === self::STATUS_CLOSED) {
+        $this->sendBuffer = $this->recvBuffer = '';
+        $this->currentPackageLength = 0;
+        $this->isPaused = $this->sslHandshakeCompleted = false;
+        if ($this->status === self::STATUS_CLOSED) {
             // Cleaning up the callback to avoid memory leaks.
             $this->onMessage = $this->onClose = $this->onError = $this->onBufferFull = $this->onBufferDrain = null;
             // Remove from worker->connections.
@@ -978,7 +978,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public static function enableCache($value)
     {
-        static::$_enableCache = (bool)$value;
+        static::$enableCache = (bool)$value;
     }
     
     /**

+ 12 - 12
src/Connection/UdpConnection.php

@@ -39,14 +39,14 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      *
      * @var resource
      */
-    protected $_socket = null;
+    protected $socket = null;
 
     /**
      * Remote address.
      *
      * @var string
      */
-    protected $_remoteAddress = '';
+    protected $remoteAddress = '';
 
     /**
      * Construct.
@@ -56,8 +56,8 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function __construct($socket, $remote_address)
     {
-        $this->_socket = $socket;
-        $this->_remoteAddress = $remote_address;
+        $this->socket = $socket;
+        $this->remoteAddress = $remote_address;
     }
 
     /**
@@ -76,7 +76,7 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
                 return;
             }
         }
-        return \strlen($send_buffer) === \stream_socket_sendto($this->_socket, $send_buffer, 0, $this->isIpV6() ? '[' . $this->getRemoteIp() . ']:' . $this->getRemotePort() : $this->_remoteAddress);
+        return \strlen($send_buffer) === \stream_socket_sendto($this->socket, $send_buffer, 0, $this->isIpV6() ? '[' . $this->getRemoteIp() . ']:' . $this->getRemotePort() : $this->remoteAddress);
     }
 
     /**
@@ -86,9 +86,9 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemoteIp()
     {
-        $pos = \strrpos($this->_remoteAddress, ':');
+        $pos = \strrpos($this->remoteAddress, ':');
         if ($pos) {
-            return \trim(\substr($this->_remoteAddress, 0, $pos), '[]');
+            return \trim(\substr($this->remoteAddress, 0, $pos), '[]');
         }
         return '';
     }
@@ -100,8 +100,8 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemotePort()
     {
-        if ($this->_remoteAddress) {
-            return (int)\substr(\strrchr($this->_remoteAddress, ':'), 1);
+        if ($this->remoteAddress) {
+            return (int)\substr(\strrchr($this->remoteAddress, ':'), 1);
         }
         return 0;
     }
@@ -113,7 +113,7 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getRemoteAddress()
     {
-        return $this->_remoteAddress;
+        return $this->remoteAddress;
     }
 
     /**
@@ -153,7 +153,7 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getLocalAddress()
     {
-        return (string)@\stream_socket_get_name($this->_socket, false);
+        return (string)@\stream_socket_get_name($this->socket, false);
     }
 
     /**
@@ -204,7 +204,7 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      */
     public function getSocket()
     {
-        return $this->_socket;
+        return $this->socket;
     }
     
     /**

+ 29 - 29
src/Events/Ev.php

@@ -26,48 +26,48 @@ class Ev implements EventInterface
      *
      * @var array
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for write event.
      *
      * @var array
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * Event listeners of signal.
      *
      * @var array
      */
-    protected $_eventSignal = [];
+    protected $eventSignal = [];
 
     /**
      * All timer event listeners.
      *
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * Timer id.
      *
      * @var int
      */
-    protected static $_timerId = 1;
+    protected static $timerId = 1;
 
     /**
      * {@inheritdoc}
      */
     public function delay(float $delay, $func, $args)
     {
-        $timer_id = self::$_timerId;
+        $timer_id = self::$timerId;
         $event = new \EvTimer($delay, 0, function () use ($func, $args, $timer_id) {
-            unset($this->_eventTimer[$timer_id]);
+            unset($this->eventTimer[$timer_id]);
             $func(...(array)$args);
         });
-        $this->_eventTimer[self::$_timerId] = $event;
-        return self::$_timerId++;
+        $this->eventTimer[self::$timerId] = $event;
+        return self::$timerId++;
     }
 
     /**
@@ -75,9 +75,9 @@ class Ev implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
-            $this->_eventTimer[$timer_id]->stop();
-            unset($this->_eventTimer[$timer_id]);
+        if (isset($this->eventTimer[$timer_id])) {
+            $this->eventTimer[$timer_id]->stop();
+            unset($this->eventTimer[$timer_id]);
             return true;
         }
         return false;
@@ -91,8 +91,8 @@ class Ev implements EventInterface
         $event = new \EvTimer($interval, $interval, function () use ($func, $args) {
             $func(...(array)$args);
         });
-        $this->_eventTimer[self::$_timerId] = $event;
-        return self::$_timerId++;
+        $this->eventTimer[self::$timerId] = $event;
+        return self::$timerId++;
     }
 
     /**
@@ -104,7 +104,7 @@ class Ev implements EventInterface
         $event = new \EvIo($stream, \Ev::READ, function () use ($func, $stream) {
             $func($stream);
         });
-        $this->_readEvents[$fd_key] = $event;
+        $this->readEvents[$fd_key] = $event;
     }
 
     /**
@@ -113,9 +113,9 @@ class Ev implements EventInterface
     public function offReadable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_readEvents[$fd_key])) {
-            $this->_readEvents[$fd_key]->stop();
-            unset($this->_readEvents[$fd_key]);
+        if (isset($this->readEvents[$fd_key])) {
+            $this->readEvents[$fd_key]->stop();
+            unset($this->readEvents[$fd_key]);
         }
     }
 
@@ -128,7 +128,7 @@ class Ev implements EventInterface
         $event = new \EvIo($stream, \Ev::WRITE, function () use ($func, $stream) {
             $func($stream);
         });
-        $this->_readEvents[$fd_key] = $event;
+        $this->readEvents[$fd_key] = $event;
     }
 
     /**
@@ -137,9 +137,9 @@ class Ev implements EventInterface
     public function offWritable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_writeEvents[$fd_key])) {
-            $this->_writeEvents[$fd_key]->stop();
-            unset($this->_writeEvents[$fd_key]);
+        if (isset($this->writeEvents[$fd_key])) {
+            $this->writeEvents[$fd_key]->stop();
+            unset($this->writeEvents[$fd_key]);
         }
     }
 
@@ -151,7 +151,7 @@ class Ev implements EventInterface
         $event = new \EvSignal($signal, function () use ($func, $signal) {
             $func($signal);
         });
-        $this->_eventSignal[$signal] = $event;
+        $this->eventSignal[$signal] = $event;
     }
 
     /**
@@ -159,9 +159,9 @@ class Ev implements EventInterface
      */
     public function offSignal($signal)
     {
-        if (isset($this->_eventSignal[$signal])) {
-            $this->_eventSignal[$signal]->stop();
-            unset($this->_eventSignal[$signal]);
+        if (isset($this->eventSignal[$signal])) {
+            $this->eventSignal[$signal]->stop();
+            unset($this->eventSignal[$signal]);
         }
     }
 
@@ -170,10 +170,10 @@ class Ev implements EventInterface
      */
     public function deleteAllTimer()
     {
-        foreach ($this->_eventTimer as $event) {
+        foreach ($this->eventTimer as $event) {
             $event->stop();
         }
-        $this->_eventTimer = [];
+        $this->eventTimer = [];
     }
 
     /**
@@ -197,7 +197,7 @@ class Ev implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 
 }

+ 43 - 43
src/Events/Event.php

@@ -25,44 +25,44 @@ class Event implements EventInterface
      * Event base.
      * @var object
      */
-    protected $_eventBase = null;
+    protected $eventBase = null;
 
     /**
      * All listeners for read event.
      * @var array
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for write event.
      * @var array
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * Event listeners of signal.
      * @var array
      */
-    protected $_eventSignal = [];
+    protected $eventSignal = [];
 
     /**
      * All timer event listeners.
      * [func, args, event, flag, time_interval]
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * Timer id.
      * @var int
      */
-    protected $_timerId = 0;
+    protected $timerId = 0;
 
     /**
      * Event class name.
      * @var string
      */
-    protected $_eventClassName = '';
+    protected $eventClassName = '';
 
     /**
      * Construct.
@@ -75,13 +75,13 @@ class Event implements EventInterface
         } else {
             $class_name = '\Event';
         }
-        $this->_eventClassName = $class_name;
+        $this->eventClassName = $class_name;
         if (\class_exists('\\\\EventBase', false)) {
             $class_name = '\\\\EventBase';
         } else {
             $class_name = '\EventBase';
         }
-        $this->_eventBase = new $class_name();
+        $this->eventBase = new $class_name();
     }
 
     /**
@@ -89,9 +89,9 @@ class Event implements EventInterface
      */
     public function delay(float $delay, $func, $args)
     {
-        $class_name = $this->_eventClassName;
-        $timer_id = $this->_timerId++;
-        $event = new $class_name($this->_eventBase, -1, $class_name::TIMEOUT, function () use ($func, $args, $timer_id) {
+        $class_name = $this->eventClassName;
+        $timer_id = $this->timerId++;
+        $event = new $class_name($this->eventBase, -1, $class_name::TIMEOUT, function () use ($func, $args, $timer_id) {
             try {
                 $this->deleteTimer($timer_id);
                 $func(...$args);
@@ -102,7 +102,7 @@ class Event implements EventInterface
         if (!$event || !$event->addTimer($delay)) {
             return false;
         }
-        $this->_eventTimer[$timer_id] = $event;
+        $this->eventTimer[$timer_id] = $event;
         return $timer_id;
     }
 
@@ -111,9 +111,9 @@ class Event implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
-            $this->_eventTimer[$timer_id]->del();
-            unset($this->_eventTimer[$timer_id]);
+        if (isset($this->eventTimer[$timer_id])) {
+            $this->eventTimer[$timer_id]->del();
+            unset($this->eventTimer[$timer_id]);
             return true;
         }
         return false;
@@ -124,9 +124,9 @@ class Event implements EventInterface
      */
     public function repeat(float $interval, $func, $args)
     {
-        $class_name = $this->_eventClassName;
-        $timer_id = $this->_timerId++;
-        $event = new $class_name($this->_eventBase, -1, $class_name::TIMEOUT | $class_name::PERSIST, function () use ($func, $args) {
+        $class_name = $this->eventClassName;
+        $timer_id = $this->timerId++;
+        $event = new $class_name($this->eventBase, -1, $class_name::TIMEOUT | $class_name::PERSIST, function () use ($func, $args) {
             try {
                 $func(...$args);
             } catch (\Throwable $e) {
@@ -136,7 +136,7 @@ class Event implements EventInterface
         if (!$event || !$event->addTimer($interval)) {
             return false;
         }
-        $this->_eventTimer[$timer_id] = $event;
+        $this->eventTimer[$timer_id] = $event;
         return $timer_id;
     }
 
@@ -145,13 +145,13 @@ class Event implements EventInterface
      */
     public function onReadable($stream, $func)
     {
-        $class_name = $this->_eventClassName;
+        $class_name = $this->eventClassName;
         $fd_key = (int)$stream;
-        $event = new $this->_eventClassName($this->_eventBase, $stream, $class_name::READ | $class_name::PERSIST, $func, $stream);
+        $event = new $this->eventClassName($this->eventBase, $stream, $class_name::READ | $class_name::PERSIST, $func, $stream);
         if (!$event || !$event->add()) {
             return false;
         }
-        $this->_writeEvents[$fd_key] = $event;
+        $this->writeEvents[$fd_key] = $event;
         return true;
     }
 
@@ -161,9 +161,9 @@ class Event implements EventInterface
     public function offReadable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_readEvents[$fd_key])) {
-            $this->_readEvents[$fd_key]->del();
-            unset($this->_readEvents[$fd_key]);
+        if (isset($this->readEvents[$fd_key])) {
+            $this->readEvents[$fd_key]->del();
+            unset($this->readEvents[$fd_key]);
         }
     }
 
@@ -172,13 +172,13 @@ class Event implements EventInterface
      */
     public function onWritable($stream, $func)
     {
-        $class_name = $this->_eventClassName;
+        $class_name = $this->eventClassName;
         $fd_key = (int)$stream;
-        $event = new $this->_eventClassName($this->_eventBase, $stream, $class_name::WRITE | $class_name::PERSIST, $func, $stream);
+        $event = new $this->eventClassName($this->eventBase, $stream, $class_name::WRITE | $class_name::PERSIST, $func, $stream);
         if (!$event || !$event->add()) {
             return false;
         }
-        $this->_writeEvents[$fd_key] = $event;
+        $this->writeEvents[$fd_key] = $event;
         return true;
     }
 
@@ -188,9 +188,9 @@ class Event implements EventInterface
     public function offWritable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_writeEvents[$fd_key])) {
-            $this->_writeEvents[$fd_key]->del();
-            unset($this->_writeEvents[$fd_key]);
+        if (isset($this->writeEvents[$fd_key])) {
+            $this->writeEvents[$fd_key]->del();
+            unset($this->writeEvents[$fd_key]);
         }
     }
 
@@ -199,13 +199,13 @@ class Event implements EventInterface
      */
     public function onSignal($signal, $func)
     {
-        $class_name = $this->_eventClassName;
+        $class_name = $this->eventClassName;
         $fd_key = (int)$signal;
-        $event = $class_name::signal($this->_eventBase, $signal, $func);
+        $event = $class_name::signal($this->eventBase, $signal, $func);
         if (!$event || !$event->add()) {
             return false;
         }
-        $this->_eventSignal[$fd_key] = $event;
+        $this->eventSignal[$fd_key] = $event;
         return true;
     }
 
@@ -215,9 +215,9 @@ class Event implements EventInterface
     public function offSignal($signal)
     {
         $fd_key = (int)$signal;
-        if (isset($this->_eventSignal[$fd_key])) {
-            $this->_eventSignal[$fd_key]->del();
-            unset($this->_eventSignal[$fd_key]);
+        if (isset($this->eventSignal[$fd_key])) {
+            $this->eventSignal[$fd_key]->del();
+            unset($this->eventSignal[$fd_key]);
         }
     }
 
@@ -226,10 +226,10 @@ class Event implements EventInterface
      */
     public function deleteAllTimer()
     {
-        foreach ($this->_eventTimer as $event) {
+        foreach ($this->eventTimer as $event) {
             $event->del();
         }
-        $this->_eventTimer = [];
+        $this->eventTimer = [];
     }
 
     /**
@@ -237,7 +237,7 @@ class Event implements EventInterface
      */
     public function run()
     {
-        $this->_eventBase->loop();
+        $this->eventBase->loop();
     }
 
     /**
@@ -245,7 +245,7 @@ class Event implements EventInterface
      */
     public function stop()
     {
-        $this->_eventBase->exit();
+        $this->eventBase->exit();
     }
 
     /**
@@ -253,6 +253,6 @@ class Event implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 }

+ 47 - 47
src/Events/Revolt.php

@@ -25,44 +25,44 @@ class Revolt implements EventInterface
     /**
      * @var Driver
      */
-    protected $_driver = null;
+    protected $driver = null;
 
     /**
      * All listeners for read event.
      * @var array
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for write event.
      * @var array
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * Event listeners of signal.
      * @var array
      */
-    protected $_eventSignal = [];
+    protected $eventSignal = [];
 
     /**
      * Event listeners of timer.
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * Timer id.
      * @var int
      */
-    protected $_timerId = 1;
+    protected $timerId = 1;
 
     /**
      * Construct.
      */
     public function __construct()
     {
-        $this->_driver = EventLoop::getDriver();
+        $this->driver = EventLoop::getDriver();
     }
 
     /**
@@ -70,7 +70,7 @@ class Revolt implements EventInterface
      */
     public function driver()
     {
-        return $this->_driver;
+        return $this->driver;
     }
 
     /**
@@ -78,7 +78,7 @@ class Revolt implements EventInterface
      */
     public function run()
     {
-        $this->_driver->run();
+        $this->driver->run();
     }
 
     /**
@@ -86,10 +86,10 @@ class Revolt implements EventInterface
      */
     public function stop()
     {
-        foreach ($this->_eventSignal as $cb_id) {
-            $this->_driver->cancel($cb_id);
+        foreach ($this->eventSignal as $cb_id) {
+            $this->driver->cancel($cb_id);
         }
-        $this->_driver->stop();
+        $this->driver->stop();
         pcntl_signal(SIGINT, SIG_IGN);
     }
 
@@ -99,13 +99,13 @@ class Revolt implements EventInterface
     public function delay(float $delay, $func, $args)
     {
         $args = (array)$args;
-        $timer_id = $this->_timerId++;
+        $timer_id = $this->timerId++;
         $closure = function () use ($func, $args, $timer_id) {
-            unset($this->_eventTimer[$timer_id]);
+            unset($this->eventTimer[$timer_id]);
             $func(...$args);
         };
-        $cb_id = $this->_driver->delay($delay, $closure);
-        $this->_eventTimer[$timer_id] = $cb_id;
+        $cb_id = $this->driver->delay($delay, $closure);
+        $this->eventTimer[$timer_id] = $cb_id;
         return $timer_id;
     }
 
@@ -115,12 +115,12 @@ class Revolt implements EventInterface
     public function repeat(float $interval, $func, $args)
     {
         $args = (array)$args;
-        $timer_id = $this->_timerId++;
+        $timer_id = $this->timerId++;
         $closure = function () use ($func, $args, $timer_id) {
             $func(...$args);
         };
-        $cb_id = $this->_driver->repeat($interval, $closure);
-        $this->_eventTimer[$timer_id] = $cb_id;
+        $cb_id = $this->driver->repeat($interval, $closure);
+        $this->eventTimer[$timer_id] = $cb_id;
         return $timer_id;
     }
 
@@ -130,12 +130,12 @@ class Revolt implements EventInterface
     public function onReadable($stream, $func)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_readEvents[$fd_key])) {
-            $this->_driver->cancel($this->_readEvents[$fd_key]);
-            unset($this->_readEvents[$fd_key]);
+        if (isset($this->readEvents[$fd_key])) {
+            $this->driver->cancel($this->readEvents[$fd_key]);
+            unset($this->readEvents[$fd_key]);
         }
 
-        $this->_readEvents[$fd_key] = $this->_driver->onReadable($stream, function () use ($stream, $func) {
+        $this->readEvents[$fd_key] = $this->driver->onReadable($stream, function () use ($stream, $func) {
             $func($stream);
         });
     }
@@ -146,9 +146,9 @@ class Revolt implements EventInterface
     public function offReadable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_readEvents[$fd_key])) {
-            $this->_driver->cancel($this->_readEvents[$fd_key]);
-            unset($this->_readEvents[$fd_key]);
+        if (isset($this->readEvents[$fd_key])) {
+            $this->driver->cancel($this->readEvents[$fd_key]);
+            unset($this->readEvents[$fd_key]);
         }
     }
 
@@ -158,11 +158,11 @@ class Revolt implements EventInterface
     public function onWritable($stream, $func)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_writeEvents[$fd_key])) {
-            $this->_driver->cancel($this->_writeEvents[$fd_key]);
-            unset($this->_writeEvents[$fd_key]);
+        if (isset($this->writeEvents[$fd_key])) {
+            $this->driver->cancel($this->writeEvents[$fd_key]);
+            unset($this->writeEvents[$fd_key]);
         }
-        $this->_writeEvents[$fd_key] = $this->_driver->onWritable($stream, function () use ($stream, $func) {
+        $this->writeEvents[$fd_key] = $this->driver->onWritable($stream, function () use ($stream, $func) {
             $func($stream);
         });
     }
@@ -173,9 +173,9 @@ class Revolt implements EventInterface
     public function offWritable($stream)
     {
         $fd_key = (int)$stream;
-        if (isset($this->_writeEvents[$fd_key])) {
-            $this->_driver->cancel($this->_writeEvents[$fd_key]);
-            unset($this->_writeEvents[$fd_key]);
+        if (isset($this->writeEvents[$fd_key])) {
+            $this->driver->cancel($this->writeEvents[$fd_key]);
+            unset($this->writeEvents[$fd_key]);
         }
     }
 
@@ -185,11 +185,11 @@ class Revolt implements EventInterface
     public function onSignal($signal, $func)
     {
         $fd_key = (int)$signal;
-        if (isset($this->_eventSignal[$fd_key])) {
-            $this->_driver->cancel($this->_eventSignal[$fd_key]);
-            unset($this->_eventSignal[$fd_key]);
+        if (isset($this->eventSignal[$fd_key])) {
+            $this->driver->cancel($this->eventSignal[$fd_key]);
+            unset($this->eventSignal[$fd_key]);
         }
-        $this->_eventSignal[$fd_key] = $this->_driver->onSignal($signal, function () use ($signal, $func) {
+        $this->eventSignal[$fd_key] = $this->driver->onSignal($signal, function () use ($signal, $func) {
             $func($signal);
         });
     }
@@ -200,9 +200,9 @@ class Revolt implements EventInterface
     public function offSignal($signal)
     {
         $fd_key = (int)$signal;
-        if (isset($this->_eventSignal[$fd_key])) {
-            $this->_driver->cancel($this->_eventSignal[$fd_key]);
-            unset($this->_eventSignal[$fd_key]);
+        if (isset($this->eventSignal[$fd_key])) {
+            $this->driver->cancel($this->eventSignal[$fd_key]);
+            unset($this->eventSignal[$fd_key]);
         }
     }
 
@@ -211,9 +211,9 @@ class Revolt implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
-            $this->_driver->cancel($this->_eventTimer[$timer_id]);
-            unset($this->_eventTimer[$timer_id]);
+        if (isset($this->eventTimer[$timer_id])) {
+            $this->driver->cancel($this->eventTimer[$timer_id]);
+            unset($this->eventTimer[$timer_id]);
             return true;
         }
         return false;
@@ -224,10 +224,10 @@ class Revolt implements EventInterface
      */
     public function deleteAllTimer()
     {
-        foreach ($this->_eventTimer as $cb_id) {
-            $this->_driver->cancel($cb_id);
+        foreach ($this->eventTimer as $cb_id) {
+            $this->driver->cancel($cb_id);
         }
-        $this->_eventTimer = [];
+        $this->eventTimer = [];
     }
 
     /**
@@ -235,6 +235,6 @@ class Revolt implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 }

+ 71 - 71
src/Events/Select.php

@@ -27,47 +27,47 @@ class Select implements EventInterface
      *
      * @var array
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for read/write event.
      *
      * @var array
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * @var array
      */
-    protected $_exceptEvents = [];
+    protected $exceptEvents = [];
 
     /**
      * Event listeners of signal.
      *
      * @var array
      */
-    protected $_signalEvents = [];
+    protected $signalEvents = [];
 
     /**
      * Fds waiting for read event.
      *
      * @var array
      */
-    protected $_readFds = [];
+    protected $readFds = [];
 
     /**
      * Fds waiting for write event.
      *
      * @var array
      */
-    protected $_writeFds = [];
+    protected $writeFds = [];
 
     /**
      * Fds waiting for except event.
      *
      * @var array
      */
-    protected $_exceptFds = [];
+    protected $exceptFds = [];
 
     /**
      * Timer scheduler.
@@ -75,7 +75,7 @@ class Select implements EventInterface
      *
      * @var \SplPriorityQueue
      */
-    protected $_scheduler = null;
+    protected $scheduler = null;
 
     /**
      * All timer event listeners.
@@ -83,21 +83,21 @@ class Select implements EventInterface
      *
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * Timer id.
      *
      * @var int
      */
-    protected $_timerId = 1;
+    protected $timerId = 1;
 
     /**
      * Select timeout.
      *
      * @var int
      */
-    protected $_selectTimeout = 100000000;
+    protected $selectTimeout = 100000000;
 
     /**
      * Construct.
@@ -105,8 +105,8 @@ class Select implements EventInterface
     public function __construct()
     {
         // Init SplPriorityQueue.
-        $this->_scheduler = new \SplPriorityQueue();
-        $this->_scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
+        $this->scheduler = new \SplPriorityQueue();
+        $this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
     }
 
     /**
@@ -114,14 +114,14 @@ class Select implements EventInterface
      */
     public function delay(float $delay, $func, $args)
     {
-        $timer_id = $this->_timerId++;
+        $timer_id = $this->timerId++;
         $run_time = \microtime(true) + $delay;
-        $this->_scheduler->insert($timer_id, -$run_time);
-        $this->_eventTimer[$timer_id] = [$func, (array)$args];
+        $this->scheduler->insert($timer_id, -$run_time);
+        $this->eventTimer[$timer_id] = [$func, (array)$args];
         $select_timeout = ($run_time - \microtime(true)) * 1000000;
         $select_timeout = $select_timeout <= 0 ? 1 : (int)$select_timeout;
-        if ($this->_selectTimeout > $select_timeout) {
-            $this->_selectTimeout = $select_timeout;
+        if ($this->selectTimeout > $select_timeout) {
+            $this->selectTimeout = $select_timeout;
         }
         return $timer_id;
     }
@@ -131,14 +131,14 @@ class Select implements EventInterface
      */
     public function repeat(float $delay, $func, $args)
     {
-        $timer_id = $this->_timerId++;
+        $timer_id = $this->timerId++;
         $run_time = \microtime(true) + $delay;
-        $this->_scheduler->insert($timer_id, -$run_time);
-        $this->_eventTimer[$timer_id] = [$func, (array)$args, $delay];
+        $this->scheduler->insert($timer_id, -$run_time);
+        $this->eventTimer[$timer_id] = [$func, (array)$args, $delay];
         $select_timeout = ($run_time - \microtime(true)) * 1000000;
         $select_timeout = $select_timeout <= 0 ? 1 : (int)$select_timeout;
-        if ($this->_selectTimeout > $select_timeout) {
-            $this->_selectTimeout = $select_timeout;
+        if ($this->selectTimeout > $select_timeout) {
+            $this->selectTimeout = $select_timeout;
         }
         return $timer_id;
     }
@@ -148,8 +148,8 @@ class Select implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
-            unset($this->_eventTimer[$timer_id]);
+        if (isset($this->eventTimer[$timer_id])) {
+            unset($this->eventTimer[$timer_id]);
             return true;
         }
         return false;
@@ -160,15 +160,15 @@ class Select implements EventInterface
      */
     public function onReadable($stream, $func)
     {
-        $count = \count($this->_readFds);
+        $count = \count($this->readFds);
         if ($count >= 1024) {
             echo "Warning: system call select exceeded the maximum number of connections 1024, please install event/libevent extension for more connections.\n";
         } else if (\DIRECTORY_SEPARATOR !== '/' && $count >= 256) {
             echo "Warning: system call select exceeded the maximum number of connections 256.\n";
         }
         $fd_key = (int)$stream;
-        $this->_readEvents[$fd_key] = $func;
-        $this->_readFds[$fd_key] = $stream;
+        $this->readEvents[$fd_key] = $func;
+        $this->readFds[$fd_key] = $stream;
     }
 
     /**
@@ -177,7 +177,7 @@ class Select implements EventInterface
     public function offReadable($stream)
     {
         $fd_key = (int)$stream;
-        unset($this->_readEvents[$fd_key], $this->_readFds[$fd_key]);
+        unset($this->readEvents[$fd_key], $this->readFds[$fd_key]);
     }
 
     /**
@@ -185,15 +185,15 @@ class Select implements EventInterface
      */
     public function onWritable($stream, $func)
     {
-        $count = \count($this->_writeFds);
+        $count = \count($this->writeFds);
         if ($count >= 1024) {
             echo "Warning: system call select exceeded the maximum number of connections 1024, please install event/libevent extension for more connections.\n";
         } else if (\DIRECTORY_SEPARATOR !== '/' && $count >= 256) {
             echo "Warning: system call select exceeded the maximum number of connections 256.\n";
         }
         $fd_key = (int)$stream;
-        $this->_writeEvents[$fd_key] = $func;
-        $this->_writeFds[$fd_key] = $stream;
+        $this->writeEvents[$fd_key] = $func;
+        $this->writeFds[$fd_key] = $stream;
     }
 
     /**
@@ -202,7 +202,7 @@ class Select implements EventInterface
     public function offWritable($stream)
     {
         $fd_key = (int)$stream;
-        unset($this->_writeEvents[$fd_key], $this->_writeFds[$fd_key]);
+        unset($this->writeEvents[$fd_key], $this->writeFds[$fd_key]);
     }
 
     /**
@@ -211,8 +211,8 @@ class Select implements EventInterface
     public function onExcept($stream, $func)
     {
         $fd_key = (int)$stream;
-        $this->_exceptEvents[$fd_key] = $func;
-        $this->_exceptFds[$fd_key] = $stream;
+        $this->exceptEvents[$fd_key] = $func;
+        $this->exceptFds[$fd_key] = $stream;
     }
 
     /**
@@ -221,7 +221,7 @@ class Select implements EventInterface
     public function offExcept($stream)
     {
         $fd_key = (int)$stream;
-        unset($this->_exceptEvents[$fd_key], $this->_exceptFds[$fd_key]);
+        unset($this->exceptEvents[$fd_key], $this->exceptFds[$fd_key]);
     }
 
     /**
@@ -232,7 +232,7 @@ class Select implements EventInterface
         if (\DIRECTORY_SEPARATOR !== '/') {
             return null;
         }
-        $this->_signalEvents[$signal] = $func;
+        $this->signalEvents[$signal] = $func;
         \pcntl_signal($signal, [$this, 'signalHandler']);
     }
 
@@ -241,7 +241,7 @@ class Select implements EventInterface
      */
     public function offsignal($signal)
     {
-        unset($this->_signalEvents[$signal]);
+        unset($this->signalEvents[$signal]);
         \pcntl_signal($signal, SIG_IGN);
     }
 
@@ -252,7 +252,7 @@ class Select implements EventInterface
      */
     public function signalHandler($signal)
     {
-        $this->_signalEvents[$signal]($signal);
+        $this->signalEvents[$signal]($signal);
     }
 
     /**
@@ -263,26 +263,26 @@ class Select implements EventInterface
     protected function tick()
     {
         $tasks_to_insert = [];
-        while (!$this->_scheduler->isEmpty()) {
-            $scheduler_data = $this->_scheduler->top();
+        while (!$this->scheduler->isEmpty()) {
+            $scheduler_data = $this->scheduler->top();
             $timer_id = $scheduler_data['data'];
             $next_run_time = -$scheduler_data['priority'];
             $time_now = \microtime(true);
-            $this->_selectTimeout = (int)(($next_run_time - $time_now) * 1000000);
-            if ($this->_selectTimeout <= 0) {
-                $this->_scheduler->extract();
+            $this->selectTimeout = (int)(($next_run_time - $time_now) * 1000000);
+            if ($this->selectTimeout <= 0) {
+                $this->scheduler->extract();
 
-                if (!isset($this->_eventTimer[$timer_id])) {
+                if (!isset($this->eventTimer[$timer_id])) {
                     continue;
                 }
 
                 // [func, args, timer_interval]
-                $task_data = $this->_eventTimer[$timer_id];
+                $task_data = $this->eventTimer[$timer_id];
                 if (isset($task_data[2])) {
                     $next_run_time = $time_now + $task_data[2];
                     $tasks_to_insert[] = [$timer_id, -$next_run_time];
                 } else {
-                    unset($this->_eventTimer[$timer_id]);
+                    unset($this->eventTimer[$timer_id]);
                 }
                 try {
                     $task_data[0]($task_data[1]);
@@ -294,16 +294,16 @@ class Select implements EventInterface
             }
         }
         foreach ($tasks_to_insert as $item) {
-            $this->_scheduler->insert($item[0], $item[1]);
+            $this->scheduler->insert($item[0], $item[1]);
         }
-        if (!$this->_scheduler->isEmpty()) {
-            $scheduler_data = $this->_scheduler->top();
+        if (!$this->scheduler->isEmpty()) {
+            $scheduler_data = $this->scheduler->top();
             $next_run_time = -$scheduler_data['priority'];
             $time_now = \microtime(true);
-            $this->_selectTimeout = \max((int)(($next_run_time - $time_now) * 1000000), 0);
+            $this->selectTimeout = \max((int)(($next_run_time - $time_now) * 1000000), 0);
             return;
         }
-        $this->_selectTimeout = 100000000;
+        $this->selectTimeout = 100000000;
     }
 
     /**
@@ -311,9 +311,9 @@ class Select implements EventInterface
      */
     public function deleteAllTimer()
     {
-        $this->_scheduler = new \SplPriorityQueue();
-        $this->_scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
-        $this->_eventTimer = [];
+        $this->scheduler = new \SplPriorityQueue();
+        $this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
+        $this->eventTimer = [];
     }
 
     /**
@@ -327,43 +327,43 @@ class Select implements EventInterface
                 \pcntl_signal_dispatch();
             }
 
-            $read = $this->_readFds;
-            $write = $this->_writeFds;
-            $except = $this->_exceptFds;
+            $read = $this->readFds;
+            $write = $this->writeFds;
+            $except = $this->exceptFds;
 
             if ($read || $write || $except) {
                 // Waiting read/write/signal/timeout events.
                 try {
-                    @stream_select($read, $write, $except, 0, $this->_selectTimeout);
+                    @stream_select($read, $write, $except, 0, $this->selectTimeout);
                 } catch (Throwable $e) {
                 }
 
             } else {
-                $this->_selectTimeout >= 1 && usleep($this->_selectTimeout);
+                $this->selectTimeout >= 1 && usleep($this->selectTimeout);
             }
 
-            if (!$this->_scheduler->isEmpty()) {
+            if (!$this->scheduler->isEmpty()) {
                 $this->tick();
             }
 
             foreach ($read as $fd) {
                 $fd_key = (int)$fd;
-                if (isset($this->_readEvents[$fd_key])) {
-                    $this->_readEvents[$fd_key]($fd);
+                if (isset($this->readEvents[$fd_key])) {
+                    $this->readEvents[$fd_key]($fd);
                 }
             }
 
             foreach ($write as $fd) {
                 $fd_key = (int)$fd;
-                if (isset($this->_writeEvents[$fd_key])) {
-                    $this->_writeEvents[$fd_key]($fd);
+                if (isset($this->writeEvents[$fd_key])) {
+                    $this->writeEvents[$fd_key]($fd);
                 }
             }
 
             foreach ($except as $fd) {
                 $fd_key = (int)$fd;
-                if (isset($this->_exceptEvents[$fd_key])) {
-                    $this->_exceptEvents[$fd_key]($fd);
+                if (isset($this->exceptEvents[$fd_key])) {
+                    $this->exceptEvents[$fd_key]($fd);
                 }
             }
         }
@@ -375,11 +375,11 @@ class Select implements EventInterface
     public function stop()
     {
         $this->deleteAllTimer();
-        foreach ($this->_signalEvents as $signal => $item) {
+        foreach ($this->signalEvents as $signal => $item) {
             $this->offsignal($signal);
         }
-        $this->_readFds = $this->_writeFds = $this->_exceptFds = $this->_readEvents
-            = $this->_writeEvents = $this->_exceptEvents = $this->_signalEvents = [];
+        $this->readFds = $this->writeFds = $this->exceptFds = $this->readEvents
+            = $this->writeEvents = $this->exceptEvents = $this->signalEvents = [];
     }
 
     /**
@@ -387,7 +387,7 @@ class Select implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 
 }

+ 18 - 18
src/Events/Swoole.php

@@ -24,19 +24,19 @@ class Swoole implements EventInterface
      * All listeners for read timer
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * All listeners for read event.
      * @var array
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for write event.
      * @var array
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * {@inheritdoc}
@@ -46,14 +46,14 @@ class Swoole implements EventInterface
         $t = (int)($delay * 1000);
         $t = $t < 1 ? 1 : $t;
         $timer_id = Timer::after($t, function () use ($func, $args, &$timer_id) {
-            unset($this->_eventTimer[$timer_id]);
+            unset($this->eventTimer[$timer_id]);
             try {
                 $func(...(array)$args);
             } catch (\Throwable $e) {
                 Worker::stopAll(250, $e);
             }
         });
-        $this->_eventTimer[$timer_id] = $timer_id;
+        $this->eventTimer[$timer_id] = $timer_id;
         return $timer_id;
     }
 
@@ -62,9 +62,9 @@ class Swoole implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
+        if (isset($this->eventTimer[$timer_id])) {
             $res = Timer::clear($timer_id);
-            unset($this->_eventTimer[$timer_id]);
+            unset($this->eventTimer[$timer_id]);
             return $res;
         }
         return false;
@@ -87,7 +87,7 @@ class Swoole implements EventInterface
                 Worker::stopAll(250, $e);
             }
         });
-        $this->_eventTimer[$timer_id] = $timer_id;
+        $this->eventTimer[$timer_id] = $timer_id;
         return $timer_id;
     }
 
@@ -96,7 +96,7 @@ class Swoole implements EventInterface
      */
     public function onReadable($stream, $func)
     {
-        $this->_readEvents[(int)$stream] = $stream;
+        $this->readEvents[(int)$stream] = $stream;
         return Event::add($stream, $func, null, \SWOOLE_EVENT_READ);
     }
 
@@ -106,11 +106,11 @@ class Swoole implements EventInterface
     public function offReadable($stream)
     {
         $fd = (int)$stream;
-        if (!isset($this->_readEvents[$fd])) {
+        if (!isset($this->readEvents[$fd])) {
             return;
         }
-        unset($this->_readEvents[$fd]);
-        if (!isset($this->_writeEvents[$fd])) {
+        unset($this->readEvents[$fd]);
+        if (!isset($this->writeEvents[$fd])) {
             return Event::del($stream);
         }
         return Event::set($stream, null, null, \SWOOLE_EVENT_READ);
@@ -121,7 +121,7 @@ class Swoole implements EventInterface
      */
     public function onWritable($stream, $func)
     {
-        $this->_writeEvents[(int)$stream] = $stream;
+        $this->writeEvents[(int)$stream] = $stream;
         return Event::add($stream, null, $func, \SWOOLE_EVENT_WRITE);
     }
 
@@ -131,11 +131,11 @@ class Swoole implements EventInterface
     public function offWritable($stream)
     {
         $fd = (int)$stream;
-        if (!isset($this->_writeEvents[$fd])) {
+        if (!isset($this->writeEvents[$fd])) {
             return;
         }
-        unset($this->_writeEvents[$fd]);
-        if (!isset($this->_readEvents[$fd])) {
+        unset($this->writeEvents[$fd]);
+        if (!isset($this->readEvents[$fd])) {
             return Event::del($stream);
         }
         return Event::set($stream, null, null, \SWOOLE_EVENT_WRITE);
@@ -163,7 +163,7 @@ class Swoole implements EventInterface
      */
     public function deleteAllTimer()
     {
-        foreach ($this->_eventTimer as $timer_id) {
+        foreach ($this->eventTimer as $timer_id) {
             Timer::clear($timer_id);
         }
     }
@@ -194,7 +194,7 @@ class Swoole implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 
 }

+ 26 - 26
src/Events/Swow.php

@@ -23,25 +23,25 @@ class Swow implements EventInterface
      * All listeners for read timer
      * @var array
      */
-    protected $_eventTimer = [];
+    protected $eventTimer = [];
 
     /**
      * All listeners for read event.
      * @var array<Coroutine>
      */
-    protected $_readEvents = [];
+    protected $readEvents = [];
 
     /**
      * All listeners for write event.
      * @var array<Coroutine>
      */
-    protected $_writeEvents = [];
+    protected $writeEvents = [];
 
     /**
      * All listeners for signal.
      * @var array<Coroutine>
      */
-    protected $_signalListener = [];
+    protected $signalListener = [];
 
     /**
      * Get timer count.
@@ -50,7 +50,7 @@ class Swow implements EventInterface
      */
     public function getTimerCount()
     {
-        return \count($this->_eventTimer);
+        return \count($this->eventTimer);
     }
 
     /**
@@ -62,7 +62,7 @@ class Swow implements EventInterface
         $t = max($t, 1);
         $coroutine = Coroutine::run(function () use ($t, $func, $args): void {
             msleep($t);
-            unset($this->_eventTimer[Coroutine::getCurrent()->getId()]);
+            unset($this->eventTimer[Coroutine::getCurrent()->getId()]);
             try {
                 $func(...(array) $args);
             } catch (\Throwable $e) {
@@ -70,7 +70,7 @@ class Swow implements EventInterface
             }
         });
         $timer_id = $coroutine->getId();
-        $this->_eventTimer[$timer_id] = $timer_id;
+        $this->eventTimer[$timer_id] = $timer_id;
         return $timer_id;
     }
 
@@ -92,7 +92,7 @@ class Swow implements EventInterface
             }
         });
         $timer_id = $coroutine->getId();
-        $this->_eventTimer[$timer_id] = $timer_id;
+        $this->eventTimer[$timer_id] = $timer_id;
         return $timer_id;
     }
 
@@ -101,12 +101,12 @@ class Swow implements EventInterface
      */
     public function deleteTimer($timer_id)
     {
-        if (isset($this->_eventTimer[$timer_id])) {
+        if (isset($this->eventTimer[$timer_id])) {
             try {
                 (Coroutine::getAll()[$timer_id])->kill();
                 return true;
             } finally {
-                unset($this->_eventTimer[$timer_id]);
+                unset($this->eventTimer[$timer_id]);
             }
         }
         return false;
@@ -117,7 +117,7 @@ class Swow implements EventInterface
      */
     public function deleteAllTimer()
     {
-        foreach ($this->_eventTimer as $timer_id) {
+        foreach ($this->eventTimer as $timer_id) {
             $this->deleteTimer($timer_id);
         }
     }
@@ -127,10 +127,10 @@ class Swow implements EventInterface
      */
     public function onReadable($stream, $func)
     {
-        if (isset($this->_readEvents[(int) $stream])) {
+        if (isset($this->readEvents[(int) $stream])) {
             $this->offReadable($stream);
         }
-        $this->_readEvents[(int) $stream] = Coroutine::run(function () use ($stream, $func): void {
+        $this->readEvents[(int) $stream] = Coroutine::run(function () use ($stream, $func): void {
             try {
                 while (true) {
                     $rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP);
@@ -155,17 +155,17 @@ class Swow implements EventInterface
     public function offReadable($stream, bool $bySelf = false)
     {
         $fd = (int) $stream;
-        if (!isset($this->_readEvents[$fd])) {
+        if (!isset($this->readEvents[$fd])) {
             return;
         }
         if (!$bySelf) {
-            $coroutine = $this->_readEvents[$fd];
+            $coroutine = $this->readEvents[$fd];
             if (!$coroutine->isExecuting()) {
                 return;
             }
             $coroutine->kill();
         }
-        unset($this->_readEvents[$fd]);
+        unset($this->readEvents[$fd]);
     }
 
     /**
@@ -173,10 +173,10 @@ class Swow implements EventInterface
      */
     public function onWritable($stream, $func)
     {
-        if (isset($this->_writeEvents[(int) $stream])) {
+        if (isset($this->writeEvents[(int) $stream])) {
             $this->offWritable($stream);
         }
-        $this->_writeEvents[(int) $stream] = Coroutine::run(function () use ($stream, $func): void {
+        $this->writeEvents[(int) $stream] = Coroutine::run(function () use ($stream, $func): void {
             try {
                 while (true) {
                     $rEvent = stream_poll_one($stream, STREAM_POLLOUT | STREAM_POLLHUP);
@@ -201,17 +201,17 @@ class Swow implements EventInterface
     public function offWritable($stream, bool $bySelf = false)
     {
         $fd = (int) $stream;
-        if (!isset($this->_writeEvents[$fd])) {
+        if (!isset($this->writeEvents[$fd])) {
             return;
         }
         if (!$bySelf) {
-            $coroutine = $this->_writeEvents[$fd];
+            $coroutine = $this->writeEvents[$fd];
             if (!$coroutine->isExecuting()) {
                 return;
             }
             $coroutine->kill();
         }
-        unset($this->_writeEvents[$fd]);
+        unset($this->writeEvents[$fd]);
     }
 
     /**
@@ -219,7 +219,7 @@ class Swow implements EventInterface
      */
     public function onSignal($signal, $func)
     {
-        if (isset($this->_signalListener[$signal])) {
+        if (isset($this->signalListener[$signal])) {
             return false;
         }
         $coroutine = Coroutine::run(static function () use ($signal, $func): void {
@@ -229,7 +229,7 @@ class Swow implements EventInterface
             } catch (SignalException) {
             }
         });
-        $this->_signalListener[$signal] = $coroutine;
+        $this->signalListener[$signal] = $coroutine;
         return true;
     }
 
@@ -238,11 +238,11 @@ class Swow implements EventInterface
      */
     public function offSignal($signal)
     {
-        if (!isset($this->_signalListener[$signal])) {
+        if (!isset($this->signalListener[$signal])) {
             return false;
         }
-        $this->_signalListener[$signal]->kill();
-        unset($this->_signalListener[$signal]);
+        $this->signalListener[$signal]->kill();
+        unset($this->signalListener[$signal]);
         return true;
     }
 

+ 25 - 25
src/Protocols/Http.php

@@ -29,21 +29,21 @@ class Http
      *
      * @var string
      */
-    protected static $_requestClass = Request::class;
+    protected static $requestClass = Request::class;
 
     /**
      * Upload tmp dir.
      *
      * @var string
      */
-    protected static $_uploadTmpDir = '';
+    protected static $uploadTmpDir = '';
 
     /**
      * Cache.
      *
      * @var bool.
      */
-    protected static $_enableCache = true;
+    protected static $enableCache = true;
 
     /**
      * Get or set the request class name.
@@ -54,9 +54,9 @@ class Http
     public static function requestClass($class_name = null)
     {
         if ($class_name) {
-            static::$_requestClass = $class_name;
+            static::$requestClass = $class_name;
         }
-        return static::$_requestClass;
+        return static::$requestClass;
     }
 
     /**
@@ -66,7 +66,7 @@ class Http
      */
     public static function enableCache($value)
     {
-        static::$_enableCache = (bool)$value;
+        static::$enableCache = (bool)$value;
     }
 
     /**
@@ -149,17 +149,17 @@ class Http
     public static function decode($recv_buffer, TcpConnection $connection)
     {
         static $requests = [];
-        $cacheable = static::$_enableCache && !isset($recv_buffer[512]);
+        $cacheable = static::$enableCache && !isset($recv_buffer[512]);
         if (true === $cacheable && isset($requests[$recv_buffer])) {
             $request = clone $requests[$recv_buffer];
             $request->connection = $connection;
-            $connection->__request = $request;
+            $connection->request = $request;
             $request->properties = [];
             return $request;
         }
-        $request = new static::$_requestClass($recv_buffer);
+        $request = new static::$requestClass($recv_buffer);
         $request->connection = $connection;
-        $connection->__request = $request;
+        $connection->request = $request;
         if (true === $cacheable) {
             $requests[$recv_buffer] = $request;
             if (\count($requests) > 512) {
@@ -178,15 +178,15 @@ class Http
      */
     public static function encode($response, TcpConnection $connection)
     {
-        if (isset($connection->__request)) {
-            $connection->__request->session = null;
-            $connection->__request->connection = null;
-            $connection->__request = null;
+        if (isset($connection->request)) {
+            $connection->request->session = null;
+            $connection->request->connection = null;
+            $connection->request = null;
         }
         if (!\is_object($response)) {
             $ext_header = '';
-            if (isset($connection->__header)) {
-                foreach ($connection->__header as $name => $value) {
+            if (isset($connection->header)) {
+                foreach ($connection->header as $name => $value) {
                     if (\is_array($value)) {
                         foreach ($value as $item) {
                             $ext_header = "$name: $item\r\n";
@@ -195,15 +195,15 @@ class Http
                         $ext_header = "$name: $value\r\n";
                     }
                 }
-                unset($connection->__header);
+                unset($connection->header);
             }
             $body_len = \strlen((string)$response);
             return "HTTP/1.1 200 OK\r\nServer: workerman\r\n{$ext_header}Connection: keep-alive\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $body_len\r\n\r\n$response";
         }
 
-        if (isset($connection->__header)) {
-            $response->withHeaders($connection->__header);
-            unset($connection->__header);
+        if (isset($connection->header)) {
+            $response->withHeaders($connection->header);
+            unset($connection->header);
         }
 
         if (isset($response->file)) {
@@ -302,15 +302,15 @@ class Http
     public static function uploadTmpDir($dir = null)
     {
         if (null !== $dir) {
-            static::$_uploadTmpDir = $dir;
+            static::$uploadTmpDir = $dir;
         }
-        if (static::$_uploadTmpDir === '') {
+        if (static::$uploadTmpDir === '') {
             if ($upload_tmp_dir = \ini_get('upload_tmp_dir')) {
-                static::$_uploadTmpDir = $upload_tmp_dir;
+                static::$uploadTmpDir = $upload_tmp_dir;
             } else if ($upload_tmp_dir = \sys_get_temp_dir()) {
-                static::$_uploadTmpDir = $upload_tmp_dir;
+                static::$uploadTmpDir = $upload_tmp_dir;
             }
         }
-        return static::$_uploadTmpDir;
+        return static::$uploadTmpDir;
     }
 }

+ 3 - 3
src/Protocols/Http/Chunk.php

@@ -26,7 +26,7 @@ class Chunk
      *
      * @var string
      */
-    protected $_buffer = null;
+    protected $buffer = null;
 
     /**
      * Chunk constructor.
@@ -34,7 +34,7 @@ class Chunk
      */
     public function __construct($buffer)
     {
-        $this->_buffer = $buffer;
+        $this->buffer = $buffer;
     }
 
     /**
@@ -44,6 +44,6 @@ class Chunk
      */
     public function __toString()
     {
-        return \dechex(\strlen($this->_buffer)) . "\r\n$this->_buffer\r\n";
+        return \dechex(\strlen($this->buffer)) . "\r\n$this->buffer\r\n";
     }
 }

+ 78 - 78
src/Protocols/Http/Request.php

@@ -56,21 +56,21 @@ class Request
      *
      * @var string
      */
-    protected $_buffer = null;
+    protected $buffer = null;
 
     /**
      * Request data.
      *
      * @var array
      */
-    protected $_data = null;
+    protected $data = null;
 
     /**
      * Enable cache.
      *
      * @var bool
      */
-    protected static $_enableCache = true;
+    protected static $enableCache = true;
 
 
     /**
@@ -80,11 +80,11 @@ class Request
      */
     public function __construct($buffer)
     {
-        $this->_buffer = $buffer;
+        $this->buffer = $buffer;
     }
 
     /**
-     * $_GET.
+     * $GET.
      *
      * @param string|null $name
      * @param mixed|null $default
@@ -92,17 +92,17 @@ class Request
      */
     public function get($name = null, $default = null)
     {
-        if (!isset($this->_data['get'])) {
+        if (!isset($this->data['get'])) {
             $this->parseGet();
         }
         if (null === $name) {
-            return $this->_data['get'];
+            return $this->data['get'];
         }
-        return $this->_data['get'][$name] ?? $default;
+        return $this->data['get'][$name] ?? $default;
     }
 
     /**
-     * $_POST.
+     * $POST.
      *
      * @param string|null $name
      * @param mixed|null $default
@@ -110,13 +110,13 @@ class Request
      */
     public function post($name = null, $default = null)
     {
-        if (!isset($this->_data['post'])) {
+        if (!isset($this->data['post'])) {
             $this->parsePost();
         }
         if (null === $name) {
-            return $this->_data['post'];
+            return $this->data['post'];
         }
-        return $this->_data['post'][$name] ?? $default;
+        return $this->data['post'][$name] ?? $default;
     }
 
     /**
@@ -128,14 +128,14 @@ class Request
      */
     public function header($name = null, $default = null)
     {
-        if (!isset($this->_data['headers'])) {
+        if (!isset($this->data['headers'])) {
             $this->parseHeaders();
         }
         if (null === $name) {
-            return $this->_data['headers'];
+            return $this->data['headers'];
         }
         $name = \strtolower($name);
-        return $this->_data['headers'][$name] ?? $default;
+        return $this->data['headers'][$name] ?? $default;
     }
 
     /**
@@ -147,14 +147,14 @@ class Request
      */
     public function cookie($name = null, $default = null)
     {
-        if (!isset($this->_data['cookie'])) {
-            $this->_data['cookie'] = [];
-            \parse_str(\preg_replace('/; ?/', '&', $this->header('cookie', '')), $this->_data['cookie']);
+        if (!isset($this->data['cookie'])) {
+            $this->data['cookie'] = [];
+            \parse_str(\preg_replace('/; ?/', '&', $this->header('cookie', '')), $this->data['cookie']);
         }
         if ($name === null) {
-            return $this->_data['cookie'];
+            return $this->data['cookie'];
         }
-        return $this->_data['cookie'][$name] ?? $default;
+        return $this->data['cookie'][$name] ?? $default;
     }
 
     /**
@@ -165,13 +165,13 @@ class Request
      */
     public function file($name = null)
     {
-        if (!isset($this->_data['files'])) {
+        if (!isset($this->data['files'])) {
             $this->parsePost();
         }
         if (null === $name) {
-            return $this->_data['files'];
+            return $this->data['files'];
         }
-        return $this->_data['files'][$name] ?? null;
+        return $this->data['files'][$name] ?? null;
     }
 
     /**
@@ -181,10 +181,10 @@ class Request
      */
     public function method()
     {
-        if (!isset($this->_data['method'])) {
+        if (!isset($this->data['method'])) {
             $this->parseHeadFirstLine();
         }
-        return $this->_data['method'];
+        return $this->data['method'];
     }
 
     /**
@@ -194,10 +194,10 @@ class Request
      */
     public function protocolVersion()
     {
-        if (!isset($this->_data['protocolVersion'])) {
+        if (!isset($this->data['protocolVersion'])) {
             $this->parseProtocolVersion();
         }
-        return $this->_data['protocolVersion'];
+        return $this->data['protocolVersion'];
     }
 
     /**
@@ -222,10 +222,10 @@ class Request
      */
     public function uri()
     {
-        if (!isset($this->_data['uri'])) {
+        if (!isset($this->data['uri'])) {
             $this->parseHeadFirstLine();
         }
-        return $this->_data['uri'];
+        return $this->data['uri'];
     }
 
     /**
@@ -235,10 +235,10 @@ class Request
      */
     public function path()
     {
-        if (!isset($this->_data['path'])) {
-            $this->_data['path'] = (string)\parse_url($this->uri(), PHP_URL_PATH);
+        if (!isset($this->data['path'])) {
+            $this->data['path'] = (string)\parse_url($this->uri(), PHP_URL_PATH);
         }
-        return $this->_data['path'];
+        return $this->data['path'];
     }
 
     /**
@@ -248,10 +248,10 @@ class Request
      */
     public function queryString()
     {
-        if (!isset($this->_data['query_string'])) {
-            $this->_data['query_string'] = (string)\parse_url($this->uri(), PHP_URL_QUERY);
+        if (!isset($this->data['query_string'])) {
+            $this->data['query_string'] = (string)\parse_url($this->uri(), PHP_URL_QUERY);
         }
-        return $this->_data['query_string'];
+        return $this->data['query_string'];
     }
 
     /**
@@ -326,10 +326,10 @@ class Request
      */
     public function rawHead()
     {
-        if (!isset($this->_data['head'])) {
-            $this->_data['head'] = \strstr($this->_buffer, "\r\n\r\n", true);
+        if (!isset($this->data['head'])) {
+            $this->data['head'] = \strstr($this->buffer, "\r\n\r\n", true);
         }
-        return $this->_data['head'];
+        return $this->data['head'];
     }
 
     /**
@@ -339,7 +339,7 @@ class Request
      */
     public function rawBody()
     {
-        return \substr($this->_buffer, \strpos($this->_buffer, "\r\n\r\n") + 4);
+        return \substr($this->buffer, \strpos($this->buffer, "\r\n\r\n") + 4);
     }
 
     /**
@@ -349,7 +349,7 @@ class Request
      */
     public function rawBuffer()
     {
-        return $this->_buffer;
+        return $this->buffer;
     }
 
     /**
@@ -359,7 +359,7 @@ class Request
      */
     public static function enableCache($value)
     {
-        static::$_enableCache = (bool)$value;
+        static::$enableCache = (bool)$value;
     }
 
     /**
@@ -369,10 +369,10 @@ class Request
      */
     protected function parseHeadFirstLine()
     {
-        $first_line = \strstr($this->_buffer, "\r\n", true);
+        $first_line = \strstr($this->buffer, "\r\n", true);
         $tmp = \explode(' ', $first_line, 3);
-        $this->_data['method'] = $tmp[0];
-        $this->_data['uri'] = $tmp[1] ?? '/';
+        $this->data['method'] = $tmp[0];
+        $this->data['uri'] = $tmp[1] ?? '/';
     }
 
     /**
@@ -382,9 +382,9 @@ class Request
      */
     protected function parseProtocolVersion()
     {
-        $first_line = \strstr($this->_buffer, "\r\n", true);
+        $first_line = \strstr($this->buffer, "\r\n", true);
         $protoco_version = substr(\strstr($first_line, 'HTTP/'), 5);
-        $this->_data['protocolVersion'] = $protoco_version ? $protoco_version : '1.0';
+        $this->data['protocolVersion'] = $protoco_version ? $protoco_version : '1.0';
     }
 
     /**
@@ -395,16 +395,16 @@ class Request
     protected function parseHeaders()
     {
         static $cache = [];
-        $this->_data['headers'] = [];
+        $this->data['headers'] = [];
         $raw_head = $this->rawHead();
         $end_line_position = \strpos($raw_head, "\r\n");
         if ($end_line_position === false) {
             return;
         }
         $head_buffer = \substr($raw_head, $end_line_position + 2);
-        $cacheable = static::$_enableCache && !isset($head_buffer[2048]);
+        $cacheable = static::$enableCache && !isset($head_buffer[2048]);
         if ($cacheable && isset($cache[$head_buffer])) {
-            $this->_data['headers'] = $cache[$head_buffer];
+            $this->data['headers'] = $cache[$head_buffer];
             return;
         }
         $head_data = \explode("\r\n", $head_buffer);
@@ -417,14 +417,14 @@ class Request
                 $key = \strtolower($content);
                 $value = '';
             }
-            if (isset($this->_data['headers'][$key])) {
-                $this->_data['headers'][$key] = "{$this->_data['headers'][$key]},$value";
+            if (isset($this->data['headers'][$key])) {
+                $this->data['headers'][$key] = "{$this->data['headers'][$key]},$value";
             } else {
-                $this->_data['headers'][$key] = $value;
+                $this->data['headers'][$key] = $value;
             }
         }
         if ($cacheable) {
-            $cache[$head_buffer] = $this->_data['headers'];
+            $cache[$head_buffer] = $this->data['headers'];
             if (\count($cache) > 128) {
                 unset($cache[key($cache)]);
             }
@@ -440,18 +440,18 @@ class Request
     {
         static $cache = [];
         $query_string = $this->queryString();
-        $this->_data['get'] = [];
+        $this->data['get'] = [];
         if ($query_string === '') {
             return;
         }
-        $cacheable = static::$_enableCache && !isset($query_string[1024]);
+        $cacheable = static::$enableCache && !isset($query_string[1024]);
         if ($cacheable && isset($cache[$query_string])) {
-            $this->_data['get'] = $cache[$query_string];
+            $this->data['get'] = $cache[$query_string];
             return;
         }
-        \parse_str($query_string, $this->_data['get']);
+        \parse_str($query_string, $this->data['get']);
         if ($cacheable) {
-            $cache[$query_string] = $this->_data['get'];
+            $cache[$query_string] = $this->data['get'];
             if (\count($cache) > 256) {
                 unset($cache[key($cache)]);
             }
@@ -466,7 +466,7 @@ class Request
     protected function parsePost()
     {
         static $cache = [];
-        $this->_data['post'] = $this->_data['files'] = [];
+        $this->data['post'] = $this->data['files'] = [];
         $content_type = $this->header('content-type', '');
         if (\preg_match('/boundary="?(\S+)"?/', $content_type, $match)) {
             $http_post_boundary = '--' . $match[1];
@@ -477,18 +477,18 @@ class Request
         if ($body_buffer === '') {
             return;
         }
-        $cacheable = static::$_enableCache && !isset($body_buffer[1024]);
+        $cacheable = static::$enableCache && !isset($body_buffer[1024]);
         if ($cacheable && isset($cache[$body_buffer])) {
-            $this->_data['post'] = $cache[$body_buffer];
+            $this->data['post'] = $cache[$body_buffer];
             return;
         }
         if (\preg_match('/\bjson\b/i', $content_type)) {
-            $this->_data['post'] = (array)\json_decode($body_buffer, true);
+            $this->data['post'] = (array)\json_decode($body_buffer, true);
         } else {
-            \parse_str($body_buffer, $this->_data['post']);
+            \parse_str($body_buffer, $this->data['post']);
         }
         if ($cacheable) {
-            $cache[$body_buffer] = $this->_data['post'];
+            $cache[$body_buffer] = $this->data['post'];
             if (\count($cache) > 256) {
                 unset($cache[key($cache)]);
             }
@@ -504,7 +504,7 @@ class Request
     protected function parseUploadFiles($http_post_boundary)
     {
         $http_post_boundary = \trim($http_post_boundary, '"');
-        $buffer = $this->_buffer;
+        $buffer = $this->buffer;
         $post_encode_string = '';
         $files_encode_string = '';
         $files = [];
@@ -515,12 +515,12 @@ class Request
             $offset = $this->parseUploadFile($http_post_boundary, $offset, $post_encode_string, $files_encode_string, $files);
         }
         if ($post_encode_string) {
-            parse_str($post_encode_string, $this->_data['post']);
+            parse_str($post_encode_string, $this->data['post']);
         }
 
         if ($files_encode_string) {
-            parse_str($files_encode_string, $this->_data['files']);
-            \array_walk_recursive($this->_data['files'], function (&$value) use ($files) {
+            parse_str($files_encode_string, $this->data['files']);
+            \array_walk_recursive($this->data['files'], function (&$value) use ($files) {
                 $value = $files[$value];
             });
         }
@@ -535,20 +535,20 @@ class Request
     {
         $file = [];
         $boundary = "\r\n$boundary";
-        if (\strlen($this->_buffer) < $section_start_offset) {
+        if (\strlen($this->buffer) < $section_start_offset) {
             return 0;
         }
-        $section_end_offset = \strpos($this->_buffer, $boundary, $section_start_offset);
+        $section_end_offset = \strpos($this->buffer, $boundary, $section_start_offset);
         if (!$section_end_offset) {
             return 0;
         }
-        $content_lines_end_offset = \strpos($this->_buffer, "\r\n\r\n", $section_start_offset);
+        $content_lines_end_offset = \strpos($this->buffer, "\r\n\r\n", $section_start_offset);
         if (!$content_lines_end_offset || $content_lines_end_offset + 4 > $section_end_offset) {
             return 0;
         }
-        $content_lines_str = \substr($this->_buffer, $section_start_offset, $content_lines_end_offset - $section_start_offset);
+        $content_lines_str = \substr($this->buffer, $section_start_offset, $content_lines_end_offset - $section_start_offset);
         $content_lines = \explode("\r\n", trim($content_lines_str . "\r\n"));
-        $boundary_value = \substr($this->_buffer, $content_lines_end_offset + 4, $section_end_offset - $content_lines_end_offset - 4);
+        $boundary_value = \substr($this->buffer, $content_lines_end_offset + 4, $section_end_offset - $content_lines_end_offset - 4);
         $upload_key = false;
         foreach ($content_lines as $content_line) {
             if (!\strpos($content_line, ': ')) {
@@ -585,7 +585,7 @@ class Request
                         break;
                     } // Is post field.
                     else {
-                        // Parse $_POST.
+                        // Parse $POST.
                         if (\preg_match('/name="(.*?)"$/', $value, $match)) {
                             $k = $match[1];
                             $post_encode_string .= \urlencode($k) . "=" . \urlencode($boundary_value) . '&';
@@ -667,7 +667,7 @@ class Request
      */
     public function __toString()
     {
-        return $this->_buffer;
+        return $this->buffer;
     }
 
     /**
@@ -677,9 +677,9 @@ class Request
      */
     public function __destruct()
     {
-        if (isset($this->_data['files'])) {
+        if (isset($this->data['files'])) {
             \clearstatcache();
-            \array_walk_recursive($this->_data['files'], function ($value, $key) {
+            \array_walk_recursive($this->data['files'], function ($value, $key) {
                 if ($key === 'tmp_name') {
                     if (\is_file($value)) {
                         \unlink($value);
@@ -697,7 +697,7 @@ class Request
      */
     protected function setSidCookie(string $session_name, string $sid, array $cookie_params)
     {
-        $this->connection->__header['Set-Cookie'] = [$session_name . '=' . $sid
+        $this->connection->header['Set-Cookie'] = [$session_name . '=' . $sid
             . (empty($cookie_params['domain']) ? '' : '; Domain=' . $cookie_params['domain'])
             . (empty($cookie_params['lifetime']) ? '' : '; Max-Age=' . $cookie_params['lifetime'])
             . (empty($cookie_params['path']) ? '' : '; Path=' . $cookie_params['path'])

+ 38 - 38
src/Protocols/Http/Response.php

@@ -25,35 +25,35 @@ class Response
      *
      * @var array
      */
-    protected $_header = null;
+    protected $header = null;
 
     /**
      * Http status.
      *
      * @var int
      */
-    protected $_status = null;
+    protected $status = null;
 
     /**
      * Http reason.
      *
      * @var string
      */
-    protected $_reason = null;
+    protected $reason = null;
 
     /**
      * Http version.
      *
      * @var string
      */
-    protected $_version = '1.1';
+    protected $version = '1.1';
 
     /**
      * Http body.
      *
      * @var string
      */
-    protected $_body = null;
+    protected $body = null;
 
     /**
      * Send file info
@@ -66,7 +66,7 @@ class Response
      * Mine type map.
      * @var array
      */
-    protected static $_mimeTypeMap = null;
+    protected static $mimeTypeMap = null;
 
     /**
      * Phrases.
@@ -168,9 +168,9 @@ class Response
         $body = ''
     )
     {
-        $this->_status = $status;
-        $this->_header = $headers;
-        $this->_body = (string)$body;
+        $this->status = $status;
+        $this->header = $headers;
+        $this->body = (string)$body;
     }
 
     /**
@@ -182,7 +182,7 @@ class Response
      */
     public function header($name, $value)
     {
-        $this->_header[$name] = $value;
+        $this->header[$name] = $value;
         return $this;
     }
 
@@ -206,7 +206,7 @@ class Response
      */
     public function withHeaders($headers)
     {
-        $this->_header = \array_merge_recursive($this->_header, $headers);
+        $this->header = \array_merge_recursive($this->header, $headers);
         return $this;
     }
 
@@ -218,7 +218,7 @@ class Response
      */
     public function withoutHeader($name)
     {
-        unset($this->_header[$name]);
+        unset($this->header[$name]);
         return $this;
     }
 
@@ -231,7 +231,7 @@ class Response
     public function getHeader($name)
     {
 
-        return $this->_header[$name] ?? null;
+        return $this->header[$name] ?? null;
     }
 
     /**
@@ -241,7 +241,7 @@ class Response
      */
     public function getHeaders()
     {
-        return $this->_header;
+        return $this->header;
     }
 
     /**
@@ -253,8 +253,8 @@ class Response
      */
     public function withStatus($code, $reason_phrase = null)
     {
-        $this->_status = $code;
-        $this->_reason = $reason_phrase;
+        $this->status = $code;
+        $this->reason = $reason_phrase;
         return $this;
     }
 
@@ -265,7 +265,7 @@ class Response
      */
     public function getStatusCode()
     {
-        return $this->_status;
+        return $this->status;
     }
 
     /**
@@ -275,7 +275,7 @@ class Response
      */
     public function getReasonPhrase()
     {
-        return $this->_reason;
+        return $this->reason;
     }
 
     /**
@@ -286,7 +286,7 @@ class Response
      */
     public function withProtocolVersion($version)
     {
-        $this->_version = $version;
+        $this->version = $version;
         return $this;
     }
 
@@ -298,7 +298,7 @@ class Response
      */
     public function withBody($body)
     {
-        $this->_body = (string)$body;
+        $this->body = (string)$body;
         return $this;
     }
 
@@ -309,7 +309,7 @@ class Response
      */
     public function rawBody()
     {
-        return $this->_body;
+        return $this->body;
     }
 
     /**
@@ -344,7 +344,7 @@ class Response
      */
     public function cookie($name, $value = '', $max_age = null, $path = '', $domain = '', $secure = false, $http_only = false, $same_site  = false)
     {
-        $this->_header['Set-Cookie'][] = $name . '=' . \rawurlencode($value)
+        $this->header['Set-Cookie'][] = $name . '=' . \rawurlencode($value)
             . (empty($domain) ? '' : '; Domain=' . $domain)
             . ($max_age === null ? '' : '; Max-Age=' . $max_age)
             . (empty($path) ? '' : '; Path=' . $path)
@@ -363,9 +363,9 @@ class Response
     protected function createHeadForFile($file_info)
     {
         $file = $file_info['file'];
-        $reason = $this->_reason ?: self::PHRASES[$this->_status];
-        $head = "HTTP/{$this->_version} {$this->_status} $reason\r\n";
-        $headers = $this->_header;
+        $reason = $this->reason ?: self::PHRASES[$this->status];
+        $head = "HTTP/{$this->version} {$this->status} $reason\r\n";
+        $headers = $this->header;
         if (!isset($headers['Server'])) {
             $head .= "Server: workerman\r\n";
         }
@@ -387,14 +387,14 @@ class Response
         $extension = $file_info['extension'] ?? '';
         $base_name = $file_info['basename'] ?? 'unknown';
         if (!isset($headers['Content-Type'])) {
-            if (isset(self::$_mimeTypeMap[$extension])) {
-                $head .= "Content-Type: " . self::$_mimeTypeMap[$extension] . "\r\n";
+            if (isset(self::$mimeTypeMap[$extension])) {
+                $head .= "Content-Type: " . self::$mimeTypeMap[$extension] . "\r\n";
             } else {
                 $head .= "Content-Type: application/octet-stream\r\n";
             }
         }
 
-        if (!isset($headers['Content-Disposition']) && !isset(self::$_mimeTypeMap[$extension])) {
+        if (!isset($headers['Content-Disposition']) && !isset(self::$mimeTypeMap[$extension])) {
             $head .= "Content-Disposition: attachment; filename=\"$base_name\"\r\n";
         }
 
@@ -418,14 +418,14 @@ class Response
             return $this->createHeadForFile($this->file);
         }
 
-        $reason = $this->_reason ?: self::PHRASES[$this->_status] ?? '';
-        $body_len = \strlen($this->_body);
-        if (empty($this->_header)) {
-            return "HTTP/{$this->_version} {$this->_status} $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $body_len\r\nConnection: keep-alive\r\n\r\n{$this->_body}";
+        $reason = $this->reason ?: self::PHRASES[$this->status] ?? '';
+        $body_len = \strlen($this->body);
+        if (empty($this->header)) {
+            return "HTTP/{$this->version} {$this->status} $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $body_len\r\nConnection: keep-alive\r\n\r\n{$this->body}";
         }
 
-        $head = "HTTP/{$this->_version} {$this->_status} $reason\r\n";
-        $headers = $this->_header;
+        $head = "HTTP/{$this->version} {$this->status} $reason\r\n";
+        $headers = $this->header;
         if (!isset($headers['Server'])) {
             $head .= "Server: workerman\r\n";
         }
@@ -446,17 +446,17 @@ class Response
         if (!isset($headers['Content-Type'])) {
             $head .= "Content-Type: text/html;charset=utf-8\r\n";
         } else if ($headers['Content-Type'] === 'text/event-stream') {
-            return $head . $this->_body;
+            return $head . $this->body;
         }
 
         if (!isset($headers['Transfer-Encoding'])) {
             $head .= "Content-Length: $body_len\r\n\r\n";
         } else {
-            return "$head\r\n" . dechex($body_len) . "\r\n{$this->_body}\r\n";
+            return "$head\r\n" . dechex($body_len) . "\r\n{$this->body}\r\n";
         }
 
         // The whole http package
-        return $head . $this->_body;
+        return $head . $this->body;
     }
 
     /**
@@ -474,7 +474,7 @@ class Response
                 $extension_var = $match[2];
                 $extension_array = \explode(' ', \substr($extension_var, 0, -1));
                 foreach ($extension_array as $file_extension) {
-                    static::$_mimeTypeMap[$file_extension] = $mime_type;
+                    static::$mimeTypeMap[$file_extension] = $mime_type;
                 }
             }
         }

+ 3 - 3
src/Protocols/Http/ServerSentEvents.php

@@ -24,7 +24,7 @@ class ServerSentEvents
      * Data.
      * @var array
      */
-    protected $_data = null;
+    protected $data = null;
 
     /**
      * ServerSentEvents constructor.
@@ -33,7 +33,7 @@ class ServerSentEvents
      */
     public function __construct(array $data)
     {
-        $this->_data = $data;
+        $this->data = $data;
     }
 
     /**
@@ -44,7 +44,7 @@ class ServerSentEvents
     public function __toString()
     {
         $buffer = '';
-        $data = $this->_data;
+        $data = $this->data;
         if (isset($data[''])) {
             $buffer = ": {$data['']}\n";
         }

+ 38 - 38
src/Protocols/Http/Session.php

@@ -28,14 +28,14 @@ class Session
      *
      * @var string
      */
-    protected static $_handlerClass = FileSessionHandler::class;
+    protected static $handlerClass = FileSessionHandler::class;
 
     /**
      * Parameters of __constructor for session handler class.
      *
      * @var null
      */
-    protected static $_handlerConfig = null;
+    protected static $handlerConfig = null;
 
     /**
      * Session name.
@@ -112,28 +112,28 @@ class Session
      *
      * @var SessionHandlerInterface
      */
-    protected static $_handler = null;
+    protected static $handler = null;
 
     /**
      * Session data.
      *
      * @var array
      */
-    protected $_data = [];
+    protected $data = [];
 
     /**
      * Session changed and need to save.
      *
      * @var bool
      */
-    protected $_needSave = false;
+    protected $needSave = false;
 
     /**
      * Session id.
      *
      * @var null
      */
-    protected $_sessionId = null;
+    protected $sessionId = null;
 
     /**
      * Session constructor.
@@ -143,12 +143,12 @@ class Session
     public function __construct($session_id)
     {
         static::checkSessionId($session_id);
-        if (static::$_handler === null) {
+        if (static::$handler === null) {
             static::initHandler();
         }
-        $this->_sessionId = $session_id;
-        if ($data = static::$_handler->read($session_id)) {
-            $this->_data = \unserialize($data);
+        $this->sessionId = $session_id;
+        if ($data = static::$handler->read($session_id)) {
+            $this->data = \unserialize($data);
         }
     }
 
@@ -159,7 +159,7 @@ class Session
      */
     public function getId()
     {
-        return $this->_sessionId;
+        return $this->sessionId;
     }
 
     /**
@@ -171,7 +171,7 @@ class Session
      */
     public function get($name, $default = null)
     {
-        return $this->_data[$name] ?? $default;
+        return $this->data[$name] ?? $default;
     }
 
     /**
@@ -182,8 +182,8 @@ class Session
      */
     public function set($name, $value)
     {
-        $this->_data[$name] = $value;
-        $this->_needSave = true;
+        $this->data[$name] = $value;
+        $this->needSave = true;
     }
 
     /**
@@ -193,8 +193,8 @@ class Session
      */
     public function delete($name)
     {
-        unset($this->_data[$name]);
-        $this->_needSave = true;
+        unset($this->data[$name]);
+        $this->needSave = true;
     }
 
     /**
@@ -225,9 +225,9 @@ class Session
         }
 
         foreach ($key as $k => $v) {
-            $this->_data[$k] = $v;
+            $this->data[$k] = $v;
         }
-        $this->_needSave = true;
+        $this->needSave = true;
     }
 
     /**
@@ -243,10 +243,10 @@ class Session
         }
         if (\is_array($name)) {
             foreach ($name as $key) {
-                unset($this->_data[$key]);
+                unset($this->data[$key]);
             }
         }
-        $this->_needSave = true;
+        $this->needSave = true;
     }
 
     /**
@@ -256,7 +256,7 @@ class Session
      */
     public function all()
     {
-        return $this->_data;
+        return $this->data;
     }
 
     /**
@@ -266,8 +266,8 @@ class Session
      */
     public function flush()
     {
-        $this->_needSave = true;
-        $this->_data = [];
+        $this->needSave = true;
+        $this->data = [];
     }
 
     /**
@@ -278,7 +278,7 @@ class Session
      */
     public function has($name)
     {
-        return isset($this->_data[$name]);
+        return isset($this->data[$name]);
     }
 
     /**
@@ -289,7 +289,7 @@ class Session
      */
     public function exists($name)
     {
-        return \array_key_exists($name, $this->_data);
+        return \array_key_exists($name, $this->data);
     }
 
     /**
@@ -299,16 +299,16 @@ class Session
      */
     public function save()
     {
-        if ($this->_needSave) {
-            if (empty($this->_data)) {
-                static::$_handler->destroy($this->_sessionId);
+        if ($this->needSave) {
+            if (empty($this->data)) {
+                static::$handler->destroy($this->sessionId);
             } else {
-                static::$_handler->write($this->_sessionId, \serialize($this->_data));
+                static::$handler->write($this->sessionId, \serialize($this->data));
             }
         } elseif (static::$autoUpdateTimestamp) {
             static::refresh();
         }
-        $this->_needSave = false;
+        $this->needSave = false;
     }
 
     /**
@@ -318,7 +318,7 @@ class Session
      */
     public function refresh()
     {
-        return static::$_handler->updateTimestamp($this->getId());
+        return static::$handler->updateTimestamp($this->getId());
     }
 
     /**
@@ -354,12 +354,12 @@ class Session
     public static function handlerClass($class_name = null, $config = null)
     {
         if ($class_name) {
-            static::$_handlerClass = $class_name;
+            static::$handlerClass = $class_name;
         }
         if ($config) {
-            static::$_handlerConfig = $config;
+            static::$handlerConfig = $config;
         }
-        return static::$_handlerClass;
+        return static::$handlerClass;
     }
 
     /**
@@ -386,10 +386,10 @@ class Session
      */
     protected static function initHandler()
     {
-        if (static::$_handlerConfig === null) {
-            static::$_handler = new static::$_handlerClass();
+        if (static::$handlerConfig === null) {
+            static::$handler = new static::$handlerClass();
         } else {
-            static::$_handler = new static::$_handlerClass(static::$_handlerConfig);
+            static::$handler = new static::$handlerClass(static::$handlerConfig);
         }
     }
 
@@ -400,7 +400,7 @@ class Session
      */
     public function gc()
     {
-        static::$_handler->gc(static::$lifetime);
+        static::$handler->gc(static::$lifetime);
     }
 
     /**

+ 6 - 6
src/Protocols/Http/Session/FileSessionHandler.php

@@ -27,14 +27,14 @@ class FileSessionHandler implements SessionHandlerInterface
      *
      * @var string
      */
-    protected static $_sessionSavePath = null;
+    protected static $sessionSavePath = null;
 
     /**
      * Session file prefix.
      *
      * @var string
      */
-    protected static $_sessionFilePrefix = 'session_';
+    protected static $sessionFilePrefix = 'session_';
 
     /**
      * Init.
@@ -90,7 +90,7 @@ class FileSessionHandler implements SessionHandlerInterface
      */
     public function write($session_id, $session_data)
     {
-        $temp_file = static::$_sessionSavePath . uniqid(bin2hex(random_bytes(8)), true);
+        $temp_file = static::$sessionSavePath . uniqid(bin2hex(random_bytes(8)), true);
         if (!\file_put_contents($temp_file, $session_data)) {
             return false;
         }
@@ -147,7 +147,7 @@ class FileSessionHandler implements SessionHandlerInterface
     public function gc($maxlifetime)
     {
         $time_now = \time();
-        foreach (\glob(static::$_sessionSavePath . static::$_sessionFilePrefix . '*') as $file) {
+        foreach (\glob(static::$sessionSavePath . static::$sessionFilePrefix . '*') as $file) {
             if (\is_file($file) && $time_now - \filemtime($file) > $maxlifetime) {
                 \unlink($file);
             }
@@ -162,7 +162,7 @@ class FileSessionHandler implements SessionHandlerInterface
      */
     protected static function sessionFile($session_id)
     {
-        return static::$_sessionSavePath . static::$_sessionFilePrefix . $session_id;
+        return static::$sessionSavePath . static::$sessionFilePrefix . $session_id;
     }
 
     /**
@@ -177,7 +177,7 @@ class FileSessionHandler implements SessionHandlerInterface
             if ($path[\strlen($path) - 1] !== DIRECTORY_SEPARATOR) {
                 $path .= DIRECTORY_SEPARATOR;
             }
-            static::$_sessionSavePath = $path;
+            static::$sessionSavePath = $path;
             if (!\is_dir($path)) {
                 \mkdir($path, 0777, true);
             }

+ 3 - 3
src/Protocols/Http/Session/RedisClusterSessionHandler.php

@@ -28,11 +28,11 @@ class RedisClusterSessionHandler extends RedisSessionHandler
         if ($auth) {
             $args[] = $auth;
         }
-        $this->_redis = new \RedisCluster(...$args);
+        $this->redis = new \RedisCluster(...$args);
         if (empty($config['prefix'])) {
             $config['prefix'] = 'redis_session_';
         }
-        $this->_redis->setOption(\Redis::OPT_PREFIX, $config['prefix']);
+        $this->redis->setOption(\Redis::OPT_PREFIX, $config['prefix']);
     }
 
     /**
@@ -40,7 +40,7 @@ class RedisClusterSessionHandler extends RedisSessionHandler
      */
     public function read($session_id)
     {
-        return $this->_redis->get($session_id);
+        return $this->redis->get($session_id);
     }
 
 }

+ 15 - 15
src/Protocols/Http/Session/RedisSessionHandler.php

@@ -28,12 +28,12 @@ class RedisSessionHandler implements SessionHandlerInterface
     /**
      * @var \Redis
      */
-    protected $_redis;
+    protected $redis;
 
     /**
      * @var array
      */
-    protected $_config;
+    protected $config;
 
     /**
      * RedisSessionHandler constructor.
@@ -57,33 +57,33 @@ class RedisSessionHandler implements SessionHandlerInterface
             $config['timeout'] = 2;
         }
 
-        $this->_config = $config;
+        $this->config = $config;
 
         $this->connect();
 
         Timer::add($config['ping'] ?? 55, function () {
-            $this->_redis->get('ping');
+            $this->redis->get('ping');
         });
     }
 
     public function connect()
     {
-        $config = $this->_config;
+        $config = $this->config;
 
-        $this->_redis = new \Redis();
-        if (false === $this->_redis->connect($config['host'], $config['port'], $config['timeout'])) {
+        $this->redis = new \Redis();
+        if (false === $this->redis->connect($config['host'], $config['port'], $config['timeout'])) {
             throw new \RuntimeException("Redis connect {$config['host']}:{$config['port']} fail.");
         }
         if (!empty($config['auth'])) {
-            $this->_redis->auth($config['auth']);
+            $this->redis->auth($config['auth']);
         }
         if (!empty($config['database'])) {
-            $this->_redis->select($config['database']);
+            $this->redis->select($config['database']);
         }
         if (empty($config['prefix'])) {
             $config['prefix'] = 'redis_session_';
         }
-        $this->_redis->setOption(\Redis::OPT_PREFIX, $config['prefix']);
+        $this->redis->setOption(\Redis::OPT_PREFIX, $config['prefix']);
     }
 
     /**
@@ -100,12 +100,12 @@ class RedisSessionHandler implements SessionHandlerInterface
     public function read($session_id)
     {
         try {
-            return $this->_redis->get($session_id);
+            return $this->redis->get($session_id);
         } catch (RedisException $e) {
             $msg = strtolower($e->getMessage());
             if ($msg === 'connection lost' || strpos($msg, 'went away')) {
                 $this->connect();
-                return $this->_redis->get($session_id);
+                return $this->redis->get($session_id);
             }
             throw $e;
         }
@@ -116,7 +116,7 @@ class RedisSessionHandler implements SessionHandlerInterface
      */
     public function write($session_id, $session_data)
     {
-        return true === $this->_redis->setex($session_id, Session::$lifetime, $session_data);
+        return true === $this->redis->setex($session_id, Session::$lifetime, $session_data);
     }
 
     /**
@@ -124,7 +124,7 @@ class RedisSessionHandler implements SessionHandlerInterface
      */
     public function updateTimestamp($id, $data = "")
     {
-        return true === $this->_redis->expire($id, Session::$lifetime);
+        return true === $this->redis->expire($id, Session::$lifetime);
     }
 
     /**
@@ -132,7 +132,7 @@ class RedisSessionHandler implements SessionHandlerInterface
      */
     public function destroy($session_id)
     {
-        $this->_redis->del($session_id);
+        $this->redis->del($session_id);
         return true;
     }
 

+ 1 - 1
src/Protocols/Http/Session/SessionHandlerInterface.php

@@ -88,7 +88,7 @@ interface SessionHandlerInterface
      * @param string $session_data <p>
      * The encoded session data. This data is the
      * result of the PHP internally encoding
-     * the $_SESSION superglobal to a serialized
+     * the $SESSION superglobal to a serialized
      * string and passing it as this parameter.
      * Please note sessions use an alternative serialization method.
      * </p>

+ 29 - 29
src/Timer.php

@@ -33,21 +33,21 @@ class Timer
      *
      * @var array
      */
-    protected static $_tasks = [];
+    protected static $tasks = [];
 
     /**
      * event
      *
      * @var Select
      */
-    protected static $_event = null;
+    protected static $event = null;
 
     /**
      * timer id
      *
      * @var int
      */
-    protected static $_timerId = 0;
+    protected static $timerId = 0;
 
     /**
      * timer status
@@ -59,7 +59,7 @@ class Timer
      *
      * @var array
      */
-    protected static $_status = [];
+    protected static $status = [];
 
     /**
      * Init.
@@ -70,7 +70,7 @@ class Timer
     public static function init($event = null)
     {
         if ($event) {
-            self::$_event = $event;
+            self::$event = $event;
             return;
         }
         if (\function_exists('pcntl_signal')) {
@@ -85,7 +85,7 @@ class Timer
      */
     public static function signalHandle()
     {
-        if (!self::$_event) {
+        if (!self::$event) {
             \pcntl_alarm(1);
             self::tick();
         }
@@ -111,8 +111,8 @@ class Timer
             $args = [];
         }
 
-        if (self::$_event) {
-            return $persistent ? self::$_event->repeat($time_interval, $func, $args) : self::$_event->delay($time_interval, $func, $args);
+        if (self::$event) {
+            return $persistent ? self::$event->repeat($time_interval, $func, $args) : self::$event->delay($time_interval, $func, $args);
         }
         
         // If not workerman runtime just return.
@@ -125,20 +125,20 @@ class Timer
             return false;
         }
 
-        if (empty(self::$_tasks)) {
+        if (empty(self::$tasks)) {
             \pcntl_alarm(1);
         }
 
         $run_time = \time() + $time_interval;
-        if (!isset(self::$_tasks[$run_time])) {
-            self::$_tasks[$run_time] = [];
+        if (!isset(self::$tasks[$run_time])) {
+            self::$tasks[$run_time] = [];
         }
 
-        self::$_timerId = self::$_timerId == \PHP_INT_MAX ? 1 : ++self::$_timerId;
-        self::$_status[self::$_timerId] = true;
-        self::$_tasks[$run_time][self::$_timerId] = [$func, (array)$args, $persistent, $time_interval];
+        self::$timerId = self::$timerId == \PHP_INT_MAX ? 1 : ++self::$timerId;
+        self::$status[self::$timerId] = true;
+        self::$tasks[$run_time][self::$timerId] = [$func, (array)$args, $persistent, $time_interval];
 
-        return self::$_timerId;
+        return self::$timerId;
     }
 
     /**
@@ -160,12 +160,12 @@ class Timer
      */
     public static function tick()
     {
-        if (empty(self::$_tasks)) {
+        if (empty(self::$tasks)) {
             \pcntl_alarm(0);
             return;
         }
         $time_now = \time();
-        foreach (self::$_tasks as $run_time => $task_data) {
+        foreach (self::$tasks as $run_time => $task_data) {
             if ($time_now >= $run_time) {
                 foreach ($task_data as $index => $one_task) {
                     $task_func     = $one_task[0];
@@ -177,13 +177,13 @@ class Timer
                     } catch (\Throwable $e) {
                         Worker::safeEcho($e);
                     }
-                    if($persistent && !empty(self::$_status[$index])) {
+                    if($persistent && !empty(self::$status[$index])) {
                         $new_run_time = \time() + $time_interval;
-                        if(!isset(self::$_tasks[$new_run_time])) self::$_tasks[$new_run_time] = [];
-                        self::$_tasks[$new_run_time][$index] = [$task_func, (array)$task_args, $persistent, $time_interval];
+                        if(!isset(self::$tasks[$new_run_time])) self::$tasks[$new_run_time] = [];
+                        self::$tasks[$new_run_time][$index] = [$task_func, (array)$task_args, $persistent, $time_interval];
                     }
                 }
-                unset(self::$_tasks[$run_time]);
+                unset(self::$tasks[$run_time]);
             }
         }
     }
@@ -196,16 +196,16 @@ class Timer
      */
     public static function del($timer_id)
     {
-        if (self::$_event) {
-            return self::$_event->deleteTimer($timer_id);
+        if (self::$event) {
+            return self::$event->deleteTimer($timer_id);
         }
 
-        foreach(self::$_tasks as $run_time => $task_data) 
+        foreach(self::$tasks as $run_time => $task_data) 
         {
-            if(array_key_exists($timer_id, $task_data)) unset(self::$_tasks[$run_time][$timer_id]);
+            if(array_key_exists($timer_id, $task_data)) unset(self::$tasks[$run_time][$timer_id]);
         }
 
-        if(array_key_exists($timer_id, self::$_status)) unset(self::$_status[$timer_id]);
+        if(array_key_exists($timer_id, self::$status)) unset(self::$status[$timer_id]);
 
         return true;
     }
@@ -217,12 +217,12 @@ class Timer
      */
     public static function delAll()
     {
-        self::$_tasks = self::$_status = [];
+        self::$tasks = self::$status = [];
         if (\function_exists('pcntl_alarm')) {
             \pcntl_alarm(0);
         }
-        if (self::$_event) {
-            self::$_event->deleteAllTimer();
+        if (self::$event) {
+            self::$event->deleteAllTimer();
         }
     }
 }

Datei-Diff unterdrückt, da er zu groß ist
+ 171 - 171
src/Worker.php


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.