Files
kiri-core/kiri-gii/GiiTask.php
T
as2252258 7b1cc1bd7b Revert "改名"
This reverts commit fdf58326
2022-01-12 14:10:33 +08:00

91 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri;
/**
* Class GiiModel
* @package Gii
*/
class GiiTask extends GiiBase
{
/**
* @return string[]
* @throws Exception
*/
public function generate(): array
{
$managerName = $this->input->getArgument('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}
$html = '<?php
namespace App\Async;
use Kiri\Server\Contract\OnTaskInterface;
';
$managerName = ucfirst($managerName);
$html .= '
/**
* Class ' . $managerName . '
* @package App\Async
*/
class ' . $managerName . ' implements Task
{
protected $params = [];
/**
* @return mixed|void
*/
public function onHandler()
{
// TODO: Implement handler() method.
}
/**
* @param $params
* @return $this
*/
public function setParams(array $params)
{
$this->params = $params;
return $this;
}
/**
* @return array
*/
public function getParams()
{
return $this->params;
}
}';
$file = APP_PATH . 'app/Async/' . $managerName . '.php';
if (file_exists($file)) {
throw new Exception('File exists.');
}
Kiri::writeFile($file, $html);
return [$managerName . '.php'];
}
}