This commit is contained in:
2020-09-08 15:59:15 +08:00
parent 4aee04f14b
commit 9a086a50d0
9 changed files with 123 additions and 31 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace Gii;
use Exception;
use Snowflake\Abstracts\Input;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
/**
* Class Command
* @package HttpServer
*/
class Command extends \Console\Command
{
public $command = 'sw:gii';
public $description = 'server start|stop|reload|restart';
/**
* @param Input $dtl
* @return array
* @throws Exception
*/
public function onHandler(Input $dtl)
{
/** @var Gii $gii */
$gii = Snowflake::app()->get('gii');
$connections = Snowflake::app()->db->get($dtl->get('databases', 'db'));
return $gii->run($connections, $dtl);
}
}
+24 -17
View File
@@ -6,11 +6,12 @@
* Time: 17:43
*/
namespace Snowflake\Gii;
namespace Gii;
use Database\Connection;
use Database\Db;
use Exception;
use Snowflake\Abstracts\Input;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
@@ -27,6 +28,9 @@ class Gii
/** @var Connection */
private $db;
/** @var Input */
private $input;
public $modelPath = APP_PATH . '/models/';
public $modelNamespace = 'models\\';
@@ -45,34 +49,35 @@ class Gii
/**
* @param Connection|null $db
*
* @param $input
* @return array
* @throws ComponentException
* @throws ConfigException
* @throws Exception
*/
public static function run(Connection $db = NULL)
public function run($db, $input)
{
$gii = new Gii();
if (!empty($db)) $gii->db = $db;
if (!$gii->db) {
$db = Input()->get('databases', 'db');
$gii->db = Snowflake::app()->db->get($db);
$this->input = $input;
if (!empty($db)) $this->db = $db;
if (!$this->db) {
$db = $this->input->get('databases', 'db');
$this->db = Snowflake::app()->db->get($db);
}
$redis = Snowflake::app()->getRedis();
if (!empty(Input()->get('t'))) {
$gii->tableName = Input()->get('t');
$redis->del('column:' . $gii->tableName);
if (!empty($input->get('t'))) {
$this->tableName = $input->get('t');
$redis->del('column:' . $this->tableName);
}
if (Input()->get('m', NULL)) {
if ($input->get('m', NULL)) {
$model = 1;
}
if (Input()->get('c', NULL)) {
if ($input->get('c', NULL)) {
$c = 1;
}
if (Input()->get('isUpdate') == 1) {
$gii->isUpdate = TRUE;
if ($input->get('isUpdate') == 1) {
$this->isUpdate = TRUE;
}
return $gii->getTable($c, $model);
return $this->getTable($c, $model);
}
/**
@@ -113,7 +118,8 @@ class Gii
$controller->setConnection($this->db);
$controller->setModelPath($this->modelPath);
$controller->setModelNamespace($this->modelNamespace);
$controller->setModule(Input()->get('module', null));
$controller->setInput($this->input);
$controller->setModule($this->input->get('module', null));
$controller->setControllerPath($this->controllerPath);
$controller->setControllerNamespace($this->controllerNamespace);
return $controller->generate();
@@ -129,9 +135,10 @@ class Gii
$controller = new GiiController($data['classFileName'], $data['fields']);
$controller->setConnection($this->db);
$controller->setModelPath($this->modelPath);
$controller->setInput($this->input);
$controller->setModelNamespace($this->modelNamespace);
$controller->setControllerPath($this->controllerPath);
$controller->setModule(Input()->get('module', null));
$controller->setModule($this->input->get('module', null));
$controller->setControllerNamespace($this->controllerNamespace);
return $controller->generate();
}
+16 -2
View File
@@ -1,20 +1,25 @@
<?php
namespace Snowflake\Gii;
namespace Gii;
use Database\Connection;
use Snowflake\Abstracts\Input;
/**
* Class GiiBase
* @package Snowflake\Gii
* @package Gii
*/
abstract class GiiBase
{
public $fileList = [];
/** @var Input */
protected $input;
public $modelPath = APP_PATH . '/models/';
public $modelNamespace = 'models\\';
@@ -80,6 +85,15 @@ abstract class GiiBase
}
/**
* @param Input $input
*/
public function setInput(Input $input)
{
$this->input = $input;
}
/**
* @param \ReflectionClass $object
* @param $className
@@ -1,13 +1,13 @@
<?php
namespace Snowflake\Gii;
namespace Gii;
use Snowflake\Snowflake;
/**
* Class GiiController
* @package Snowflake\Gii
* @package Gii
*/
class GiiController extends GiiBase
{
@@ -100,7 +100,7 @@ class {$controllerName}Controller extends ActiveController
$html .= $this->getFuncLineContent($class, $classFileName, $val->name) . "\n";
}
}
if (!Input()->get('--controller-empty', false)) {
if (!$this->input->get('--controller-empty', false)) {
$default = ['actionLoadParam', 'actionAdd', 'actionUpdate', 'actionDetail', 'actionDelete', 'actionBatchDelete', 'actionList'];
foreach ($default as $key => $val) {
+2 -3
View File
@@ -1,15 +1,14 @@
<?php
namespace Snowflake\Gii;
namespace Gii;
use Database\Db;
use Snowflake\Snowflake;
use Swoole\Coroutine\System;
/**
* Class GiiModel
* @package Snowflake\Gii
* @package Gii
*/
class GiiModel extends GiiBase
{
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Gii;
use Console\Console;
use Exception;
use Snowflake\Abstracts\Providers;
use Snowflake\Application;
/**
* Class DatabasesProviders
* @package Database
*/
class GiiProviders extends Providers
{
/**
* @param Application $application
* @throws Exception
*/
public function onImport(Application $application)
{
$application->set('gii', ['class' => Gii::class]);
/** @var Console $console */
$console = $application->get('console');
$console->register(Command::class);
}
}
+1 -2
View File
@@ -6,7 +6,6 @@ namespace HttpServer;
use Exception;
use Snowflake\Abstracts\Input;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
@@ -17,7 +16,7 @@ use Snowflake\Snowflake;
class Command extends \Console\Command
{
public $command = 'server';
public $command = 'sw:server';
public $description = 'server start|stop|reload|restart';
+3 -3
View File
@@ -383,15 +383,15 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
$model = $this->getUserModel();
if (empty($model)) {
return '授权信息已过期!';
throw new AuthException('授权信息已过期!');
// throw new AuthException('授权信息已过期!');
}
if (!isset($model['user'])) {
return '授权信息错误!';
throw new AuthException('授权信息错误!');
// throw new AuthException('授权信息错误!');
}
if (!$this->check($this->data, $model['user'])) {
return '授权信息不合法!';
throw new AuthException('授权信息不合法!');
// throw new AuthException('授权信息不合法!');
}
$this->expireRefresh();
+2 -1
View File
@@ -33,7 +33,8 @@
"HttpServer\\": "HttpServer/",
"validator\\": "Validator/",
"Console\\": "./Console/",
"Database\\": "./Database/"
"Database\\": "./Database/",
"Gii\\": "./Gii/"
},
"files": [
"error.php",