Browse Source

删除注解功能,修改demo

xaboy 1 year ago
parent
commit
cd0e5644ec

+ 10 - 0
demo/demo.php

@@ -1,4 +1,14 @@
 <?php
+/**
+ * PHP表单生成器
+ *
+ * @package  FormBuilder
+ * @author   xaboy <xaboy2005@qq.com>
+ * @version  2.0
+ * @license  MIT
+ * @link     https://github.com/xaboy/form-builder
+ * @document http://php.form-create.com
+ */
 
 namespace App;
 

+ 60 - 155
demo/elm.php

@@ -1,162 +1,67 @@
 <?php
+/**
+ * PHP表单生成器
+ *
+ * @package  FormBuilder
+ * @author   xaboy <xaboy2005@qq.com>
+ * @version  2.0
+ * @license  MIT
+ * @link     https://github.com/xaboy/form-builder
+ * @document http://php.form-create.com
+ */
 
 namespace App;
 
-
-require '../vendor/autoload.php';
-
-use FormBuilder\Annotation\Col;
-use FormBuilder\Annotation\Emit;
-use FormBuilder\Annotation\Group;
-use FormBuilder\Annotation\Validate\Required;
-use FormBuilder\Annotation\Validate\Min;
-use FormBuilder\Annotation\Validate\Range;
 use FormBuilder\Factory\Elm;
