walkor 2 жил өмнө
parent
commit
9e93d41d8d

+ 2 - 1
composer.json

@@ -24,7 +24,8 @@
         "source": "https://github.com/walkor/workerman"
     },
     "require": {
-        "php": ">=7.0"
+        "php": ">=7.0",
+        "ext-json": "*"
     },
     "suggest": {
         "ext-event": "For better performance. "

+ 1 - 14
src/Connection/ConnectionInterface.php

@@ -14,11 +14,10 @@
 
 namespace Workerman\Connection;
 
-use Workerman\Properties;
-
 /**
  * ConnectionInterface.
  */
+#[\AllowDynamicProperties]
 abstract class ConnectionInterface
 {
     /**
@@ -69,18 +68,6 @@ abstract class ConnectionInterface
     public $onError = null;
 
     /**
-     * Protocol context
-     *
-     * @var array
-     */
-    public $protocolContext = [];
-
-    /**
-     * Dynamic Properties。
-     */
-    use Properties;
-
-    /**
      * Sends data on the connection.
      *
      * @param mixed $sendBuffer

+ 0 - 57
src/Properties.php

@@ -1,57 +0,0 @@
-<?php
-namespace Workerman;
-
-Trait Properties
-{
-    /**
-     * Properties.
-     *
-     * @var array
-     */
-    public $properties = [];
-
-    /**
-     * 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]);
-    }
-}

+ 70 - 25
src/Protocols/Http/Request.php

@@ -15,8 +15,6 @@
 namespace Workerman\Protocols\Http;
 
 use Workerman\Connection\TcpConnection;
-use Workerman\Properties;
-use Workerman\Protocols\Http\Session;
 use Workerman\Protocols\Http;
 use Workerman\Worker;
 
@@ -46,6 +44,13 @@ class Request
     public static $maxFileUploads = 1024;
 
     /**
+     * Properties.
+     *
+     * @var array
+     */
+    public $properties = [];
+
+    /**
      * Http buffer.
      *
      * @var string
@@ -67,11 +72,6 @@ class Request
     protected static $enableCache = true;
 
     /**
-     * Dynamic Properties。
-     */
-    use Properties;
-
-    /**
      * Request constructor.
      *
      * @param string $buffer
@@ -255,7 +255,7 @@ class Request
     /**
      * Get session.
      *
-     * @return bool|\Workerman\Protocols\Http\Session
+     * @return bool|Session
      */
     public function session()
     {
@@ -616,6 +616,23 @@ class Request
     }
 
     /**
+     * @param string $sessionName
+     * @param string $sid
+     * @param array $cookieParams
+     * @return void
+     */
+    protected function setSidCookie(string $sessionName, string $sid, array $cookieParams)
+    {
+        $this->connection->header['Set-Cookie'] = [$sessionName . '=' . $sid
+            . (empty($cookieParams['domain']) ? '' : '; Domain=' . $cookieParams['domain'])
+            . (empty($cookieParams['lifetime']) ? '' : '; Max-Age=' . $cookieParams['lifetime'])
+            . (empty($cookieParams['path']) ? '' : '; Path=' . $cookieParams['path'])
+            . (empty($cookieParams['samesite']) ? '' : '; SameSite=' . $cookieParams['samesite'])
+            . (!$cookieParams['secure'] ? '' : '; Secure')
+            . (!$cookieParams['httponly'] ? '' : '; HttpOnly')];
+    }
+
+    /**
      * __toString.
      */
     public function __toString()
@@ -624,6 +641,51 @@ 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]);
+    }
+
+    /**
      * __destruct.
      *
      * @return void
@@ -641,21 +703,4 @@ class Request
             });
         }
     }
-
-    /**
-     * @param string $sessionName
-     * @param string $sid
-     * @param array $cookieParams
-     * @return void
-     */
-    protected function setSidCookie(string $sessionName, string $sid, array $cookieParams)
-    {
-        $this->connection->header['Set-Cookie'] = [$sessionName . '=' . $sid
-            . (empty($cookieParams['domain']) ? '' : '; Domain=' . $cookieParams['domain'])
-            . (empty($cookieParams['lifetime']) ? '' : '; Max-Age=' . $cookieParams['lifetime'])
-            . (empty($cookieParams['path']) ? '' : '; Path=' . $cookieParams['path'])
-            . (empty($cookieParams['samesite']) ? '' : '; SameSite=' . $cookieParams['samesite'])
-            . (!$cookieParams['secure'] ? '' : '; Secure')
-            . (!$cookieParams['httponly'] ? '' : '; HttpOnly')];
-    }
 }

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

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

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

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

+ 1 - 18
src/Worker.php

@@ -26,6 +26,7 @@ use Workerman\Events\Select;
  * Worker class
  * A container for listening ports
  */
+#[\AllowDynamicProperties]
 class Worker
 {
     /**
@@ -537,11 +538,6 @@ class Worker
     protected $workerId = null;
 
     /**
-     * Dynamic Properties。
-     */
-    use Properties;
-
-    /**
      * Run all worker instances.
      *
      * @return void
@@ -703,19 +699,6 @@ class Worker
     }
 
     /**
-     * Reload all worker instances.
-     *
-     * @return void
-     */
-    public static function reloadAllWorkers()
-    {
-        static::init();
-        static::initWorkers();
-        static::displayUI();
-        static::$status = static::STATUS_RELOADING;
-    }
-
-    /**
      * Get all worker instances.
      *
      * @return Worker[]