Browse Source

Properties

walkor 2 years ago
parent
commit
e2846d5a58
1 changed files with 57 additions and 0 deletions
  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]);
+    }
+}