This commit is contained in:
2021-03-25 18:28:41 +08:00
parent e89ce9f2f1
commit 823c1ded50
4 changed files with 140 additions and 103 deletions
+29 -6
View File
@@ -19,10 +19,10 @@ class GiiInterceptor extends GiiBase
/**
* @return string[]
* @return bool|array
* @throws Exception
*/
public function generate(): array
public function generate(): bool|array
{
$managerName = $this->input->get('name', null);
@@ -34,12 +34,24 @@ class GiiInterceptor extends GiiBase
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);
}
} else {
$html .= '
use Closure;
use HttpServer\Http\Request;
use HttpServer\IInterface\Interceptor;
';
}
$managerName = ucfirst($managerName);
$html .= '
@@ -48,7 +60,17 @@ use HttpServer\IInterface\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
@@ -62,8 +84,9 @@ class ' . $managerName . 'Interceptor implements Interceptor
}';
}
$file = APP_PATH . 'app/Http/Interceptor/' . $managerName . 'Interceptor.php';
if (file_exists($file)) {
unlink($file);
}