Files
kiri-core/Gii/GiiInterceptor.php
T

76 lines
1.2 KiB
PHP
Raw Normal View History

2020-09-11 18:53:09 +08:00
<?php
2020-10-30 01:07:28 +08:00
declare(strict_types=1);
2020-09-11 18:53:09 +08:00
namespace Gii;
use Exception;
use Snowflake\Snowflake;
/**
* Class GiiInterceptor
* @package Gii
*/
class GiiInterceptor extends GiiBase
{
2020-12-17 14:09:14 +08:00
public ?string $tableName = null;
2020-09-11 18:53:09 +08:00
/**
* @return string[]
* @throws Exception
*/
2020-12-17 14:09:14 +08:00
public function generate(): array
2020-09-11 18:53:09 +08:00
{
$managerName = $this->input->get('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}
$html = '<?php
namespace App\Http\Interceptor;
use Closure;
use HttpServer\Http\Request;
use HttpServer\IInterface\Interceptor;
';
$managerName = ucfirst($managerName);
$html .= '
/**
2020-09-11 18:57:16 +08:00
* Class ' . $managerName . 'Interceptor
2020-09-11 18:53:09 +08:00
* @package App\Http\Interceptor
*/
class ' . $managerName . 'Interceptor implements Interceptor
{
/**
* @param Request $request
* @param Closure $closure
* @return mixed
*/
public function Interceptor(Request $request, Closure $closure)
{
return $closure($request);
}
}';
2020-09-11 18:55:45 +08:00
$file = APP_PATH . 'app/Http/Interceptor/' . $managerName . 'Interceptor.php';
2020-09-11 18:53:09 +08:00
if (file_exists($file)) {
unlink($file);
}
Snowflake::writeFile($file, $html);
return [$managerName . 'Interceptor.php'];
}
}