瀏覽代碼

Properties

walkor 2 年之前
父節點
當前提交
e2846d5a58
共有 1 個文件被更改,包括 57 次插入0 次删除
  1. 57 0
      src/Properties.php

+ 57 - 0
src/Properties.php

@@ -0,0 +1,57 @@
+<?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]);
+    }
+}