-use FormBuilder\Handle\ElmFormHandle;
-use FormBuilder\UI\Elm\Components\Rate;
-use FormBuilder\UI\Iview\Components\DatePicker;
-
-
-class GoodsForm extends ElmFormHandle
-{
-    protected $action = 'save.php';
-    protected $title = '测试 Handle';
-    protected $fieldTitles = [
-        'start_time' => '开启时间',
-        'star' => '点赞'
-    ];
-
-    protected $scene = 'get';
-
-    protected function getScene()
-    {
-//        $this->except = ['goods_name'];
-    }
-
-    /**
-     * @Col(6)
-     * @return \FormBuilder\UI\Elm\Components\Input
-     */
-    public function goods_name_field()
-    {
-        return Elm::input('goods_name', '商品名称')->required();
-    }
-
-    /**
-     * @Required()
-     * @Group()
-     * @Col(8)
-     * @Range({10,1000},message = "最少输入10个字")
-     * @return \FormBuilder\UI\Elm\Components\Input
-     */
-    public function goods_info_field()
-    {
-        return Elm::textarea('goods_info', '商品简介');
-    }
-
-    /**
-     * @Group()
-     * @Col(8)
-     * @Emit({"change","click"})
-     * @return \FormBuilder\UI\Elm\Components\Switches
-     */
-    public function is_open_field()
-    {
-        return Elm::switches('is_open', '是否开启');
-    }
-
-    /**
-     * @Group(2)
-     * @Col(12)
-     * @return \FormBuilder\UI\Elm\Components\Frame
-     */
-    public function frame_field()
-    {
-        return Elm::frameFile('as', 'asd', 'afsdfasdf');
-    }
 
-    /**
-     * @Group(2)
-     * @Col(12)
-     * @return \FormBuilder\UI\Elm\Components\Upload
-     */
-    public function test_field()
-    {
-        return Elm::uploadFiles('aaa', 'aaa', 'bbb', [1])->required();
-    }
-
-    /**
-     * @return \FormBuilder\UI\Elm\Components\Hidden
-     */
-    public function id_field()
-    {
-        return Elm::hidden('1', '1');
-    }
-
-    /**
-     * @Required("请输入 testRow")
-     * @return array
-     */
-    public function row_field()
-    {
-//        return [
-//            'type' => 'row',
-//            'children' =>
-//                [
-        return [
-            'type' => 'input',
-            'field' => 'row',
-            'title' => 'test Row',
-            'value' => '123',
-            'col' => [
-                'span' => 12
+$api = '/save.php';
+$form = Elm::createForm($api);
+$rules = [
+    Elm::input('svip_name', '会员名:')->required(),
+    Elm::radio('svip_type', '会员类别:', '2')
+        ->setOptions([
+            ['value' => '1', 'label' => '试用期',],
+            ['value' => '2', 'label' => '有限期',],
+            ['value' => '3', 'label' => '永久期',],
+        ])->control([
+            [
+                'value' => '1',
+                'rule' => [
+                    Elm::number('svip_number', '有效期(天):')->required()->min(0),
+                ]
+            ],
+            [
+                'value' =>'2',
+                'rule' => [
+                    Elm::number('svip_number', '有效期(天):')->required()->min(0),
+                ]
+            ],
+            [
+                'value' => '3',
+                'rule' => [
+                    Elm::input('svip_number1', '有效期(天):','永久期')->disabled(true)->placeholder('请输入有效期'),
+                    Elm::input('svip_number', '有效期(天):','永久期')->hiddenStatus(true)->placeholder('请输入有效期'),
+                ]
+            ],
+        ])->appendRule('suffix', [
+            'type' => 'div',
+            'style' => ['color' => '#999999'],
+            'domProps' => [
+                'innerHTML' =>'试用期每个用户只能购买一次,购买过付费会员之后将不在展示,不可购买',
             ]
-        ];
-//        ,
-//                Elm::input('row2', 'row2', 'asdf')->col(12)
-//            ],
-//            'native' => true
-//        ];
-    }
-
-    /**
-     * 通过依赖注入方式生成组件
-     *
-     * @param DatePicker $date
-     * @return DatePicker
-     */
-    public function start_time_field(DatePicker $date)
-    {
-        return $date->required()->info('asdfasdfasdfsf');
-    }
-
-    public function starField(Rate $rate)
-    {
-        return $rate;
-    }
-
-    protected function getFormConfig()
-    {
-        $config = Elm::config();
-        $config->createResetBtn()->show(true);
-
-        return $config;
-    }
-
-    protected function getFormData()
-    {
-        return [
-            'goods_name' => 'goods_name123',
-            'asdf' => 'asdfafd',
-            'is_open' => '0',
-            'goods_info' => "asdf\r\nadfa",
-            'star' => 0,
-            'row' => 'adsfasdfasd'
-        ];
-    }
-}
-
-$formHtml = (new GoodsForm())->view();
-//$formHtml = (new GoodsForm())->form()->view();
-
-echo $formHtml;
+        ]),
+    Elm::number('cost_price', '原价:')->required(),
+    Elm::number('price', '优惠价:')->required(),
+    Elm::number('sort', '排序:'),
+    Elm::switches('status', '是否显示:')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
+];
+$form->setRule($rules);
+$form->setTitle('demo');
+
+$rule = $form->formRule();
+$action = $form->getAction();
+$method = $form->getMethod();
+$title = $form->getTitle();
+$view = $form->view();
+
+var_dump(compact('rule', 'action', 'method', 'title', 'view', 'api'));

+ 0 - 140
demo/iview.php

@@ -1,140 +0,0 @@
-<?php
-
-namespace App;
-
-
-require '../vendor/autoload.php';
-
-use FormBuilder\Annotation\Col;
-use FormBuilder\Annotation\Group;
-use  FormBuilder\Factory\Iview;
-use FormBuilder\Handle\ElmFormHandle;
-use FormBuilder\Handle\IviewFormHandle;
-use FormBuilder\FormHandle;
-use FormBuilder\UI\Elm\Components\Checkbox;
-use FormBuilder\UI\Elm\Components\Rate;
-use FormBuilder\UI\Iview\Components\DatePicker;
-
-
-class GoodsForm extends IviewFormHandle
-{
-    protected $action = 'save.php';
-    protected $title = '测试 Handle';
-    protected $fieldTitles = [
-        'start_time' => '开启时间',
-        'star' => '点赞'
-    ];
-
-    protected $scene = 'get';
-
-    protected function getScene()
-    {
-//        $this->except = ['goods_name'];
-    }
-
-    /**
-     * @Col(12)
-     * @return \FormBuilder\UI\Iview\Components\Input
-     */
-    public function goods_name_field()
-    {
-        return Iview::input('goods_name', '商品名称')->required();
-    }
-
-    /**
-     * @Group(className="test")
-     * @Col(12)
-     * @return \FormBuilder\UI\Iview\Components\Input
-     */
-    public function goods_info_field()
-    {
-        return Iview::textarea('goods_info', '商品简介');
-    }
-
-    /**
-     * @Group()
-     * @Col(12)
-     * @return \FormBuilder\UI\Iview\Components\Switches
-     */
-    public function is_open_field()
-    {
-        return Iview::switches('is_open', '是否开启');
-    }
-
-    public function id_field()
-    {
-        return Iview::hidden('1', '1');
-    }
-
-    public function frame_field()
-    {
-        return Iview::frame('as', 'asd', 'afsdfasdf');
-    }
-
-    public function test_field()
-    {
-        return Iview::dateTime('aaa', 'aaa')->required();
-    }
-
-    public function row_field()
-    {
-        return [
-            'type' => 'row',
-            'children' => [
-                [
-                    'type' => 'input',
-                    'field' => 'row',
-                    'title' => 'test Row',
-                    'value' => '123',
-                    'col' => [
-                        'span' => 12
-                    ]
-                ],
-                Iview::input('row2', 'row2', 'asdf')->col(12)
-            ],
-            'native' => true
-        ];
-    }
-
-    /**
-     * 通过依赖注入方式生成组件
-     *
-     * @param DatePicker $date
-     * @return DatePicker
-     */
-    public function start_time_field(DatePicker $date)
-    {
-        return $date->required()->info('asdfasdfasdfsf');
-    }
-
-    public function starField(Rate $rate)
-    {
-        return $rate;
-    }
-
-    protected function getFormConfig()
-    {
-        $config = Iview::config();
-        $config->createResetBtn()->show(true);
-
-        return $config;
-    }
-
-    protected function getFormData()
-    {
-        return [
-            'goods_name' => 'goods_name123',
-            'asdf' => 'asdfafd',
-            'is_open' => '0',
-            'goods_info' => "asdf\r\nadfa",
-            'start_time' => '1999-11-11',
-            'star' => 0,
-            'row' => 'adsfasdfasd'
-        ];
-    }
-}
-
-$formHtml = (new GoodsForm())->view();
-//$formHtml = (new GoodsForm())->form()->view();
-
-echo $formHtml;

+ 22 - 0
demo/upload.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * PHP表单生成器
+ *
+ * @package  FormBuilder
+ * @author   xaboy <xaboy2005@qq.com>
+ * @version  2.0
+ * @license  MIT
+ * @link     https://github.com/xaboy/form-builder
+ * @document http://php.form-create.com
+ */
+
+
+namespace App;
+
+
+use FormBuilder\Response;
+
+require '../vendor/autoload.php';
+
+//上传接口响应
+Response::uploadSuccess('https://user-images.githubusercontent.com/37764940/83014819-f582b300-a051-11ea-8979-e7b02b372795.png')->send();

+ 0 - 122
src/Annotation/AnnotationReader.php

@@ -1,122 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-
-use Doctrine\Common\Annotations\AnnotationRegistry;
-use Doctrine\Common\Annotations\AnnotationReader as Render;
-use FormBuilder\Contract\AnnotationInterface;
-use FormBuilder\FormHandle;
-use FormBuilder\Util;
-
-class AnnotationReader
-{
-    protected static $isInit = false;
-
-    /**
-     * @var Render
-     */
-    protected $annotationReader;
-
-    /**
-     * @var FormHandle
-     */
-    protected $handle;
-
-    public function __construct(FormHandle $handle)
-    {
-        if (!self::$isInit) {
-            AnnotationRegistry::registerLoader('class_exists');
-            self::$isInit = true;
-        }
-
-        $this->annotationReader = new Render();
-        $this->handle = $handle;
-    }
-
-    public function getRender()
-    {
-        return $this->annotationReader;
-    }
-
-    /**
-     * @return array
-     * @throws \ReflectionException
-     */
-    public function render()
-    {
-        $reflectionClass = new \ReflectionClass($this->handle);
-        $methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
-        $rule = [];
-        $except = $this->handle->getExcept();
-        foreach ($methods as $method) {
-            $field = preg_replace('/^(.+)(Field|_field)$/', '$1', $method->name);
-            $value = null;
-            if ($field != $method->name && !in_array($field, $except)) {
-                $params = $method->getParameters();
-                if (isset($params[0]) && ($dep = $params[0]->getClass())) {
-                    if (in_array('FormBuilder\\Contract\\FormComponentInterface', $dep->getInterfaceNames())) {
-                        $componentClass = $dep->getName();
-                        $value = $method->invokeArgs($this->handle, [new $componentClass($field, $this->handle->getFieldTitle($field))]);
-                    }
-                }
-                if (is_null($value)) $value = $method->invoke($this->handle);
-                if (!is_null($value) && (($isArray = is_array($value)) || Util::isComponent($value))) {
-                    $rule[] = compact('value', 'method', 'isArray');
-                }
-            }
-        }
-        return $this->parse($rule);
-    }
-
-    /**
-     * @param $rules
-     * @return array
-     */
-    protected function parse($rules)
-    {
-        $formRule = [];
-        $groupList = [];
-        foreach ($rules as $rule) {
-            $annotations = $this->annotationReader->getMethodAnnotations($rule['method']);
-            $value = $rule['value'];
-            $group = null;
-            foreach ($annotations as $annotation) {
-                if (!$annotation instanceof AnnotationInterface) continue;
-                if ($annotation instanceof Group) {
-                    $group = $annotation;
-                } else {
-                    $value = $rule['isArray'] ? $annotation->parseRule($value) : $annotation->parseComponent($value);
-                }
-            }
-
-            if (!is_null($group)) {
-                if (!isset($groupList[$group->id])) {
-                    $groupList[$group->id] = $group;
-                    $formRule[] = $group;
-                }
-                $groupList[$group->id]->appendChildren($value);
-            } else {
-                $formRule[] = $value;
-            }
-        }
-
-        foreach ($formRule as $k => $v) {
-            if ($v instanceof Group) {
-                $formRule[$k] = $v->parse($this->handle->ui());
-            }
-        }
-
-        return $formRule;
-    }
-}

+ 0 - 39
src/Annotation/ClassName.php

@@ -1,39 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- */
-final class ClassName implements AnnotationInterface
-{
-
-    /**
-     * @var string
-     */
-    public $className = '';
-
-    public function parseRule($rule)
-    {
-        $rule['className'] = $this->className;
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->className($this->className);
-        return $component;
-    }
-}

+ 0 - 45
src/Annotation/Col.php

@@ -1,45 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- */
-final class Col implements AnnotationInterface
-{
-    public $props = 24;
-
-    protected function getCol()
-    {
-        if (is_integer($this->props))
-            return ['span' => $this->props];
-        else
-            return $this->props;
-    }
-
-    public function parseRule($rule)
-    {
-        $rule['col'] = $this->getCol();
-
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->col($this->getCol());
-
-        return $component;
-    }
-}

+ 0 - 47
src/Annotation/Emit.php

@@ -1,47 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- */
-final class Emit implements AnnotationInterface
-{
-    /**
-     * @var array
-     */
-    public $emit = [];
-
-    /**
-     * @var string
-     */
-    public $prefix = '';
-
-
-    public function parseRule($rule)
-    {
-        $rule['emit'] = $this->emit;
-        if ($this->prefix)
-            $rule['emitPrefix'] = $this->prefix;
-
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->emit($this->emit)->emitPrefix($this->prefix);
-        return $component;
-    }
-}

+ 0 - 86
src/Annotation/Group.php

@@ -1,86 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- */
-final class Group implements AnnotationInterface
-{
-    /**
-     * @var int
-     */
-    public $id = 1;
-
-    /**
-     * @var string
-     */
-    public $tag;
-
-    /**
-     * @var string
-     */
-    public $className = '';
-
-    public $span = 24;
-
-    protected $children = [];
-
-    public function parseRule($rule)
-    {
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        return $component;
-    }
-
-    public function appendChildren($rule)
-    {
-        $this->children[] = $rule;
-    }
-
-    /**
-     * @param string $UI
-     * @return array
-     */
-    public function parse($UI)
-    {
-        $col = 'i-col';
-        $row = 'row';
-        if ($UI == 'elm') {
-            $row = 'el-row';
-            $col = 'el-col';
-        }
-
-        return [
-            'type' => $col,
-            'props' => [
-                'span' => $this->span
-            ],
-            'children' => [
-                [
-                    'type' => is_null($this->tag) ? $row : $this->tag,
-                    'children' => $this->children,
-                    'attrs' => [
-                        'class' => $this->className
-                    ]
-                ]
-            ],
-            'native' => true
-        ];
-    }
-}

+ 0 - 40
src/Annotation/Info.php

@@ -1,40 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- */
-final class Info implements AnnotationInterface
-{
-    /**
-     * @var string
-     */
-    public $info = '';
-
-    public function parseRule($rule)
-    {
-        $rule['info'] = $this->info;
-
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->info($this->info);
-
-        return $component;
-    }
-}

+ 0 - 40
src/Annotation/Validate/Enum.php

@@ -1,40 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Enum extends ValidateAnnotation
-{
-    /**
-     * @Required
-     * @var array
-     */
-    public $value = [];
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['enum' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->enum($this->value)->message($this->message));
-        return $component;
-    }
-}

