fixed:云上传配置无法生效

This commit is contained in:
JaguarJack 2020-11-19 09:42:54 +08:00
parent e4a5ae0c37
commit 78e782dd01
10 changed files with 503 additions and 15 deletions

View File

@ -15,6 +15,7 @@ use catcher\base\CatchController;
use catcher\base\CatchRequest; use catcher\base\CatchRequest;
use catcher\CatchResponse; use catcher\CatchResponse;
use catcher\CatchUpload; use catcher\CatchUpload;
use catcher\exceptions\FailedException;
class Upload extends CatchController class Upload extends CatchController
{ {
@ -37,6 +38,10 @@ class Upload extends CatchController
{ {
$images = $request->file(); $images = $request->file();
if (!$images) {
throw new FailedException('请选择图片上传');
}
return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image'])); return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image']));
} }

View File

@ -261,20 +261,11 @@ class CatchUpload
if ($upload) { if ($upload) {
$disk = app()->config->get('filesystem.disks'); $disk = app()->config->get('filesystem.disks');
$uploadConfigs = $configModel->getConfig($upload->id); $uploadConfigs = $configModel->getConfig($upload->component);
// 重组
$_config = [];
if (!empty($uploadConfigs)) { 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; // $disk[$key]['type'] = $key;
// 腾讯云配置处理 // 腾讯云配置处理
if (strtolower($key) == 'qcloud') { 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 (!in_array($key, ['public', 'local'])) {
if ($_config[$key] ?? false) { if ($uploadConfigs[$key] ?? false) {
foreach ($_config[$key] as $k => $value) { foreach ($uploadConfigs[$key] as $k => $value) {
$item[$k] = $value; $item[$k] = $value;
} }
} }
} }
}); });
// 重新分配配置 // 重新分配配置
app()->config->set([ app()->config->set([
'disk' => $disk, 'disks' => $disk,
], 'filesystem'); ], 'filesystem');
} }
} }

View File

@ -0,0 +1,49 @@
<?php
namespace catcher\generate\build;
use catcher\generate\build\classes\Classes;
use PhpParser\BuilderFactory;
use PhpParser\PrettyPrinter\Standard;
class PHPBuild
{
protected $astBuilder;
public function __construct()
{
$this->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));
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace catcher\generate\classes;
class Classes extends Iteration
{
/**
*
* @time 2020年11月17日
* @param $name
* @return $this
*/
public function name($name)
{
$this->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];
}
}

View File

@ -0,0 +1,159 @@
<?php
namespace catcher\generate\classes;
class Methods extends Iteration
{
protected $method = [];
/**
* set method name
*
* @time 2020年11月16日
* @param string $method
* @return $this
*/
public function name(string $method)
{
$this->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;
}
}

View File

@ -0,0 +1,97 @@
<?php
namespace catcher\generate\build\classes;
use PhpParser\BuilderFactory;
class Properties
{
protected $propertyBuild;
public function __construct(string $name)
{
$this->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;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace catcher\generate\classes;
class Traits extends Iteration
{
protected $trait = [];
public function name($name)
{
if (!empty($this->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;
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace catcher\generate\classes;
use think\helper\Str;
class Uses extends Iteration
{
protected $uses;
public function __construct($uses)
{
$delimiter = ' as ';
foreach ($uses as $key => $use) {
if (Str::contains($use, $delimiter)) {
$uses[$key] = explode($delimiter, $use);
}
}
$this->data = $uses;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace catcher\generate\build\traits;
class MethodReturn
{
public function index()
{
}
public function save()
{
}
public function update()
{
}
public function read()
{
}
public function delete()
{
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace catcher\generate\build\types;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
class Array_
{
public function build($array)
{
$items = [];
foreach ($array as $item) {
$items[] = new ArrayItem(new String_($item));
}
return new \PhpParser\Node\Expr\Array_($items);
}
}