feat: 本次提交更新内容如下
php有问题,覆盖下
This commit is contained in:
@@ -15,10 +15,11 @@ use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\App;
|
||||
use think\facade\Build as AppBuild;
|
||||
|
||||
class Build extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -35,7 +36,7 @@ class Build extends Command
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
if ($input->hasOption('module')) {
|
||||
\think\Build::module($input->getOption('module'));
|
||||
AppBuild::module($input->getOption('module'));
|
||||
$output->writeln("Successed");
|
||||
return;
|
||||
}
|
||||
@@ -43,13 +44,15 @@ class Build extends Command
|
||||
if ($input->hasOption('config')) {
|
||||
$build = include $input->getOption('config');
|
||||
} else {
|
||||
$build = include APP_PATH . 'build.php';
|
||||
$build = include App::getAppPath() . 'build.php';
|
||||
}
|
||||
|
||||
if (empty($build)) {
|
||||
$output->writeln("Build Config Is Empty");
|
||||
return;
|
||||
}
|
||||
\think\Build::run($build);
|
||||
|
||||
AppBuild::run($build);
|
||||
$output->writeln("Successed");
|
||||
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command;
|
||||
|
||||
use think\Cache;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\App;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Clear extends Command
|
||||
{
|
||||
@@ -24,39 +24,46 @@ class Clear extends Command
|
||||
// 指令配置
|
||||
$this
|
||||
->setName('clear')
|
||||
->addArgument('type', Argument::OPTIONAL, 'type to clear', null)
|
||||
->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear', null)
|
||||
->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file')
|
||||
->addOption('route', 'u', Option::VALUE_NONE, 'clear route cache')
|
||||
->addOption('log', 'l', Option::VALUE_NONE, 'clear log file')
|
||||
->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir')
|
||||
->setDescription('Clear runtime file');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$path = $input->getOption('path') ?: RUNTIME_PATH;
|
||||
|
||||
$type = $input->getArgument('type');
|
||||
|
||||
if ($type == 'route') {
|
||||
Cache::clear('route_check');
|
||||
if ($input->getOption('route')) {
|
||||
Cache::clear('route_cache');
|
||||
} else {
|
||||
if (is_dir($path)) {
|
||||
$this->clearPath($path);
|
||||
if ($input->getOption('cache')) {
|
||||
$path = App::getRuntimePath() . 'cache';
|
||||
} elseif ($input->getOption('log')) {
|
||||
$path = App::getRuntimePath() . 'log';
|
||||
} else {
|
||||
$path = $input->getOption('path') ?: App::getRuntimePath();
|
||||
}
|
||||
|
||||
$rmdir = $input->getOption('dir') ? true : false;
|
||||
$this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir);
|
||||
}
|
||||
|
||||
$output->writeln("<info>Clear Successed</info>");
|
||||
}
|
||||
|
||||
protected function clearPath($path)
|
||||
protected function clear($path, $rmdir)
|
||||
{
|
||||
$path = realpath($path) . DS;
|
||||
$files = scandir($path);
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
if ('.' != $file && '..' != $file && is_dir($path . $file)) {
|
||||
$this->clearPath($path . $file);
|
||||
} elseif ('.gitignore' != $file && is_file($path . $file)) {
|
||||
unlink($path . $file);
|
||||
$files = is_dir($path) ? scandir($path) : [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ('.' != $file && '..' != $file && is_dir($path . $file)) {
|
||||
array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*'));
|
||||
if ($rmdir) {
|
||||
rmdir($path . $file);
|
||||
}
|
||||
} elseif ('.gitignore' != $file && is_file($path . $file)) {
|
||||
unlink($path . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ use think\console\Output;
|
||||
|
||||
class Help extends Command
|
||||
{
|
||||
|
||||
private $command;
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,14 +13,13 @@ namespace think\console\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Argument as InputArgument;
|
||||
use think\console\input\Option as InputOption;
|
||||
use think\console\input\Definition as InputDefinition;
|
||||
use think\console\input\Option as InputOption;
|
||||
use think\console\Output;
|
||||
|
||||
class Lists extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -68,7 +67,7 @@ EOF
|
||||
{
|
||||
return new InputDefinition([
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
|
||||
namespace think\console\command;
|
||||
|
||||
use think\App;
|
||||
use think\Config;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
use think\facade\App;
|
||||
use think\facade\Config;
|
||||
use think\facade\Env;
|
||||
|
||||
abstract class Make extends Command
|
||||
{
|
||||
|
||||
protected $type;
|
||||
|
||||
abstract protected function getStub();
|
||||
@@ -45,7 +45,7 @@ abstract class Make extends Command
|
||||
}
|
||||
|
||||
if (!is_dir(dirname($pathname))) {
|
||||
mkdir(strtolower(dirname($pathname)), 0755, true);
|
||||
mkdir(dirname($pathname), 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents($pathname, $this->buildClass($classname));
|
||||
@@ -62,26 +62,26 @@ abstract class Make extends Command
|
||||
|
||||
$class = str_replace($namespace . '\\', '', $name);
|
||||
|
||||
return str_replace(['{%className%}', '{%namespace%}', '{%app_namespace%}'], [
|
||||
return str_replace(['{%className%}', '{%actionSuffix%}', '{%namespace%}', '{%app_namespace%}'], [
|
||||
$class,
|
||||
Config::get('action_suffix'),
|
||||
$namespace,
|
||||
App::$namespace,
|
||||
App::getNamespace(),
|
||||
], $stub);
|
||||
|
||||
}
|
||||
|
||||
protected function getPathName($name)
|
||||
{
|
||||
$name = str_replace(App::$namespace . '\\', '', $name);
|
||||
$name = str_replace(App::getNamespace() . '\\', '', $name);
|
||||
|
||||
return APP_PATH . str_replace('\\', '/', $name) . '.php';
|
||||
return Env::get('app_path') . ltrim(str_replace('\\', '/', $name), '/') . '.php';
|
||||
}
|
||||
|
||||
protected function getClassName($name)
|
||||
{
|
||||
$appNamespace = App::$namespace;
|
||||
$appNamespace = App::getNamespace();
|
||||
|
||||
if (strpos($name, $appNamespace . '\\') === 0) {
|
||||
if (strpos($name, $appNamespace . '\\') !== false) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,30 +11,36 @@
|
||||
|
||||
namespace think\console\command\make;
|
||||
|
||||
use think\Config;
|
||||
use think\console\command\Make;
|
||||
use think\console\input\Option;
|
||||
use think\facade\Config;
|
||||
|
||||
class Controller extends Make
|
||||
{
|
||||
|
||||
protected $type = "Controller";
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('make:controller')
|
||||
->addOption('api', null, Option::VALUE_NONE, 'Generate an api controller class.')
|
||||
->addOption('plain', null, Option::VALUE_NONE, 'Generate an empty controller class.')
|
||||
->setDescription('Create a new resource controller class');
|
||||
}
|
||||
|
||||
protected function getStub()
|
||||
{
|
||||
if ($this->input->getOption('plain')) {
|
||||
return __DIR__ . '/stubs/controller.plain.stub';
|
||||
$stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ($this->input->getOption('api')) {
|
||||
return $stubPath . 'controller.api.stub';
|
||||
}
|
||||
|
||||
return __DIR__ . '/stubs/controller.stub';
|
||||
if ($this->input->getOption('plain')) {
|
||||
return $stubPath . 'controller.plain.stub';
|
||||
}
|
||||
|
||||
return $stubPath . 'controller.stub';
|
||||
}
|
||||
|
||||
protected function getClassName($name)
|
||||
|
||||
@@ -26,7 +26,7 @@ class Model extends Make
|
||||
|
||||
protected function getStub()
|
||||
{
|
||||
return __DIR__ . '/stubs/model.stub';
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'model.stub';
|
||||
}
|
||||
|
||||
protected function getNamespace($appNamespace, $module)
|
||||
|
||||
@@ -12,7 +12,7 @@ class {%className%} extends Controller
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
public function index{%actionSuffix%}()
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class {%className%} extends Controller
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
public function create{%actionSuffix%}()
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class {%className%} extends Controller
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
public function save{%actionSuffix%}(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class {%className%} extends Controller
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
public function read{%actionSuffix%}($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class {%className%} extends Controller
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit{%actionSuffix%}($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class {%className%} extends Controller
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update{%actionSuffix%}(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class {%className%} extends Controller
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
public function delete{%actionSuffix%}($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
@@ -10,15 +10,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\App;
|
||||
use think\Config;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Container;
|
||||
|
||||
class Autoload extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:autoload')
|
||||
@@ -37,20 +35,14 @@ class Autoload extends Command
|
||||
return [
|
||||
|
||||
EOF;
|
||||
|
||||
$app = Container::get('app');
|
||||
$namespacesToScan = [
|
||||
App::$namespace . '\\' => realpath(rtrim(APP_PATH)),
|
||||
'think\\' => LIB_PATH . 'think',
|
||||
'behavior\\' => LIB_PATH . 'behavior',
|
||||
'traits\\' => LIB_PATH . 'traits',
|
||||
'' => realpath(rtrim(EXTEND_PATH)),
|
||||
$app->getNamespace() . '\\' => realpath(rtrim($app->getAppPath())),
|
||||
'think\\' => $app->getThinkPath() . 'library/think',
|
||||
'traits\\' => $app->getThinkPath() . 'library/traits',
|
||||
'' => realpath(rtrim($app->getRootPath() . 'extend')),
|
||||
];
|
||||
|
||||
$root_namespace = Config::get('root_namespace');
|
||||
foreach ($root_namespace as $namespace => $dir) {
|
||||
$namespacesToScan[$namespace . '\\'] = realpath($dir);
|
||||
}
|
||||
|
||||
krsort($namespacesToScan);
|
||||
$classMap = [];
|
||||
foreach ($namespacesToScan as $namespace => $dir) {
|
||||
@@ -59,7 +51,7 @@ EOF;
|
||||
continue;
|
||||
}
|
||||
|
||||
$namespaceFilter = $namespace === '' ? null : $namespace;
|
||||
$namespaceFilter = '' === $namespace ? null : $namespace;
|
||||
$classMap = $this->addClassMapCode($dir, $namespaceFilter, $classMap);
|
||||
}
|
||||
|
||||
@@ -68,12 +60,12 @@ EOF;
|
||||
$classmapFile .= ' ' . var_export($class, true) . ' => ' . $code;
|
||||
}
|
||||
$classmapFile .= "];\n";
|
||||
|
||||
if (!is_dir(RUNTIME_PATH)) {
|
||||
@mkdir(RUNTIME_PATH, 0755, true);
|
||||
$runtimePath = $app->getRuntimePath();
|
||||
if (!is_dir($runtimePath)) {
|
||||
@mkdir($runtimePath, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents(RUNTIME_PATH . 'classmap' . EXT, $classmapFile);
|
||||
file_put_contents($runtimePath . 'classmap.php', $classmapFile);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
@@ -100,40 +92,33 @@ EOF;
|
||||
|
||||
protected function getPathCode($path)
|
||||
{
|
||||
|
||||
$baseDir = '';
|
||||
$libPath = $this->normalizePath(realpath(LIB_PATH));
|
||||
$appPath = $this->normalizePath(realpath(APP_PATH));
|
||||
$extendPath = $this->normalizePath(realpath(EXTEND_PATH));
|
||||
$rootPath = $this->normalizePath(realpath(ROOT_PATH));
|
||||
$app = Container::get('app');
|
||||
$appPath = $this->normalizePath(realpath($app->getAppPath()));
|
||||
$libPath = $this->normalizePath(realpath($app->getThinkPath() . 'library'));
|
||||
$extendPath = $this->normalizePath(realpath($app->getRootPath() . 'extend'));
|
||||
$path = $this->normalizePath($path);
|
||||
|
||||
if ($libPath !== null && strpos($path, $libPath . '/') === 0) {
|
||||
$path = substr($path, strlen(LIB_PATH));
|
||||
$baseDir = 'LIB_PATH';
|
||||
} elseif ($appPath !== null && strpos($path, $appPath . '/') === 0) {
|
||||
if (strpos($path, $libPath . '/') === 0) {
|
||||
$path = substr($path, strlen($app->getThinkPath() . 'library'));
|
||||
$baseDir = "'" . $libPath . "/'";
|
||||
} elseif (strpos($path, $appPath . '/') === 0) {
|
||||
$path = substr($path, strlen($appPath) + 1);
|
||||
$baseDir = 'APP_PATH';
|
||||
} elseif ($extendPath !== null && strpos($path, $extendPath . '/') === 0) {
|
||||
$baseDir = "'" . $appPath . "/'";
|
||||
} elseif (strpos($path, $extendPath . '/') === 0) {
|
||||
$path = substr($path, strlen($extendPath) + 1);
|
||||
$baseDir = 'EXTEND_PATH';
|
||||
} elseif ($rootPath !== null && strpos($path, $rootPath . '/') === 0) {
|
||||
$path = substr($path, strlen($rootPath) + 1);
|
||||
$baseDir = 'ROOT_PATH';
|
||||
$baseDir = "'" . $extendPath . "/'";
|
||||
}
|
||||
|
||||
if ($path !== false) {
|
||||
if (false !== $path) {
|
||||
$baseDir .= " . ";
|
||||
}
|
||||
|
||||
return $baseDir . (($path !== false) ? var_export($path, true) : "");
|
||||
return $baseDir . ((false !== $path) ? var_export($path, true) : "");
|
||||
}
|
||||
|
||||
protected function normalizePath($path)
|
||||
{
|
||||
if ($path === false) {
|
||||
return;
|
||||
}
|
||||
$parts = [];
|
||||
$path = strtr($path, '\\', '/');
|
||||
$prefix = '';
|
||||
@@ -252,7 +237,7 @@ EOF;
|
||||
// strip leading non-php code if needed
|
||||
if (substr($contents, 0, 2) !== '<?') {
|
||||
$contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
|
||||
if ($replacements === 0) {
|
||||
if (0 === $replacements) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -279,9 +264,9 @@ EOF;
|
||||
$namespace = str_replace([' ', "\t", "\r", "\n"], '', $matches['nsname'][$i]) . '\\';
|
||||
} else {
|
||||
$name = $matches['name'][$i];
|
||||
if ($name[0] === ':') {
|
||||
if (':' === $name[0]) {
|
||||
$name = 'xhp' . substr(str_replace(['-', ':'], ['_', '__'], $name), 1);
|
||||
} elseif ($matches['type'][$i] === 'enum') {
|
||||
} elseif ('enum' === $matches['type'][$i]) {
|
||||
$name = rtrim($name, ':');
|
||||
}
|
||||
$classes[] = ltrim($namespace . $name, '\\');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// | Copyright (c) 2006-2017 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -10,17 +10,15 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\Config as ThinkConfig;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
use think\Container;
|
||||
use think\facade\App;
|
||||
|
||||
class Config extends Command
|
||||
{
|
||||
/** @var Output */
|
||||
protected $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:config')
|
||||
@@ -31,63 +29,79 @@ class Config extends Command
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
if ($input->getArgument('module')) {
|
||||
$module = $input->getArgument('module') . DS;
|
||||
$module = $input->getArgument('module') . DIRECTORY_SEPARATOR;
|
||||
} else {
|
||||
$module = '';
|
||||
}
|
||||
|
||||
$content = '<?php ' . PHP_EOL . $this->buildCacheContent($module);
|
||||
|
||||
if (!is_dir(RUNTIME_PATH . $module)) {
|
||||
@mkdir(RUNTIME_PATH . $module, 0755, true);
|
||||
$content = '<?php ' . PHP_EOL . $this->buildCacheContent($module);
|
||||
$runtimePath = App::getRuntimePath();
|
||||
if (!is_dir($runtimePath . $module)) {
|
||||
@mkdir($runtimePath . $module, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents(RUNTIME_PATH . $module . 'init' . EXT, $content);
|
||||
file_put_contents($runtimePath . $module . 'init.php', $content);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function buildCacheContent($module)
|
||||
{
|
||||
$content = '';
|
||||
$path = realpath(APP_PATH . $module) . DS;
|
||||
|
||||
$content = '// This cache file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL;
|
||||
$path = realpath(App::getAppPath() . $module) . DIRECTORY_SEPARATOR;
|
||||
if ($module) {
|
||||
// 加载模块配置
|
||||
$config = ThinkConfig::load(CONF_PATH . $module . 'config' . CONF_EXT);
|
||||
$configPath = is_dir($path . 'config') ? $path . 'config' : App::getConfigPath() . $module;
|
||||
} else {
|
||||
$configPath = App::getConfigPath();
|
||||
}
|
||||
$ext = App::getConfigExt();
|
||||
$config = Container::get('config');
|
||||
|
||||
// 读取数据库配置文件
|
||||
$filename = CONF_PATH . $module . 'database' . CONF_EXT;
|
||||
ThinkConfig::load($filename, 'database');
|
||||
$files = is_dir($configPath) ? scandir($configPath) : [];
|
||||
|
||||
// 加载应用状态配置
|
||||
if ($config['app_status']) {
|
||||
$config = ThinkConfig::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
|
||||
}
|
||||
// 读取扩展配置文件
|
||||
if (is_dir(CONF_PATH . $module . 'extra')) {
|
||||
$dir = CONF_PATH . $module . 'extra';
|
||||
$files = scandir($dir);
|
||||
foreach ($files as $file) {
|
||||
if (strpos($file, CONF_EXT)) {
|
||||
$filename = $dir . DS . $file;
|
||||
ThinkConfig::load($filename, pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if ('.' . pathinfo($file, PATHINFO_EXTENSION) === $ext) {
|
||||
$filename = $configPath . DIRECTORY_SEPARATOR . $file;
|
||||
$config->load($filename, pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
|
||||
// 加载行为扩展文件
|
||||
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
|
||||
$content .= '\think\Hook::import(' . (var_export(include CONF_PATH . $module . 'tags' . EXT, true)) . ');' . PHP_EOL;
|
||||
if (is_file($path . 'tags.php')) {
|
||||
$tags = include $path . 'tags.php';
|
||||
if (is_array($tags)) {
|
||||
$content .= PHP_EOL . '\think\facade\Hook::import(' . (var_export($tags, true)) . ');' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载公共文件
|
||||
if (is_file($path . 'common' . EXT)) {
|
||||
$content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
|
||||
if (is_file($path . 'common.php')) {
|
||||
$common = substr(php_strip_whitespace($path . 'common.php'), 6);
|
||||
if ($common) {
|
||||
$content .= PHP_EOL . $common . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$content .= '\think\Config::set(' . var_export(ThinkConfig::get(), true) . ');';
|
||||
if ('' == $module) {
|
||||
$content .= PHP_EOL . substr(php_strip_whitespace(App::getThinkPath() . 'helper.php'), 6) . PHP_EOL;
|
||||
|
||||
if (is_file($path . 'middleware.php')) {
|
||||
$middleware = include $path . 'middleware.php';
|
||||
if (is_array($middleware)) {
|
||||
$content .= PHP_EOL . '\think\Container::get("middleware")->import(' . var_export($middleware, true) . ');' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_file($path . 'provider.php')) {
|
||||
$provider = include $path . 'provider.php';
|
||||
if (is_array($provider)) {
|
||||
$content .= PHP_EOL . '\think\Container::getInstance()->bindTo(' . var_export($provider, true) . ');' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$content .= PHP_EOL . '\think\facade\Config::set(' . var_export($config->get(), true) . ');' . PHP_EOL;
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,17 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Container;
|
||||
|
||||
class Route extends Command
|
||||
{
|
||||
/** @var Output */
|
||||
protected $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:route')
|
||||
@@ -27,49 +25,42 @@ class Route extends Command
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
|
||||
if (!is_dir(RUNTIME_PATH)) {
|
||||
@mkdir(RUNTIME_PATH, 0755, true);
|
||||
$filename = Container::get('app')->getRuntimePath() . 'route.php';
|
||||
if (is_file($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
file_put_contents(RUNTIME_PATH . 'route.php', $this->buildRouteCache());
|
||||
file_put_contents($filename, $this->buildRouteCache());
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function buildRouteCache()
|
||||
{
|
||||
$files = \think\Config::get('route_config_file');
|
||||
Container::get('route')->setName([]);
|
||||
Container::get('route')->setTestMode(true);
|
||||
// 路由检测
|
||||
$path = Container::get('app')->getRoutePath();
|
||||
|
||||
$files = is_dir($path) ? scandir($path) : [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file(CONF_PATH . $file . CONF_EXT)) {
|
||||
$config = include CONF_PATH . $file . CONF_EXT;
|
||||
if (is_array($config)) {
|
||||
\think\Route::import($config);
|
||||
if (strpos($file, '.php')) {
|
||||
$filename = $path . DIRECTORY_SEPARATOR . $file;
|
||||
// 导入路由配置
|
||||
$rules = include $filename;
|
||||
if (is_array($rules)) {
|
||||
Container::get('route')->import($rules);
|
||||
}
|
||||
}
|
||||
}
|
||||
$rules = \think\Route::rules(true);
|
||||
array_walk_recursive($rules, [$this, 'buildClosure']);
|
||||
|
||||
if (Container::get('config')->get('route_annotation')) {
|
||||
$suffix = Container::get('config')->get('controller_suffix') || Container::get('config')->get('class_suffix');
|
||||
include Container::get('build')->buildRoute($suffix);
|
||||
}
|
||||
|
||||
$content = '<?php ' . PHP_EOL . 'return ';
|
||||
$content .= var_export($rules, true) . ';';
|
||||
$content = str_replace(['\'[__start__', '__end__]\''], '', stripcslashes($content));
|
||||
$content .= var_export(Container::get('route')->getName(), true) . ';';
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function buildClosure(&$value)
|
||||
{
|
||||
if ($value instanceof \Closure) {
|
||||
$reflection = new \ReflectionFunction($value);
|
||||
$startLine = $reflection->getStartLine();
|
||||
$endLine = $reflection->getEndLine();
|
||||
$file = $reflection->getFileName();
|
||||
$item = file($file);
|
||||
$content = '';
|
||||
for ($i = $startLine - 1; $i <= $endLine - 1; $i++) {
|
||||
$content .= $item[$i];
|
||||
}
|
||||
$start = strpos($content, 'function');
|
||||
$end = strrpos($content, '}');
|
||||
$value = '[__start__' . substr($content, $start, $end - $start + 1) . '__end__]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,22 +10,18 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\App;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\App;
|
||||
|
||||
class Schema extends Command
|
||||
{
|
||||
/** @var Output */
|
||||
protected $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:schema')
|
||||
->addOption('config', null, Option::VALUE_REQUIRED, 'db config .')
|
||||
->addOption('db', null, Option::VALUE_REQUIRED, 'db name .')
|
||||
->addOption('table', null, Option::VALUE_REQUIRED, 'table name .')
|
||||
->addOption('module', null, Option::VALUE_REQUIRED, 'module name .')
|
||||
@@ -34,56 +30,58 @@ class Schema extends Command
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
if (!is_dir(RUNTIME_PATH . 'schema')) {
|
||||
@mkdir(RUNTIME_PATH . 'schema', 0755, true);
|
||||
}
|
||||
$config = [];
|
||||
if ($input->hasOption('config')) {
|
||||
$config = $input->getOption('config');
|
||||
if (!is_dir(App::getRuntimePath() . 'schema')) {
|
||||
@mkdir(App::getRuntimePath() . 'schema', 0755, true);
|
||||
}
|
||||
|
||||
if ($input->hasOption('module')) {
|
||||
$module = $input->getOption('module');
|
||||
// 读取模型
|
||||
$path = APP_PATH . $module . DS . 'model';
|
||||
$list = is_dir($path) ? scandir($path) : [];
|
||||
$app = App::$namespace;
|
||||
$path = App::getAppPath() . $module . DIRECTORY_SEPARATOR . 'model';
|
||||
$list = is_dir($path) ? scandir($path) : [];
|
||||
$namespace = App::getNamespace();
|
||||
|
||||
foreach ($list as $file) {
|
||||
if (0 === strpos($file, '.')) {
|
||||
continue;
|
||||
}
|
||||
$class = '\\' . $app . '\\' . $module . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
|
||||
$class = '\\' . $namespace . '\\' . $module . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
|
||||
$this->buildModelSchema($class);
|
||||
}
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
return;
|
||||
} elseif ($input->hasOption('table')) {
|
||||
$table = $input->getOption('table');
|
||||
if (!strpos($table, '.')) {
|
||||
$dbName = Db::connect($config)->getConfig('database');
|
||||
if (false === strpos($table, '.')) {
|
||||
$dbName = Db::getConfig('database');
|
||||
}
|
||||
|
||||
$tables[] = $table;
|
||||
} elseif ($input->hasOption('db')) {
|
||||
$dbName = $input->getOption('db');
|
||||
$tables = Db::connect($config)->getTables($dbName);
|
||||
} elseif (!\think\Config::get('app_multi_module')) {
|
||||
$app = App::$namespace;
|
||||
$path = APP_PATH . 'model';
|
||||
$list = is_dir($path) ? scandir($path) : [];
|
||||
$tables = Db::getConnection()->getTables($dbName);
|
||||
} elseif (!\think\facade\Config::get('app_multi_module')) {
|
||||
$namespace = App::getNamespace();
|
||||
$path = App::getAppPath() . 'model';
|
||||
$list = is_dir($path) ? scandir($path) : [];
|
||||
|
||||
foreach ($list as $file) {
|
||||
if (0 === strpos($file, '.')) {
|
||||
continue;
|
||||
}
|
||||
$class = '\\' . $app . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
|
||||
$class = '\\' . $namespace . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
|
||||
$this->buildModelSchema($class);
|
||||
}
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
return;
|
||||
} else {
|
||||
$tables = Db::connect($config)->getTables();
|
||||
$tables = Db::getConnection()->getTables();
|
||||
}
|
||||
|
||||
$db = isset($dbName) ? $dbName . '.' : '';
|
||||
$this->buildDataBaseSchema($tables, $db, $config);
|
||||
$this->buildDataBaseSchema($tables, $db);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
@@ -97,22 +95,24 @@ class Schema extends Command
|
||||
$content = '<?php ' . PHP_EOL . 'return ';
|
||||
$info = $class::getConnection()->getFields($table);
|
||||
$content .= var_export($info, true) . ';';
|
||||
file_put_contents(RUNTIME_PATH . 'schema' . DS . $dbName . '.' . $table . EXT, $content);
|
||||
|
||||
file_put_contents(App::getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR . $dbName . '.' . $table . '.php', $content);
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildDataBaseSchema($tables, $db, $config)
|
||||
protected function buildDataBaseSchema($tables, $db)
|
||||
{
|
||||
if ('' == $db) {
|
||||
$dbName = Db::connect($config)->getConfig('database') . '.';
|
||||
$dbName = Db::getConfig('database') . '.';
|
||||
} else {
|
||||
$dbName = $db;
|
||||
}
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$content = '<?php ' . PHP_EOL . 'return ';
|
||||
$info = Db::connect($config)->getFields($db . $table);
|
||||
$info = Db::getConnection()->getFields($db . $table);
|
||||
$content .= var_export($info, true) . ';';
|
||||
file_put_contents(RUNTIME_PATH . 'schema' . DS . $dbName . $table . EXT, $content);
|
||||
file_put_contents(App::getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR . $dbName . $table . '.php', $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user