+ 0 - 39
src/Annotation/Validate/Len.php

@@ -1,39 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Len extends ValidateAnnotation
-{
-    /**
-     * @Required
-     */
-    public $value;
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['len' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->len($this->value)->message($this->message));
-        return $component;
-    }
-}

+ 0 - 39
src/Annotation/Validate/Max.php

@@ -1,39 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Max extends ValidateAnnotation
-{
-    /**
-     * @Required
-     */
-    public $value;
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['max' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->max($this->value)->message($this->message));
-        return $component;
-    }
-}

+ 0 - 39
src/Annotation/Validate/Min.php

@@ -1,39 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Min extends ValidateAnnotation
-{
-    /**
-     * @Required
-     */
-    public $value;
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['min' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->min($this->value)->message($this->message));
-        return $component;
-    }
-}

+ 0 - 40
src/Annotation/Validate/Pattern.php

@@ -1,40 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Pattern extends ValidateAnnotation
-{
-    /**
-     * @Required
-     * @var string
-     */
-    public $value = '';
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['pattern' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->pattern($this->value)->message($this->message));
-        return $component;
-    }
-}

+ 0 - 40
src/Annotation/Validate/Range.php

@@ -1,40 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-/**
- * @Annotation
- */
-final class Range extends ValidateAnnotation
-{
-    /**
-     * @Required
-     * @var array
-     */
-    public $value = [];
-
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['validate'][] = ['range' => $this->value, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->appendValidate($component->createValidate()->range($this->value[0], $this->value[1])->message($this->message));
-        return $component;
-    }
-}

