This commit is contained in:
as2252258@163.com
2021-08-28 00:51:27 +08:00
parent c4144f2913
commit f052cf1fbf
13 changed files with 7 additions and 666 deletions
-98
View File
@@ -1,98 +0,0 @@
<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri\Kiri;
/**
* Class GiiInterceptor
* @package Gii
*/
class GiiInterceptor extends GiiBase
{
public ?string $tableName = null;
/**
* @return bool|array
* @throws Exception
*/
public function generate(): bool|array
{
$managerName = $this->input->get('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}
$html = '<?php
namespace App\Http\Interceptor;
';
$file = APP_PATH . 'app/Http/Interceptor/' . $managerName . 'Interceptor.php';
if (file_exists($file)) {
try {
$class = new \ReflectionClass('App\\Http\\Interceptor\\' . $managerName . 'Interceptor');
$html .= $this->getImports($file, $class);
} catch (\Throwable $exception) {
return logger()->addError($exception, 'throwable');
}
} else {
$html .= '
use Closure;
use Http\Context\Request;
use Http\IInterface\Interceptor;
';
}
$managerName = ucfirst($managerName);
$html .= '
/**
* Class ' . $managerName . 'Interceptor
* @package App\Http\Interceptor
*/
class ' . $managerName . 'Interceptor implements Interceptor
{';
if (isset($class)) {
$html .= $this->getClassProperty($class);
$html .= $this->getClassMethods($class);
$html .= '
}';
} else {
$html .= '
/**
* @param Request $request
* @param Closure $closure
* @return mixed
*/
public function Interceptor(Request $request, Closure $closure)
{
return $closure($request);
}
}';
}
if (file_exists($file)) {
throw new Exception('File exists.');
}
Kiri::writeFile($file, $html);
return [$managerName . 'Interceptor.php'];
}
}
-75
View File
@@ -1,75 +0,0 @@
<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri\Kiri;
/**
* Class GiiLimits
* @package Gii
*/
class GiiLimits extends GiiBase
{
public ?string $tableName = '';
/**
* @return string[]
* @throws Exception
*/
public function generate(): array
{
$managerName = $this->input->get('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}
$html = '<?php
namespace App\Http\Limits;
use Closure;
use Http\Context\Request;
use Http\IInterface\Limits;
';
$managerName = ucfirst($managerName);
$html .= '
/**
* Class ' . $managerName . 'Limits
* @package App\Http\Limits
*/
class ' . $managerName . 'Limits implements Limits
{
/**
* @param Request $request
* @param Closure $closure
* @return mixed
*/
public function next(Request $request, Closure $closure)
{
return $closure($request);
}
}';
$file = APP_PATH . 'app/Http/Limits/' . $managerName . 'Limits.php';
if (file_exists($file)) {
throw new Exception('File exists.');
}
Kiri::writeFile($file, $html);
return [$managerName . 'Limits.php'];
}
}
-1
View File
@@ -33,7 +33,6 @@ class GiiMiddleware extends GiiBase
namespace App\Http\Middleware;
use Closure;
use Http\Context\Request;
use Http\IInterface\MiddlewareInterface;
use Server\RequestInterface;