diff --git a/GiiBase.php b/GiiBase.php index e0063dd..a4bdf70 100644 --- a/GiiBase.php +++ b/GiiBase.php @@ -64,6 +64,16 @@ abstract class GiiBase $this->modelNamespace = $modelNamespace; } + + /** + * @param string $content + * @return string + */ + protected function clearBlank(string $content): string + { + return preg_replace('/\s/ixm', '', $content); + } + /** * @param string $controllerPath */ diff --git a/GiiController.php b/GiiController.php index da51729..bb1bf05 100644 --- a/GiiController.php +++ b/GiiController.php @@ -129,17 +129,15 @@ use {$model_namespace}\\{$managerName}; file_put_contents($file, 'db->tablePrefix, '', $this->tableName); $tableName = str_replace('_', '-', $tableName); - $addRouter = 'Router::group([\'prefix\' => \'' . $tableName . '\',\'namespace\' => \''.$namespace.'\'], function () { + $addRouter = 'Router::group([\'prefix\' => \'' . $tableName . '\',\'namespace\' => \'' . $namespace . '\'], function () { Router::post(\'add\', \'' . $controllerName . 'Controller@actionAdd\'); Router::get(\'list\', \'' . $controllerName . 'Controller@actionList\'); Router::post(\'update\', \'' . $controllerName . 'Controller@actionUpdate\'); @@ -150,7 +148,7 @@ use {$model_namespace}\\{$managerName}; Router::get(\'detail\', \'' . $controllerName . 'Controller@actionDetail\'); }); '; - if (!str_contains(preg_replace('/\s/ixm', '', file_get_contents($file)), preg_replace('/\s/ixm', '', $addRouter))) { + if (!str_contains($this->clearBlank(file_get_contents($file)), $this->clearBlank($addRouter))) { file_put_contents($file, $addRouter, FILE_APPEND); }