+ 0 - 38
src/Annotation/Validate/Required.php

@@ -1,38 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-use FormBuilder\Contract\AnnotationInterface;
-
-/**
- * @Annotation
- * Class RuleAnnotation
- * @package FormBuilder
- */
-final class Required extends ValidateAnnotation
-{
-
-    public function parseRule($rule)
-    {
-        $rule = $this->tidyValidate($rule);
-        $rule['required'] = true;
-        $rule['validate'][] = ['required' => true, 'type' => $this->type, 'trigger' => $this->trigger, 'message' => $this->message];
-        return $rule;
-    }
-
-    public function parseComponent($component)
-    {
-        $component->required($this->message);
-        return $component;
-    }
-}

+ 0 - 44
src/Annotation/Validate/ValidateAnnotation.php

@@ -1,44 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Annotation\Validate;
-
-
-use FormBuilder\Contract\AnnotationInterface;
-
-abstract class ValidateAnnotation implements AnnotationInterface
-{
-
-    /**
-     * @var string
-     */
-    public $message;
-
-    /**
-     * @var string
-     */
-    public $type = 'string';
-
-    /**
-     * @var string
-     */
-    public $trigger = 'change';
-
-
-    public function tidyValidate($rule)
-    {
-        if (!isset($rule['validate']) || !is_array($rule['validate'])) {
-            $rule['validate'] = [];
-        }
-        return $rule;
-    }
-}

