Browse Source

Properties

walkor 2 năm trước cách đây
mục cha
commit
10c1882ba6

+ 2 - 2
src/Connection/AsyncTcpConnection.php

@@ -39,14 +39,14 @@ class AsyncTcpConnection extends TcpConnection
     public $transport = 'tcp';
 
     /**
-     * Socks5 proxy
+     * Socks5 proxy.
      *
      * @var string
      */
     public $proxySocks5 = '';
 
     /**
-     * Http proxy
+     * Http proxy.
      *
      * @var string
      */

+ 8 - 1
src/Connection/ConnectionInterface.php

@@ -14,10 +14,11 @@
 
 namespace Workerman\Connection;
 
+use Workerman\Properties;
+
 /**
  * ConnectionInterface.
  */
-#[\AllowDynamicProperties]
 abstract class ConnectionInterface
 {
     /**
@@ -75,6 +76,11 @@ abstract class ConnectionInterface
     public $protocolContext = [];
 
     /**
+     * Dynamic Properties。
+     */
+    use Properties;
+
+    /**
      * Sends data on the connection.
      *
      * @param mixed $sendBuffer
@@ -145,4 +151,5 @@ abstract class ConnectionInterface
      * @return void
      */
     abstract public function close($data = null);
+
 }

+ 3 - 2
src/Connection/TcpConnection.php

@@ -16,6 +16,7 @@ namespace Workerman\Connection;
 
 use Workerman\Events\EventInterface;
 use Workerman\Protocols\Http\Request;
+use Workerman\Protocols\ProtocolInterface;
 use Workerman\Worker;
 
 /**
@@ -104,7 +105,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      * Application layer protocol.
      * The format is like this Workerman\\Protocols\\Http.
      *
-     * @var \Workerman\Protocols\ProtocolInterface
+     * @var ProtocolInterface
      */
     public $protocol = null;
 
@@ -323,7 +324,7 @@ class TcpConnection extends ConnectionInterface implements \JsonSerializable
      *
      * @param mixed $sendBuffer
      * @param bool $raw
-     * @return bool|null
+     * @return bool|void
      */
     public function send($sendBuffer, $raw = false)
     {

+ 3 - 1
src/Connection/UdpConnection.php

@@ -14,6 +14,8 @@
 
 namespace Workerman\Connection;
 
+use Workerman\Protocols\ProtocolInterface;
+
 /**
  * UdpConnection.
  */
@@ -23,7 +25,7 @@ class UdpConnection extends ConnectionInterface implements \JsonSerializable
      * Application layer protocol.
      * The format is like this Workerman\\Protocols\\Http.
      *
-     * @var \Workerman\Protocols\ProtocolInterface
+     * @var ProtocolInterface
      */
     public $protocol = null;
 

+ 5 - 52
src/Protocols/Http/Request.php

@@ -15,6 +15,7 @@
 namespace Workerman\Protocols\Http;
 
 use Workerman\Connection\TcpConnection;
+use Workerman\Properties;
 use Workerman\Protocols\Http\Session;
 use Workerman\Protocols\Http;
 use Workerman\Worker;
@@ -40,13 +41,6 @@ class Request
     public $session = null;
 
     /**
-     * Properties.
-     *
-     * @var array
-     */
-    public $properties = [];
-
-    /**
      * @var int
      */
     public static $maxFileUploads = 1024;
@@ -72,6 +66,10 @@ class Request
      */
     protected static $enableCache = true;
 
+    /**
+     * Dynamic Properties。
+     */
+    use Properties;
 
     /**
      * Request constructor.
@@ -618,51 +616,6 @@ class Request
     }
 
     /**
-     * Setter.
-     *
-     * @param string $name
-     * @param mixed $value
-     * @return void
-     */
-    public function __set($name, $value)
-    {
-        $this->properties[$name] = $value;
-    }
-
-    /**
-     * Getter.
-     *
-     * @param string $name
-     * @return mixed|null
-     */
-    public function __get($name)
-    {
-        return $this->properties[$name] ?? null;
-    }
-
-    /**
-     * Isset.
-     *
-     * @param string $name
-     * @return bool
-     */
-    public function __isset($name)
-    {
-        return isset($this->properties[$name]);
-    }
-
-    /**
-     * Unset.
-     *
-     * @param string $name
-     * @return void
-     */
-    public function __unset($name)
-    {
-        unset($this->properties[$name]);
-    }
-
-    /**
      * __toString.
      */
     public function __toString()

+ 7 - 0
src/Protocols/Http/Response.php

@@ -14,6 +14,8 @@
 
 namespace Workerman\Protocols\Http;
 
+use Workerman\Properties;
+
 /**
  * Class Response
  * @package Workerman\Protocols\Http
@@ -146,6 +148,11 @@ class Response
     ];
 
     /**
+     * Dynamic Properties。
+     */
+    use Properties;
+
+    /**
      * Init.
      *
      * @return void

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

@@ -14,6 +14,7 @@
 
 namespace Workerman\Protocols\Http;
 
+use Workerman\Properties;
 use Workerman\Protocols\Http\Session\FileSessionHandler;
 use Workerman\Protocols\Http\Session\SessionHandlerInterface;
 
@@ -136,6 +137,11 @@ class Session
     protected $sessionId = null;
 
     /**
+     * Dynamic Properties。
+     */
+    use Properties;
+
+    /**
      * Session constructor.
      *
      * @param string $sessionId

+ 5 - 1
src/Worker.php

@@ -26,7 +26,6 @@ use Workerman\Events\Select;
  * Worker class
  * A container for listening ports
  */
-#[\AllowDynamicProperties]
 class Worker
 {
     /**
@@ -538,6 +537,11 @@ class Worker
     protected $workerId = null;
 
     /**
+     * Dynamic Properties。
+     */
+    use Properties;
+
+    /**
      * Run all worker instances.
      *
      * @return void