diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..df55cd7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = false + +[*.{vue,js,scss}] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9af3157 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +* text=auto + +/tests export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.scrutinizer.yml export-ignore +.travis.yml export-ignore +phpunit.php export-ignore +phpunit.xml.dist export-ignore +phpunit.xml export-ignore +.php_cs export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..497c4e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.idea +*.DS_Store +/vendor +/coverage +sftp-config.json +composer.lock +.subsplit +.php_cs.cache diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..5627ca6 --- /dev/null +++ b/.php_cs @@ -0,0 +1,27 @@ + + +This source file is subject to the MIT license that is bundled. +EOF; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules(array( + '@Symfony' => true, + 'header_comment' => array('header' => $header), + 'array_syntax' => array('syntax' => 'short'), + 'ordered_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'php_unit_construct' => true, + 'php_unit_strict' => true, + )) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude('vendor') + ->in(__DIR__) + ) +; \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..75303d5 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +

data-dict

+ +

A plug-in that generates a data dictionary.

+ + +## Installing + +```shell +$ composer require tim168/data-dict -vvv +``` + +## Usage + +TODO + +## Contributing + +You can contribute in one of three ways: + +1. File bug reports using the [issue tracker](https://github.com/tim168/data-dict/issues). +2. Answer questions or fix bugs on the [issue tracker](https://github.com/tim168/data-dict/issues). +3. Contribute new features or update the wiki. + +_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._ + +## License + +MIT \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a39e44e --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "tim168\/data-dict", + "description": "A plug-in that generates a data dictionary", + "license": "MIT", + "authors": [ + { + "name": "TIM168", + "email": "784699571@qq.com" + } + ], + "require": { + "ext-mysqli": "*", + "phpunit/phpunit": "^8.5", + "mockery/mockery": "^1.3" + }, + "autoload": { + "psr-4": { + "Tim168\\DataDict\\": "src" + } + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..e47284c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + ./tests/ + + + + + src/ + + + diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/Data/Draw.php b/src/Data/Draw.php new file mode 100644 index 0000000..d8f76a6 --- /dev/null +++ b/src/Data/Draw.php @@ -0,0 +1,62 @@ + $v) { + $html .= ''; + $html .= ''; + $html .= ' + + '; + $html .= ''; + foreach ($v['COLUMN'] as $f) { + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= '
' . $v['TABLE_NAME'] . ' ' . $v['TABLE_COMMENT'] . '
字段名数据类型默认值允许非空自动递增备注
' . $f['COLUMN_NAME'] . '' . $f['COLUMN_TYPE'] . ' ' . $f['COLUMN_DEFAULT'] . ' ' . $f['IS_NULLABLE'] . '' . ($f['EXTRA'] == 'auto_increment' ? '是' : ' ') . ' ' . $f['COLUMN_COMMENT'] . '

'; + } + return $html; + } else { + return false; + } + } + + public function ToHtml($title, $html) + { + $content = ' + + + ' . $title . ' + + + +

' . $title . '

+ ' . $html . ' + '; + + return $content; + } +} \ No newline at end of file diff --git a/src/Data/Fetch.php b/src/Data/Fetch.php new file mode 100644 index 0000000..ea3b8ee --- /dev/null +++ b/src/Data/Fetch.php @@ -0,0 +1,53 @@ + $v) { + $sql = 'SELECT * FROM '; + $sql .= 'INFORMATION_SCHEMA.TABLES '; + $sql .= 'WHERE '; + $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$dbName}'"; + $tableResult = mysqli_query($mysqlConn, $sql); + while ($t = mysqli_fetch_array($tableResult)) { + $tables[$k]['TABLE_COMMENT'] = $t['TABLE_COMMENT']; + } + $sql = 'SELECT * FROM '; + $sql .= 'INFORMATION_SCHEMA.COLUMNS '; + $sql .= 'WHERE '; + $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$dbName}'"; + $fields = array(); + $fieldsResult = mysqli_query($mysqlConn, $sql); + while ($t = mysqli_fetch_array($fieldsResult)) { + $fields[] = $t; + } + $tables[$k]['COLUMN'] = $fields; + } + return $tables; + } + return false; + } catch (\Exception $e) { + throw new MysqlErrorException($e->getMessage(), $e->getCode(), $e); + } finally { + if (!empty($mysqlConn)) mysqli_close($mysqlConn); + } + } +} \ No newline at end of file diff --git a/src/DataDict.php b/src/DataDict.php new file mode 100644 index 0000000..874f79b --- /dev/null +++ b/src/DataDict.php @@ -0,0 +1,39 @@ +dbHost = $dbHost; + $this->dbUserName = $dbUserName; + $this->dbPassWord = $dbPassWord; + $this->dbName = $dbName; + $this->dbPort = $dbPort; + } + + public function get() + { + $fetch = new Fetch(); + $tables = $fetch->conn($this->dbHost, $this->dbUserName, $this->dbPassWord, $this->dbName, $this->dbPort); + var_dump($tables); + exit(); + if (!empty($tables)) { + $draw = new Draw(); + $html = $draw->dataToHtml($tables); + $content = $draw->ToHtml($this->title, $html); + return $content; + } + } +} \ No newline at end of file diff --git a/src/Exceptions/MysqlErrorException.php b/src/Exceptions/MysqlErrorException.php new file mode 100644 index 0000000..71cf67c --- /dev/null +++ b/src/Exceptions/MysqlErrorException.php @@ -0,0 +1,8 @@ +