+ 0 - 153
src/FormHandle.php

@@ -1,153 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder;
-
-
-use FormBuilder\Annotation\AnnotationReader;
-use FormBuilder\Contract\ConfigInterface;
-use FormBuilder\Contract\FormHandleInterface;
-
-/**
- * 表单生成类
- *
- * Class FormHandle
- * @package FormBuilder
- */
-abstract class FormHandle implements FormHandleInterface
-{
-    protected $action = '';
-
-    protected $method = 'POST';
-
-    protected $title;
-
-    protected $formContentType;
-
-    protected $headers = [];
-
-    protected $fieldTitles = [];
-
-    protected $except = [];
-
-    protected $scene;
-
-    /**
-     * 表单 UI
-     *
-     * @return mixed
-     */
-    abstract public function ui();
-
-    final public function getExcept()
-    {
-        return $this->except;
-    }
-
-    /**
-     * 获取表单数据
-     * @return array
-     */
-    protected function getFormData()
-    {
-        return [];
-    }
-
-    public function scene($scene = null)
-    {
-        if (!is_null($scene)) $this->scene = $scene;
-        return $this->scene;
-    }
-
-    /**
-     * 获取表单配置
-     *
-     * @return mixed|array|ConfigInterface
-     */
-    protected function getFormConfig()
-    {
-        return;
-    }
-
-    public function getFieldTitle($field)
-    {
-        return isset($this->fieldTitles[$field]) ? $this->fieldTitles[$field] : null;
-    }
-
-    /**
-     * 获取表单组件
-     *
-     * @return array
-     * @throws \ReflectionException
-     */
-    protected function getFormRule()
-    {
-        $render = new AnnotationReader($this);
-        return $render->render();
-    }
-
-    /**
-     * 创建表单
-     *
-     * @return Form
-     * @throws \ReflectionException
-     */
-    protected function createForm()
-    {
-        $ui = lcfirst($this->ui());
-        return call_user_func_array(['FormBuilder\\Form', $ui], $this->getParams());
-    }
-
-    /**
-     * @return array
-     * @throws \ReflectionException
-     */
-    protected function getParams()
-    {
-        $params = [$this->action, $this->getFormRule()];
-        $config = $this->getFormConfig();
-        if (is_array($config) || $config instanceof ConfigInterface)
-            $params[] = $config;
-
-        return $params;
-    }
-
-    /**
-     * 获取表单
-     *
-     * @return Form
-     * @throws \ReflectionException
-     */
-    public function form()
-    {
-        if ($this->scene && method_exists($this, $this->scene . 'Scene'))
-            $this->{$this->scene . 'Scene'}();
-
-        $form = $this->createForm()->setMethod($this->method);
-        if (!is_null($this->title)) $form->setTitle($this->title)->headers($this->headers);
-        $formData = $this->getFormData();
-        if (is_array($formData)) $form->formData($formData);
-        if ($this->formContentType) $form->setFormContentType($this->formContentType);
-        $config = $this->getFormConfig();
-        if ($config) $form->setConfig($config);
-        return $form;
-    }
-
-    /**
-     * @return string
-     * @throws \ReflectionException
-     */
-    public function view()
-    {
-        return $this->form()->view();
-    }
-}

+ 0 - 30
src/Handle/ElmFormHandle.php

@@ -1,30 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Handle;
-
-
-use FormBuilder\FormHandle;
-
-/**
- * ElementUI 表单生成类
- * Class ElmFormHandle
- * @package FormBuilder\Factory
- */
-abstract class ElmFormHandle extends FormHandle
-{
-
-    public function ui()
-    {
-        return 'elm';
-    }
-}

+ 0 - 33
src/Handle/IviewFormHandle.php

@@ -1,33 +0,0 @@
-<?php
-/**
- * PHP表单生成器
- *
- * @package  FormBuilder
- * @author   xaboy <xaboy2005@qq.com>
- * @version  2.0
- * @license  MIT
- * @link     https://github.com/xaboy/form-builder
- * @document http://php.form-create.com
- */
-
-namespace FormBuilder\Handle;
-
-
-use FormBuilder\FormHandle;
-
-/**
- * Iview 表单生成类
- *
- * Class IviewFormHandle
- * @package FormBuilder\Factory
- */
-abstract class IviewFormHandle extends FormHandle
-{
-
-    protected $version = 3;
-
-    public function ui()
-    {
-        return $this->version == 4 ? 'iview4' : 'iview';
-    }
-}