Files
kiri-core/Gii/GiiLimits.php
T

76 lines
1.1 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 GiiLimits
* @package Gii
*/
class GiiLimits extends GiiBase
{
2020-12-17 14:09:14 +08:00
public ?string $tableName = '';
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\Limits;
use Closure;
use HttpServer\Http\Request;
use HttpServer\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);
}
}';
2020-09-11 18:55:45 +08:00
$file = APP_PATH . 'app/Http/Limits/' . $managerName . 'Limits.php';
2020-09-11 18:53:09 +08:00
if (file_exists($file)) {
unlink($file);
}
Snowflake::writeFile($file, $html);
return [$managerName . 'Limits.php'];
}
}