From 78e782dd0162f81ca2f66c98e6c55129d4333990 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Thu, 19 Nov 2020 09:42:54 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=E4=BA=91=E4=B8=8A=E4=BC=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=97=A0=E6=B3=95=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/system/controller/Upload.php | 5 + extend/catcher/CatchUpload.php | 22 +-- extend/catcher/generate/build/CatchBuild.php | 49 ++++++ .../generate/build/classes/Classes.php | 75 +++++++++ .../generate/build/classes/Methods.php | 159 ++++++++++++++++++ .../generate/build/classes/Property.php | 97 +++++++++++ .../catcher/generate/build/classes/Traits.php | 37 ++++ .../catcher/generate/build/classes/Uses.php | 23 +++ .../build/traits/CatchMethodReturn.php | 31 ++++ extend/catcher/generate/build/types/Arr.php | 20 +++ 10 files changed, 503 insertions(+), 15 deletions(-) create mode 100644 extend/catcher/generate/build/CatchBuild.php create mode 100644 extend/catcher/generate/build/classes/Classes.php create mode 100644 extend/catcher/generate/build/classes/Methods.php create mode 100644 extend/catcher/generate/build/classes/Property.php create mode 100644 extend/catcher/generate/build/classes/Traits.php create mode 100644 extend/catcher/generate/build/classes/Uses.php create mode 100644 extend/catcher/generate/build/traits/CatchMethodReturn.php create mode 100644 extend/catcher/generate/build/types/Arr.php diff --git a/catch/system/controller/Upload.php b/catch/system/controller/Upload.php index d3d5f39..079643d 100644 --- a/catch/system/controller/Upload.php +++ b/catch/system/controller/Upload.php @@ -15,6 +15,7 @@ use catcher\base\CatchController; use catcher\base\CatchRequest; use catcher\CatchResponse; use catcher\CatchUpload; +use catcher\exceptions\FailedException; class Upload extends CatchController { @@ -37,6 +38,10 @@ class Upload extends CatchController { $images = $request->file(); + if (!$images) { + throw new FailedException('请选择图片上传'); + } + return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image'])); } diff --git a/extend/catcher/CatchUpload.php b/extend/catcher/CatchUpload.php index 436484d..422d1b9 100644 --- a/extend/catcher/CatchUpload.php +++ b/extend/catcher/CatchUpload.php @@ -261,20 +261,11 @@ class CatchUpload if ($upload) { $disk = app()->config->get('filesystem.disks'); - $uploadConfigs = $configModel->getConfig($upload->id); + $uploadConfigs = $configModel->getConfig($upload->component); - // 重组 - $_config = []; if (!empty($uploadConfigs)) { - foreach ($uploadConfigs as $key => $value) { - list($object, $key) = explode('.', $key); - $_config[$object][$key] = $value; - } - } - - if (!empty($_config)) { // 读取上传可配置数据 - foreach ($_config as $key => &$config) { + foreach ($uploadConfigs as $key => &$config) { // $disk[$key]['type'] = $key; // 腾讯云配置处理 if (strtolower($key) == 'qcloud') { @@ -294,18 +285,19 @@ class CatchUpload } // 合并数组 - array_walk($disk, function (&$item, $key) use ($_config) { + array_walk($disk, function (&$item, $key) use ($uploadConfigs) { if (!in_array($key, ['public', 'local'])) { - if ($_config[$key] ?? false) { - foreach ($_config[$key] as $k => $value) { + if ($uploadConfigs[$key] ?? false) { + foreach ($uploadConfigs[$key] as $k => $value) { $item[$k] = $value; } } } }); + // 重新分配配置 app()->config->set([ - 'disk' => $disk, + 'disks' => $disk, ], 'filesystem'); } } diff --git a/extend/catcher/generate/build/CatchBuild.php b/extend/catcher/generate/build/CatchBuild.php new file mode 100644 index 0000000..480978c --- /dev/null +++ b/extend/catcher/generate/build/CatchBuild.php @@ -0,0 +1,49 @@ +astBuilder = app(BuilderFactory::class); + } + + public function namespace(string $namespace) + { + $this->astBuilder = $this->astBuilder->namespace('god'); + + return $this; + } + + public function use($use) + { + $this->astBuilder->addStmt($use); + + return $this; + } + + + public function class(Classes $class, \Closure $function) + { + $function($class); + + $this->astBuilder->addStmt($class->build()); + + + return $this; + } + + + public function finish() + { + $stmts = array($this->astBuilder->getNode()); + $prettyPrinter = new Standard(); + dd($prettyPrinter->prettyPrintFile($stmts)); + } +} \ No newline at end of file diff --git a/extend/catcher/generate/build/classes/Classes.php b/extend/catcher/generate/build/classes/Classes.php new file mode 100644 index 0000000..ac9be3c --- /dev/null +++ b/extend/catcher/generate/build/classes/Classes.php @@ -0,0 +1,75 @@ +data['name'] = $name; + + return $this; + } + + /** + * @time 2020年11月17日 + * @param $extend + * @return $this + */ + public function extend($extend) + { + $this->data['extend'] = $extend; + + return $this; + } + + /** + * @time 2020年11月17日 + * @param $interfaces + * @return $this + */ + public function interfaces($interfaces) + { + $this->data['interfaces'] = $interfaces; + + return $this; + } + + /** + * @time 2020年11月17日 + * @return $this + */ + public function isAbstract() + { + $this->data['type'] = 'Abstract'; + + return $this; + } + + /** + * @time 2020年11月17日 + * @return $this + */ + public function isFinal() + { + $this->data['type'] = 'Final'; + + return $this; + } + + /** + * @time 2020年11月17日 + * @param $type + * @param $param + * @return void + */ + public function construct($type, $param) + { + $this->data['construct'][] = [$type, $param]; + } +} diff --git a/extend/catcher/generate/build/classes/Methods.php b/extend/catcher/generate/build/classes/Methods.php new file mode 100644 index 0000000..304cd8b --- /dev/null +++ b/extend/catcher/generate/build/classes/Methods.php @@ -0,0 +1,159 @@ +method['name'] = $method; + + return $this; + } + + /** + * set visible + * + * @time 2020年11月16日 + * @param string $visibility + * @return $this + */ + public function visible(string $visibility) + { + $this->method['visible'] = $visibility; + + return $this; + } + + public function makePublic() + { + $this->method['visible'] = 'public'; + + return $this; + } + + public function makeProtected() + { + $this->method['visible'] = 'protected'; + + return $this; + } + + public function makePrivate() + { + $this->method['visible'] = 'private'; + + return $this; + } + + /** + * set params + * + * @time 2020年11月16日 + * @param $type + * @param $param + * @param $default + * @return $this + */ + public function param($param, $type = null, $default = null) + { + $this->method['params'][] = [ + 'type' => $type, + 'param' => $param, + 'default' => $default, + ]; + + return $this; + } + + /** + * 返回内容 + * + * @time 2020年11月17日 + * @param $return + * @return $this + */ + public function return($return) + { + $this->method['return'] = $return; + return $this; + } + + /** + * 返回值 + * + * @time 2020年11月16日 + * @param $return + * @return $this + */ + public function returnType($return) + { + $this->method['return'] = $return; + + return $this; + } + + + /** + * 注释 + * + * @time 2020年11月16日 + * @param $comment + * @return $this + */ + public function docComment($comment) + { + $this->method['comment'] = $comment; + + return $this; + } + + /** + * 抽象 + * + * @time 2020年11月17日 + * @return $this + */ + public function toAbstract() + { + $this->method['type'] = 'Abstract'; + + return $this; + } + + /** + * final + * + * @time 2020年11月17日 + * @return $this + */ + public function toFinal() + { + $this->method['type'] = 'Final'; + + return $this; + } + + /** + * join + * + * @time 2020年11月17日 + * @return $this + */ + public function join() + { + $this->data[] = $this->method; + + $this->method = []; + + return $this; + } +} diff --git a/extend/catcher/generate/build/classes/Property.php b/extend/catcher/generate/build/classes/Property.php new file mode 100644 index 0000000..6ae940d --- /dev/null +++ b/extend/catcher/generate/build/classes/Property.php @@ -0,0 +1,97 @@ +propertyBuild = (new BuilderFactory())->property($name); + } + + + /** + * @time 2020年11月17日 + * @return $this + */ + public function public() + { + $this->propertyBuild->makePublic(); + + return $this; + } + + /** + * @time 2020年11月17日 + * @return $this + */ + public function protected() + { + $this->propertyBuild->makeProtected(); + + return $this; + } + + /** + * @time 2020年11月17日 + * @return $this + */ + public function private() + { + $this->propertyBuild->makePrivate(); + + return $this; + } + + /** + * 注释 + * + * @time 2020年11月16日 + * @param $comment + * @return $this + */ + public function static($comment) + { + $this->propertyBuild->makeStatic(); + + return $this; + } + + + /** + * set default + * + * @time 2020年11月16日 + * @param $value + * @return $this + */ + public function default($value) + { + $this->propertyBuild->setDefault($value); + + return $this; + } + + + public function type($type) + { + $this->propertyBuild->setType($type); + + return $this; + } + + public function docComment($comment) + { + $this->propertyBuild->setDocComment($comment); + + return $this; + } + + public function build() + { + return $this->propertyBuild; + } +} diff --git a/extend/catcher/generate/build/classes/Traits.php b/extend/catcher/generate/build/classes/Traits.php new file mode 100644 index 0000000..8a4f651 --- /dev/null +++ b/extend/catcher/generate/build/classes/Traits.php @@ -0,0 +1,37 @@ +trait)) { + $this->data[] = $this->trait; + + $this->trait = []; + + return $this; + } + + $this->trait['name'] = $name; + + return $this; + } + + public function adaptation($name) + { + $this->trait['adaptation'] = $name; + } + + public function insteadof($name) + { + $this->trait['insteadof'] = $name; + } + + public function as($as) + { + $this->trait['as'] = $as; + } +} diff --git a/extend/catcher/generate/build/classes/Uses.php b/extend/catcher/generate/build/classes/Uses.php new file mode 100644 index 0000000..d8ed389 --- /dev/null +++ b/extend/catcher/generate/build/classes/Uses.php @@ -0,0 +1,23 @@ + $use) { + if (Str::contains($use, $delimiter)) { + $uses[$key] = explode($delimiter, $use); + } + } + + $this->data = $uses; + } +} \ No newline at end of file diff --git a/extend/catcher/generate/build/traits/CatchMethodReturn.php b/extend/catcher/generate/build/traits/CatchMethodReturn.php new file mode 100644 index 0000000..36e7c0e --- /dev/null +++ b/extend/catcher/generate/build/traits/CatchMethodReturn.php @@ -0,0 +1,31 @@ +