Browse Source

增加 魔法方法

xaboy 6 years ago
parent
commit
c3bab819bd
1 changed files with 15 additions and 0 deletions
  1. 15 0
      src/Driver/CustomComponent.php

+ 15 - 0
src/Driver/CustomComponent.php

@@ -46,6 +46,21 @@ class CustomComponent implements CustomComponentInterface
         $this->setRuleType(is_null($type) ? $this->getComponentName() : $type)->props($this->defaultProps);
         $this->setRuleType(is_null($type) ? $this->getComponentName() : $type)->props($this->defaultProps);
     }
     }
 
 
+    public function __toString()
+    {
+        return $this->toJson();
+    }
+
+    public function __invoke()
+    {
+        return $this->build();
+    }
+
+    public function toJson()
+    {
+        return json_encode($this->build());
+    }
+
     protected function getComponentName()
     protected function getComponentName()
     {
     {
         return lcfirst(basename(str_replace('\\', '/', get_class($this))));
         return lcfirst(basename(str_replace('\\', '/', get_class($this))));