Browse Source

组件快速设置 props

xaboy 6 years ago
parent
commit
97e70021ad
1 changed files with 26 additions and 1 deletions
  1. 26 1
      src/Driver/CustomComponent.php

+ 26 - 1
src/Driver/CustomComponent.php

@@ -24,7 +24,7 @@ use FormBuilder\Rule\ValidateRule;
  * 自定义组件
  * Class CustomComponent
  */
-class CustomComponent implements CustomComponentInterface
+class CustomComponent implements CustomComponentInterface, \JsonSerializable, \ArrayAccess
 {
     use BaseRule;
     use ChildrenRule;
@@ -76,4 +76,29 @@ class CustomComponent implements CustomComponentInterface
             $this->parseChildrenRule()
         );
     }
+
+    public function jsonSerialize()
+    {
+        return $this->build();
+    }
+
+    public function offsetExists($offset)
+    {
+        return isset($this->props[$offset]);
+    }
+
+    public function offsetGet($offset)
+    {
+        return $this->props[$offset];
+    }
+
+    public function offsetSet($offset, $value)
+    {
+        $this->props[$offset] = $value;
+    }
+
+    public function offsetUnset($offset)
+    {
+        unset($this->props[$offset]);
+    }
 }