add:新增表单生成
This commit is contained in:
34
extend/catcher/library/form/FormFactory.php
Normal file
34
extend/catcher/library/form/FormFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace catcher\library\form;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
abstract class FormFactory
|
||||
{
|
||||
|
||||
abstract public static function from();
|
||||
|
||||
/**
|
||||
* 创建 Form
|
||||
*
|
||||
* @time 2021年03月02日
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function create($name)
|
||||
{
|
||||
$form = static::from() . '\\'. ucfirst($name);
|
||||
|
||||
if (!class_exists($form)) {
|
||||
throw new FailedException(sprintf('Form [%s] not found! Please create it first', ucfirst($name)));
|
||||
}
|
||||
|
||||
$form = app($form);
|
||||
|
||||
if (!$form instanceof Form) {
|
||||
throw new FailedException(sprintf('Form [%s] must implements interface [FormCreate]', ucfirst($name)));
|
||||
}
|
||||
|
||||
return $form->create();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user