fix: 上传TP框架
This commit is contained in:
294
thinkphp/library/think/console/command/optimize/Autoload.php
Normal file
294
thinkphp/library/think/console/command/optimize/Autoload.php
Normal file
@ -0,0 +1,294 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\App;
|
||||
use think\Config;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class Autoload extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:autoload')
|
||||
->setDescription('Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
|
||||
$classmapFile = <<<EOF
|
||||
<?php
|
||||
/**
|
||||
* 类库映射
|
||||
*/
|
||||
|
||||
return [
|
||||
|
||||
EOF;
|
||||
|
||||
$namespacesToScan = [
|
||||
App::$namespace . '\\' => realpath(rtrim(APP_PATH)),
|
||||
'think\\' => LIB_PATH . 'think',
|
||||
'behavior\\' => LIB_PATH . 'behavior',
|
||||
'traits\\' => LIB_PATH . 'traits',
|
||||
'' => realpath(rtrim(EXTEND_PATH)),
|
||||
];
|
||||
|
||||
$root_namespace = Config::get('root_namespace');
|
||||
foreach ($root_namespace as $namespace => $dir) {
|
||||
$namespacesToScan[$namespace . '\\'] = realpath($dir);
|
||||
}
|
||||
|
||||
krsort($namespacesToScan);
|
||||
$classMap = [];
|
||||
foreach ($namespacesToScan as $namespace => $dir) {
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$namespaceFilter = $namespace === '' ? null : $namespace;
|
||||
$classMap = $this->addClassMapCode($dir, $namespaceFilter, $classMap);
|
||||
}
|
||||
|
||||
ksort($classMap);
|
||||
foreach ($classMap as $class => $code) {
|
||||
$classmapFile .= ' ' . var_export($class, true) . ' => ' . $code;
|
||||
}
|
||||
$classmapFile .= "];\n";
|
||||
|
||||
if (!is_dir(RUNTIME_PATH)) {
|
||||
@mkdir(RUNTIME_PATH, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents(RUNTIME_PATH . 'classmap' . EXT, $classmapFile);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function addClassMapCode($dir, $namespace, $classMap)
|
||||
{
|
||||
foreach ($this->createMap($dir, $namespace) as $class => $path) {
|
||||
|
||||
$pathCode = $this->getPathCode($path) . ",\n";
|
||||
|
||||
if (!isset($classMap[$class])) {
|
||||
$classMap[$class] = $pathCode;
|
||||
} elseif ($classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class] . ' ' . $path, '\\', '/'))) {
|
||||
$this->output->writeln(
|
||||
'<warning>Warning: Ambiguous class resolution, "' . $class . '"' .
|
||||
' was found in both "' . str_replace(["',\n"], [
|
||||
'',
|
||||
], $classMap[$class]) . '" and "' . $path . '", the first will be used.</warning>'
|
||||
);
|
||||
}
|
||||
}
|
||||
return $classMap;
|
||||
}
|
||||
|
||||
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));
|
||||
$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) {
|
||||
$path = substr($path, strlen($appPath) + 1);
|
||||
$baseDir = 'APP_PATH';
|
||||
} elseif ($extendPath !== null && 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';
|
||||
}
|
||||
|
||||
if ($path !== false) {
|
||||
$baseDir .= " . ";
|
||||
}
|
||||
|
||||
return $baseDir . (($path !== false) ? var_export($path, true) : "");
|
||||
}
|
||||
|
||||
protected function normalizePath($path)
|
||||
{
|
||||
if ($path === false) {
|
||||
return;
|
||||
}
|
||||
$parts = [];
|
||||
$path = strtr($path, '\\', '/');
|
||||
$prefix = '';
|
||||
$absolute = false;
|
||||
|
||||
if (preg_match('{^([0-9a-z]+:(?://(?:[a-z]:)?)?)}i', $path, $match)) {
|
||||
$prefix = $match[1];
|
||||
$path = substr($path, strlen($prefix));
|
||||
}
|
||||
|
||||
if (substr($path, 0, 1) === '/') {
|
||||
$absolute = true;
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
|
||||
$up = false;
|
||||
foreach (explode('/', $path) as $chunk) {
|
||||
if ('..' === $chunk && ($absolute || $up)) {
|
||||
array_pop($parts);
|
||||
$up = !(empty($parts) || '..' === end($parts));
|
||||
} elseif ('.' !== $chunk && '' !== $chunk) {
|
||||
$parts[] = $chunk;
|
||||
$up = '..' !== $chunk;
|
||||
}
|
||||
}
|
||||
|
||||
return $prefix . ($absolute ? '/' : '') . implode('/', $parts);
|
||||
}
|
||||
|
||||
protected function createMap($path, $namespace = null)
|
||||
{
|
||||
if (is_string($path)) {
|
||||
if (is_file($path)) {
|
||||
$path = [new \SplFileInfo($path)];
|
||||
} elseif (is_dir($path)) {
|
||||
|
||||
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
$path = [];
|
||||
|
||||
/** @var \SplFileInfo $object */
|
||||
foreach ($objects as $object) {
|
||||
if ($object->isFile() && $object->getExtension() == 'php') {
|
||||
$path[] = $object;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException(
|
||||
'Could not scan for classes inside "' . $path .
|
||||
'" which does not appear to be a file nor a folder'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach ($path as $file) {
|
||||
$filePath = $file->getRealPath();
|
||||
|
||||
if (pathinfo($filePath, PATHINFO_EXTENSION) != 'php') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes = $this->findClasses($filePath);
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if (null !== $namespace && 0 !== strpos($class, $namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($map[$class])) {
|
||||
$map[$class] = $filePath;
|
||||
} elseif ($map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
|
||||
$this->output->writeln(
|
||||
'<warning>Warning: Ambiguous class resolution, "' . $class . '"' .
|
||||
' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
protected function findClasses($path)
|
||||
{
|
||||
$extraTypes = '|trait';
|
||||
|
||||
$contents = @php_strip_whitespace($path);
|
||||
if (!$contents) {
|
||||
if (!file_exists($path)) {
|
||||
$message = 'File at "%s" does not exist, check your classmap definitions';
|
||||
} elseif (!is_readable($path)) {
|
||||
$message = 'File at "%s" is not readable, check its permissions';
|
||||
} elseif ('' === trim(file_get_contents($path))) {
|
||||
return [];
|
||||
} else {
|
||||
$message = 'File at "%s" could not be parsed as PHP, it may be binary or corrupted';
|
||||
}
|
||||
$error = error_get_last();
|
||||
if (isset($error['message'])) {
|
||||
$message .= PHP_EOL . 'The following message may be helpful:' . PHP_EOL . $error['message'];
|
||||
}
|
||||
throw new \RuntimeException(sprintf($message, $path));
|
||||
}
|
||||
|
||||
if (!preg_match('{\b(?:class|interface' . $extraTypes . ')\s}i', $contents)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// strip heredocs/nowdocs
|
||||
$contents = preg_replace('{<<<\s*(\'?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\2(?=\r\n|\n|\r|;)}s', 'null', $contents);
|
||||
// strip strings
|
||||
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
|
||||
// strip leading non-php code if needed
|
||||
if (substr($contents, 0, 2) !== '<?') {
|
||||
$contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
|
||||
if ($replacements === 0) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
// strip non-php blocks in the file
|
||||
$contents = preg_replace('{\?>.+<\?}s', '?><?', $contents);
|
||||
// strip trailing non-php code if needed
|
||||
$pos = strrpos($contents, '?>');
|
||||
if (false !== $pos && false === strpos(substr($contents, $pos), '<?')) {
|
||||
$contents = substr($contents, 0, $pos);
|
||||
}
|
||||
|
||||
preg_match_all('{
|
||||
(?:
|
||||
\b(?<![\$:>])(?P<type>class|interface' . $extraTypes . ') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
|
||||
| \b(?<![\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
|
||||
)
|
||||
}ix', $contents, $matches);
|
||||
|
||||
$classes = [];
|
||||
$namespace = '';
|
||||
|
||||
for ($i = 0, $len = count($matches['type']); $i < $len; $i++) {
|
||||
if (!empty($matches['ns'][$i])) {
|
||||
$namespace = str_replace([' ', "\t", "\r", "\n"], '', $matches['nsname'][$i]) . '\\';
|
||||
} else {
|
||||
$name = $matches['name'][$i];
|
||||
if ($name[0] === ':') {
|
||||
$name = 'xhp' . substr(str_replace(['-', ':'], ['_', '__'], $name), 1);
|
||||
} elseif ($matches['type'][$i] === 'enum') {
|
||||
$name = rtrim($name, ':');
|
||||
}
|
||||
$classes[] = ltrim($namespace . $name, '\\');
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
}
|
93
thinkphp/library/think/console/command/optimize/Config.php
Normal file
93
thinkphp/library/think/console/command/optimize/Config.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
class Config extends Command
|
||||
{
|
||||
/** @var Output */
|
||||
protected $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:config')
|
||||
->addArgument('module', Argument::OPTIONAL, 'Build module config cache .')
|
||||
->setDescription('Build config and common file cache.');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
if ($input->hasArgument('module')) {
|
||||
$module = $input->getArgument('module') . DS;
|
||||
} else {
|
||||
$module = '';
|
||||
}
|
||||
|
||||
$content = '<?php ' . PHP_EOL . $this->buildCacheContent($module);
|
||||
|
||||
if (!is_dir(RUNTIME_PATH . $module)) {
|
||||
@mkdir(RUNTIME_PATH . $module, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents(RUNTIME_PATH . $module . 'init' . EXT, $content);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function buildCacheContent($module)
|
||||
{
|
||||
$content = '';
|
||||
$path = realpath(APP_PATH . $module) . DS;
|
||||
|
||||
if ($module) {
|
||||
// 加载模块配置
|
||||
$config = ThinkConfig::load(CONF_PATH . $module . 'config' . CONF_EXT);
|
||||
|
||||
// 读取数据库配置文件
|
||||
$filename = CONF_PATH . $module . 'database' . CONF_EXT;
|
||||
ThinkConfig::load($filename, 'database');
|
||||
|
||||
// 加载应用状态配置
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载行为扩展文件
|
||||
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 . 'common' . EXT)) {
|
||||
$content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
|
||||
}
|
||||
|
||||
$content .= '\think\Config::set(' . var_export(ThinkConfig::get(), true) . ');';
|
||||
return $content;
|
||||
}
|
||||
}
|
70
thinkphp/library/think/console/command/optimize/Route.php
Normal file
70
thinkphp/library/think/console/command/optimize/Route.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class Route extends Command
|
||||
{
|
||||
/** @var Output */
|
||||
protected $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:route')
|
||||
->setDescription('Build route cache.');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
file_put_contents(RUNTIME_PATH . 'route.php', $this->buildRouteCache());
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function buildRouteCache()
|
||||
{
|
||||
$files = \think\Config::get('route_config_file');
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$rules = \think\Route::rules(true);
|
||||
array_walk_recursive($rules, [$this, 'buildClosure']);
|
||||
$content = '<?php ' . PHP_EOL . 'return ';
|
||||
$content .= var_export($rules, true) . ';';
|
||||
$content = str_replace(['\'[__start__', '__end__]\''], '', stripcslashes($content));
|
||||
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__]';
|
||||
}
|
||||
}
|
||||
}
|
116
thinkphp/library/think/console/command/optimize/Schema.php
Normal file
116
thinkphp/library/think/console/command/optimize/Schema.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
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 .')
|
||||
->setDescription('Build database schema cache.');
|
||||
}
|
||||
|
||||
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 ($input->hasOption('module')) {
|
||||
$module = $input->getOption('module');
|
||||
// 读取模型
|
||||
$list = scandir(APP_PATH . $module . DS . 'model');
|
||||
$app = App::$namespace;
|
||||
foreach ($list as $file) {
|
||||
if (0 === strpos($file, '.')) {
|
||||
continue;
|
||||
}
|
||||
$class = '\\' . $app . '\\' . $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');
|
||||
}
|
||||
$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;
|
||||
$list = scandir(APP_PATH . 'model');
|
||||
foreach ($list as $file) {
|
||||
if (0 === strpos($file, '.')) {
|
||||
continue;
|
||||
}
|
||||
$class = '\\' . $app . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
|
||||
$this->buildModelSchema($class);
|
||||
}
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
return;
|
||||
} else {
|
||||
$tables = Db::connect($config)->getTables();
|
||||
}
|
||||
|
||||
$db = isset($dbName) ? $dbName . '.' : '';
|
||||
$this->buildDataBaseSchema($tables, $db, $config);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
|
||||
protected function buildModelSchema($class)
|
||||
{
|
||||
$reflect = new \ReflectionClass($class);
|
||||
if (!$reflect->isAbstract() && $reflect->isSubclassOf('\think\Model')) {
|
||||
$table = $class::getTable();
|
||||
$dbName = $class::getConfig('database');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildDataBaseSchema($tables, $db, $config)
|
||||
{
|
||||
if ('' == $db) {
|
||||
$dbName = Db::connect($config)->getConfig('database') . '.';
|
||||
} else {
|
||||
$dbName = $db;
|
||||
}
|
||||
foreach ($tables as $table) {
|
||||
$content = '<?php ' . PHP_EOL . 'return ';
|
||||
$info = Db::connect($config)->getFields($db . $table);
|
||||
$content .= var_export($info, true) . ';';
|
||||
file_put_contents(RUNTIME_PATH . 'schema' . DS . $dbName . $table . EXT, $content);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user