commit e80f0c95762658c6754385730e450828f83e5bc0 Author: zhangzhitong <997097287@qq.com> Date: Thu Mar 5 16:33:13 2020 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d465120 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/.idea +/.vscode +/vendor +*.log +.env \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36f7b6f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +sudo: false + +language: php + +branches: + only: + - stable + +cache: + directories: + - $HOME/.composer/cache + +before_install: + - composer self-update + +install: + - composer install --no-dev --no-interaction --ignore-platform-reqs + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . + - composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" + - composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . + +script: + - php think unit + +deploy: + provider: releases + api_key: + secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= + file: + - ThinkPHP_Core.zip + - ThinkPHP_Full.zip + skip_cleanup: true + on: + tags: true diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..574a39c --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,32 @@ + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 +版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) +All rights reserved。 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +Apache Licence是著名的非盈利开源组织Apache采用的协议。 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, +允许代码修改,再作为开源或商业软件发布。需要满足 +的条件: +1. 需要给代码的用户一份Apache Licence ; +2. 如果你修改了代码,需要在被修改的文件中说明; +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 +带有原来代码中的协议,商标,专利声明和其他原来作者规 +定需要包含的说明; +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 +件中需要带有本协议内容。你可以在Notice中增加自己的 +许可,但不可以表现为对Apache Licence构成更改。 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8888c56 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +ThinkPHP 6.0 +=============== + +> 运行环境要求PHP7.1+。 + +ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。 + +## 主要新特性 + +* 采用`PHP7`强类型(严格模式) +* 支持更多的`PSR`规范 +* 原生多应用支持 +* 更强大和易用的查询 +* 全新的事件系统 +* 模型事件和数据库事件统一纳入事件系统 +* 模板引擎分离出核心 +* 内部功能中间件化 +* SESSION/Cookie机制改进 +* 对Swoole以及协程支持改进 +* 对IDE更加友好 +* 统一和精简大量用法 + +## 安装 + +~~~ +composer create-project topthink/think tp 6.0.* +~~~ + +如果需要更新框架使用 +~~~ +composer update topthink/framework +~~~ + +## 文档 + +[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content) + +## 参与开发 + +请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。 + +## 版权信息 + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 + +本项目包含的第三方源码和二进制文件之版权信息另行标注。 + +版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn) + +All rights reserved。 + +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +更多细节参阅 [LICENSE.txt](LICENSE.txt) diff --git a/app/.htaccess b/app/.htaccess new file mode 100644 index 0000000..3418e55 --- /dev/null +++ b/app/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file diff --git a/app/AppService.php b/app/AppService.php new file mode 100644 index 0000000..96556e8 --- /dev/null +++ b/app/AppService.php @@ -0,0 +1,22 @@ +app = $app; + $this->request = $this->app->request; + + // 控制器初始化 + $this->initialize(); + } + + // 初始化 + protected function initialize() + {} + + /** + * 验证数据 + * @access protected + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 + * @return array|string|true + */ + protected function validate(array $data, $validate, array $message = [], bool $batch = false) + { + if (is_array($validate)) { + $v = new Validate(); + $v->rule($validate); + } else { + if (strpos($validate, '.')) { + // 支持场景 + [$validate, $scene] = explode('.', $validate); + } + $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); + $v = new $class(); + if (!empty($scene)) { + $v->scene($scene); + } + } + + $v->message($message); + + // 是否批量验证 + if ($batch || $this->batchValidate) { + $v->batch(true); + } + + return $v->failException(true)->check($data); + } + +} diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php new file mode 100644 index 0000000..f4635dd --- /dev/null +++ b/app/common/model/BaseModel.php @@ -0,0 +1,55 @@ +getTable(), function (Table $table) { + $table->setIfNotExists()->setTableComment($this->comment); //设置表名称 + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('id')->setIsAutoIncrement()->setIsPrimaryKey()->setIsUnsigned()->setColumnComment('主键id'); + $table->colDateTime('created_at')->setDefaultValue("CURRENT_TIMESTAMP")->setColumnComment('创建时间'); + $table->colDateTime('updated_at')->setDefaultValue("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")->setColumnComment('更新时间'); + }); + Db::query($sql); + $ori_fields = $this->db()->getTableFields($this->getTable()); + $new_fields = $this->generateTableField(); + $start = $ori_fields[count($ori_fields) - 3]; + foreach ($new_fields as $k => $v) { + if (!in_array($k, $ori_fields)) { + $sql = "ALTER TABLE {$this->getTable()} add $v AFTER $start"; + Db::execute($sql); + $start = $k; + } + } + } + + abstract protected function generateTableField(): array; +} \ No newline at end of file diff --git a/app/common/model/ImGroupModel.php b/app/common/model/ImGroupModel.php new file mode 100644 index 0000000..b91ccf5 --- /dev/null +++ b/app/common/model/ImGroupModel.php @@ -0,0 +1,22 @@ +colVarChar('stu_name', 30)->setColumnComment('学生姓名'); + $table->colTinyInt('sex', 1)->setColumnComment('性别:1男,2女')->setDefaultValue(1); + }); + } +} \ No newline at end of file diff --git a/app/event.php b/app/event.php new file mode 100644 index 0000000..e9851bb --- /dev/null +++ b/app/event.php @@ -0,0 +1,17 @@ + [ + ], + + 'listen' => [ + 'AppInit' => [], + 'HttpRun' => [], + 'HttpEnd' => [], + 'LogLevel' => [], + 'LogWrite' => [], + ], + + 'subscribe' => [ + ], +]; diff --git a/app/home/controller/Index.php b/app/home/controller/Index.php new file mode 100644 index 0000000..73d579d --- /dev/null +++ b/app/home/controller/Index.php @@ -0,0 +1,19 @@ +find(1); + return $data; + } + + public function hello($name = 'ThinkPHP6') + { + return 'hello,' . $name; + } +} diff --git a/app/middleware.php b/app/middleware.php new file mode 100644 index 0000000..d2c3fda --- /dev/null +++ b/app/middleware.php @@ -0,0 +1,10 @@ + Request::class, + 'think\exception\Handle' => ExceptionHandle::class, +]; diff --git a/app/service.php b/app/service.php new file mode 100644 index 0000000..db1ee6a --- /dev/null +++ b/app/service.php @@ -0,0 +1,9 @@ +=7.1.0", + "topthink/framework": "^6.0.0", + "topthink/think-orm": "^2.0", + "topthink/think-multi-app": "^1.0" + }, + "require-dev": { + "symfony/var-dumper": "^4.2", + "topthink/think-trace":"^1.0" + }, + "autoload": { + "psr-4": { + "app\\": "app" + }, + "psr-0": { + "": "extend/" + } + }, + "config": { + "preferred-install": "dist" + }, + "scripts": { + "post-autoload-dump": [ + "@php think service:discover", + "@php think vendor:publish" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..134630b --- /dev/null +++ b/composer.lock @@ -0,0 +1,830 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "9ef3f6f1993fcd90da3b2fda07e08183", + "packages": [ + { + "name": "league/flysystem", + "version": "1.0.64", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem.git", + "reference": "d13c43dbd4b791f815215959105a008515d1a2e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/d13c43dbd4b791f815215959105a008515d1a2e0", + "reference": "d13c43dbd4b791f815215959105a008515d1a2e0", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "php": ">=5.5.9" + }, + "conflict": { + "league/flysystem-sftp": "<1.0.6" + }, + "require-dev": { + "phpspec/phpspec": "^3.4", + "phpunit/phpunit": "^5.7.26" + }, + "suggest": { + "ext-fileinfo": "Required for MimeType", + "ext-ftp": "Allows you to use FTP server storage", + "ext-openssl": "Allows you to use FTPS server storage", + "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", + "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", + "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", + "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", + "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", + "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", + "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", + "league/flysystem-webdav": "Allows you to use WebDAV storage", + "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Flysystem\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frenky.net" + } + ], + "description": "Filesystem abstraction: Many filesystems, one API.", + "keywords": [ + "Cloud Files", + "WebDAV", + "abstraction", + "aws", + "cloud", + "copy.com", + "dropbox", + "file systems", + "files", + "filesystem", + "filesystems", + "ftp", + "rackspace", + "remote", + "s3", + "sftp", + "storage" + ], + "time": "2020-02-05T18:14:17+00:00" + }, + { + "name": "league/flysystem-cached-adapter", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-cached-adapter.git", + "reference": "08ef74e9be88100807a3b92cc9048a312bf01d6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-cached-adapter/zipball/08ef74e9be88100807a3b92cc9048a312bf01d6f", + "reference": "08ef74e9be88100807a3b92cc9048a312bf01d6f", + "shasum": "" + }, + "require": { + "league/flysystem": "~1.0", + "psr/cache": "^1.0.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpspec/phpspec": "^3.4", + "phpunit/phpunit": "^5.7", + "predis/predis": "~1.0", + "tedivm/stash": "~0.12" + }, + "suggest": { + "ext-phpredis": "Pure C implemented extension for PHP" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\Cached\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "frankdejonge", + "email": "info@frenky.net" + } + ], + "description": "An adapter decorator to enable meta-data caching.", + "time": "2018-07-09T20:51:04+00:00" + }, + { + "name": "opis/closure", + "version": "3.5.1", + "source": { + "type": "git", + "url": "https://github.com/opis/closure.git", + "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opis/closure/zipball/93ebc5712cdad8d5f489b500c59d122df2e53969", + "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969", + "shasum": "" + }, + "require": { + "php": "^5.4 || ^7.0" + }, + "require-dev": { + "jeremeamia/superclosure": "^2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Opis\\Closure\\": "src/" + }, + "files": [ + "functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marius Sarca", + "email": "marius.sarca@gmail.com" + }, + { + "name": "Sorin Sarca", + "email": "sarca_sorin@hotmail.com" + } + ], + "description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.", + "homepage": "https://opis.io/closure", + "keywords": [ + "anonymous functions", + "closure", + "function", + "serializable", + "serialization", + "serialize" + ], + "time": "2019-11-29T22:36:02+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2016-08-06T20:24:11+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/log", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2019-11-01T11:05:21+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-10-23T01:57:42+00:00" + }, + { + "name": "topthink/framework", + "version": "v6.0.2", + "source": { + "type": "git", + "url": "https://github.com/top-think/framework.git", + "reference": "1444cce94b40a836958380b160a5fb7bfc165daf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/framework/zipball/1444cce94b40a836958380b160a5fb7bfc165daf", + "reference": "1444cce94b40a836958380b160a5fb7bfc165daf", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "league/flysystem": "^1.0", + "league/flysystem-cached-adapter": "^1.0", + "opis/closure": "^3.1", + "php": ">=7.1.0", + "psr/container": "~1.0", + "psr/log": "~1.0", + "psr/simple-cache": "^1.0", + "topthink/think-helper": "^3.1.1", + "topthink/think-orm": "^2.0" + }, + "require-dev": { + "mikey179/vfsstream": "^1.6", + "mockery/mockery": "^1.2", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "autoload": { + "files": [], + "psr-4": { + "think\\": "src/think/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + }, + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "description": "The ThinkPHP Framework.", + "homepage": "http://thinkphp.cn/", + "keywords": [ + "framework", + "orm", + "thinkphp" + ], + "time": "2020-01-13T05:48:05+00:00" + }, + { + "name": "topthink/think-helper", + "version": "v3.1.3", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-helper.git", + "reference": "4d85dfd3778623bbb1de3648f1dcd0c82f4439f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-helper/zipball/4d85dfd3778623bbb1de3648f1dcd0c82f4439f4", + "reference": "4d85dfd3778623bbb1de3648f1dcd0c82f4439f4", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + }, + "files": [ + "src/helper.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "description": "The ThinkPHP6 Helper Package", + "time": "2019-09-30T02:36:48+00:00" + }, + { + "name": "topthink/think-multi-app", + "version": "v1.0.12", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-multi-app.git", + "reference": "3c1914d2adc08c8753c7f67228885ca47fb9b3bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-multi-app/zipball/3c1914d2adc08c8753c7f67228885ca47fb9b3bf", + "reference": "3c1914d2adc08c8753c7f67228885ca47fb9b3bf", + "shasum": "" + }, + "require": { + "php": ">=7.1.0", + "topthink/framework": "^6.0.0" + }, + "type": "library", + "extra": { + "think": { + "services": [ + "think\\app\\Service" + ] + } + }, + "autoload": { + "psr-4": { + "think\\app\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "thinkphp6 multi app support", + "time": "2020-03-01T13:29:35+00:00" + }, + { + "name": "topthink/think-orm", + "version": "v2.0.31", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-orm.git", + "reference": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-orm/zipball/d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", + "reference": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.1.0", + "psr/log": "~1.0", + "psr/simple-cache": "^1.0", + "topthink/think-helper": "^3.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + }, + "files": [] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "think orm", + "keywords": [ + "database", + "orm" + ], + "time": "2020-01-07T10:05:10+00:00" + } + ], + "packages-dev": [ + { + "name": "symfony/polyfill-mbstring", + "version": "v1.14.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/34094cfa9abe1f0f14f48f490772db7a775559f2", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2020-01-13T11:15:53+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.14.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf", + "reference": "46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2020-01-13T11:15:53+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v4.4.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "2572839911702b0405479410ea7a1334bfab0b96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/2572839911702b0405479410ea7a1334bfab0b96", + "reference": "2572839911702b0405479410ea7a1334bfab0b96", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php72": "~1.5" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", + "symfony/console": "<3.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^3.4|^4.0|^5.0", + "symfony/process": "^4.4|^5.0", + "twig/twig": "^1.34|^2.4|^3.0" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony mechanism for exploring and dumping PHP variables", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "time": "2020-02-24T13:10:00+00:00" + }, + { + "name": "topthink/think-trace", + "version": "v1.2", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-trace.git", + "reference": "4589d06a07945d57478cc2236f4b23d51ff919cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-trace/zipball/4589d06a07945d57478cc2236f4b23d51ff919cc", + "reference": "4589d06a07945d57478cc2236f4b23d51ff919cc", + "shasum": "" + }, + "require": { + "php": ">=7.1.0", + "topthink/framework": "^6.0.0" + }, + "type": "library", + "extra": { + "think": { + "services": [ + "think\\trace\\Service" + ], + "config": { + "trace": "src/config.php" + } + } + }, + "autoload": { + "psr-4": { + "think\\trace\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "thinkphp debug trace", + "time": "2019-10-17T02:14:09+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.1.0" + }, + "platform-dev": [] +} diff --git a/config/app.php b/config/app.php new file mode 100644 index 0000000..2d8c7c2 --- /dev/null +++ b/config/app.php @@ -0,0 +1,32 @@ + env('app.host', ''), + // 应用的命名空间 + 'app_namespace' => '', + // 是否启用路由 + 'with_route' => true, + // 默认应用 + 'default_app' => 'home', + // 默认时区 + 'default_timezone' => 'Asia/Shanghai', + + // 应用映射(自动多应用模式有效) + 'app_map' => [], + // 域名绑定(自动多应用模式有效) + 'domain_bind' => [], + // 禁止URL访问的应用列表(自动多应用模式有效) + 'deny_app_list' => [], + + // 异常页面的模板文件 + 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + + // 错误显示信息,非调试模式有效 + 'error_message' => '页面错误!请稍后再试~', + // 显示错误信息 + 'show_error_msg' => true, +]; diff --git a/config/cache.php b/config/cache.php new file mode 100644 index 0000000..a8d69d2 --- /dev/null +++ b/config/cache.php @@ -0,0 +1,29 @@ + env('cache.driver', 'file'), + + // 缓存连接方式配置 + 'stores' => [ + 'file' => [ + // 驱动方式 + 'type' => 'File', + // 缓存保存目录 + 'path' => '', + // 缓存前缀 + 'prefix' => '', + // 缓存有效期 0表示永久缓存 + 'expire' => 0, + // 缓存标签前缀 + 'tag_prefix' => 'tag:', + // 序列化机制 例如 ['serialize', 'unserialize'] + 'serialize' => [], + ], + // 更多的缓存连接 + ], +]; diff --git a/config/console.php b/config/console.php new file mode 100644 index 0000000..a818a98 --- /dev/null +++ b/config/console.php @@ -0,0 +1,9 @@ + [ + ], +]; diff --git a/config/cookie.php b/config/cookie.php new file mode 100644 index 0000000..f728024 --- /dev/null +++ b/config/cookie.php @@ -0,0 +1,18 @@ + 0, + // cookie 保存路径 + 'path' => '/', + // cookie 有效域名 + 'domain' => '', + // cookie 启用安全传输 + 'secure' => false, + // httponly设置 + 'httponly' => false, + // 是否使用 setcookie + 'setcookie' => true, +]; diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..ea5af9c --- /dev/null +++ b/config/database.php @@ -0,0 +1,62 @@ + env('database.driver', 'mysql'), + + // 自定义时间查询规则 + 'time_query_rule' => [], + + // 自动写入时间戳字段 + // true为自动识别类型 false关闭 + // 字符串则明确指定时间字段类型 支持 int timestamp datetime date + 'auto_timestamp' => true, + + // 时间字段取出后的默认时间格式 + 'datetime_format' => 'Y-m-d H:i:s', + + // 数据库连接配置信息 + 'connections' => [ + 'mysql' => [ + // 数据库类型 + 'type' => env('database.type', 'mysql'), + // 服务器地址 + 'hostname' => env('database.hostname', '127.0.0.1'), + // 数据库名 + 'database' => env('database.database', 'test'), + // 用户名 + 'username' => env('database.username', 'root'), + // 密码 + 'password' => env('database.password', ''), + // 端口 + 'hostport' => env('database.hostport', '3306'), + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => env('database.charset', 'utf8'), + // 数据库表前缀 + 'prefix' => env('database.prefix', 'lst_'), + + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 是否需要断线重连 + 'break_reconnect' => false, + // 监听SQL + 'trigger_sql' => env('app_debug', true), + // 开启字段缓存 + 'fields_cache' => false, + // 字段缓存路径 + 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, + ], + + // 更多的数据库配置信息 + ], +]; diff --git a/config/filesystem.php b/config/filesystem.php new file mode 100644 index 0000000..965297e --- /dev/null +++ b/config/filesystem.php @@ -0,0 +1,24 @@ + env('filesystem.driver', 'local'), + // 磁盘列表 + 'disks' => [ + 'local' => [ + 'type' => 'local', + 'root' => app()->getRuntimePath() . 'storage', + ], + 'public' => [ + // 磁盘类型 + 'type' => 'local', + // 磁盘路径 + 'root' => app()->getRootPath() . 'public/storage', + // 磁盘路径对应的外部URL路径 + 'url' => '/storage', + // 可见性 + 'visibility' => 'public', + ], + // 更多的磁盘配置信息 + ], +]; diff --git a/config/lang.php b/config/lang.php new file mode 100644 index 0000000..e3b4986 --- /dev/null +++ b/config/lang.php @@ -0,0 +1,25 @@ + env('lang.default_lang', 'zh-cn'), + // 允许的语言列表 + 'allow_lang_list' => [], + // 多语言自动侦测变量名 + 'detect_var' => 'lang', + // 是否使用Cookie记录 + 'use_cookie' => true, + // 多语言cookie变量 + 'cookie_var' => 'think_lang', + // 扩展语言包 + 'extend_list' => [], + // Accept-Language转义为对应语言包名称 + 'accept_language' => [ + 'zh-hans-cn' => 'zh-cn', + ], + // 是否支持语言分组 + 'allow_group' => false, +]; diff --git a/config/log.php b/config/log.php new file mode 100644 index 0000000..ea24ff9 --- /dev/null +++ b/config/log.php @@ -0,0 +1,45 @@ + env('log.channel', 'file'), + // 日志记录级别 + 'level' => [], + // 日志类型记录的通道 ['error'=>'email',...] + 'type_channel' => [], + // 关闭全局日志写入 + 'close' => false, + // 全局日志处理 支持闭包 + 'processor' => null, + + // 日志通道列表 + 'channels' => [ + 'file' => [ + // 日志记录方式 + 'type' => 'File', + // 日志保存目录 + 'path' => '', + // 单文件日志写入 + 'single' => false, + // 独立日志级别 + 'apart_level' => [], + // 最大日志文件数量 + 'max_files' => 0, + // 使用JSON格式记录 + 'json' => false, + // 日志处理 + 'processor' => null, + // 关闭通道日志写入 + 'close' => false, + // 日志输出格式化 + 'format' => '[%s][%s] %s', + // 是否实时写入 + 'realtime_write' => false, + ], + // 其它日志通道配置 + ], + +]; diff --git a/config/middleware.php b/config/middleware.php new file mode 100644 index 0000000..7e1972f --- /dev/null +++ b/config/middleware.php @@ -0,0 +1,8 @@ + [], + // 优先级设置,此数组中的中间件会按照数组中的顺序优先执行 + 'priority' => [], +]; diff --git a/config/route.php b/config/route.php new file mode 100644 index 0000000..955eeec --- /dev/null +++ b/config/route.php @@ -0,0 +1,45 @@ + '/', + // URL伪静态后缀 + 'url_html_suffix' => 'html', + // URL普通方式参数 用于自动生成 + 'url_common_param' => true, + // 是否开启路由延迟解析 + 'url_lazy_route' => false, + // 是否强制使用路由 + 'url_route_must' => false, + // 合并路由规则 + 'route_rule_merge' => false, + // 路由是否完全匹配 + 'route_complete_match' => false, + // 访问控制器层名称 + 'controller_layer' => 'controller', + // 空控制器名 + 'empty_controller' => 'Error', + // 是否使用控制器后缀 + 'controller_suffix' => false, + // 默认的路由变量规则 + 'default_route_pattern' => '[\w\.]+', + // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 + 'request_cache' => false, + // 请求缓存有效期 + 'request_cache_expire' => null, + // 全局请求缓存排除规则 + 'request_cache_except' => [], + // 默认控制器名 + 'default_controller' => 'Index', + // 默认操作名 + 'default_action' => 'index', + // 操作方法后缀 + 'action_suffix' => '', + // 默认JSONP格式返回的处理方法 + 'default_jsonp_handler' => 'jsonpReturn', + // 默认JSONP处理方法 + 'var_jsonp_handler' => 'callback', +]; diff --git a/config/session.php b/config/session.php new file mode 100644 index 0000000..c1ef6e1 --- /dev/null +++ b/config/session.php @@ -0,0 +1,19 @@ + 'PHPSESSID', + // SESSION_ID的提交变量,解决flash上传跨域 + 'var_session_id' => '', + // 驱动方式 支持file cache + 'type' => 'file', + // 存储连接标识 当type使用cache的时候有效 + 'store' => null, + // 过期时间 + 'expire' => 1440, + // 前缀 + 'prefix' => '', +]; diff --git a/config/trace.php b/config/trace.php new file mode 100644 index 0000000..fad2392 --- /dev/null +++ b/config/trace.php @@ -0,0 +1,10 @@ + 'Html', + // 读取的日志通道名 + 'channel' => '', +]; diff --git a/config/view.php b/config/view.php new file mode 100644 index 0000000..01259a0 --- /dev/null +++ b/config/view.php @@ -0,0 +1,25 @@ + 'Think', + // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 + 'auto_rule' => 1, + // 模板目录名 + 'view_dir_name' => 'view', + // 模板后缀 + 'view_suffix' => 'html', + // 模板文件名分隔符 + 'view_depr' => DIRECTORY_SEPARATOR, + // 模板引擎普通标签开始标记 + 'tpl_begin' => '{', + // 模板引擎普通标签结束标记 + 'tpl_end' => '}', + // 标签库标签开始标记 + 'taglib_begin' => '{', + // 标签库标签结束标记 + 'taglib_end' => '}', +]; diff --git a/extend/mysql_dll/autoload.php b/extend/mysql_dll/autoload.php new file mode 100644 index 0000000..4c2dbea --- /dev/null +++ b/extend/mysql_dll/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/extend/mysql_dll/composer/LICENSE b/extend/mysql_dll/composer/LICENSE new file mode 100644 index 0000000..f27399a --- /dev/null +++ b/extend/mysql_dll/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/extend/mysql_dll/composer/autoload_classmap.php b/extend/mysql_dll/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/extend/mysql_dll/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($vendorDir . '/textalk/websocket/lib'), + 'EasySwoole\\Spl\\Test\\' => array($vendorDir . '/easyswoole/spl/test'), + 'EasySwoole\\Spl\\' => array($vendorDir . '/easyswoole/spl/src'), + 'EasySwoole\\DDL\\Test\\' => array($vendorDir . '/easyswoole/ddl/test'), + 'EasySwoole\\DDL\\' => array($vendorDir . '/easyswoole/ddl/src'), +); diff --git a/extend/mysql_dll/composer/autoload_real.php b/extend/mysql_dll/composer/autoload_real.php new file mode 100644 index 0000000..cc43c55 --- /dev/null +++ b/extend/mysql_dll/composer/autoload_real.php @@ -0,0 +1,52 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInite4e760d3dabd5a5ecb618c06e992f333::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/extend/mysql_dll/composer/autoload_static.php b/extend/mysql_dll/composer/autoload_static.php new file mode 100644 index 0000000..76172ec --- /dev/null +++ b/extend/mysql_dll/composer/autoload_static.php @@ -0,0 +1,54 @@ + + array ( + 'WebSocket\\' => 10, + ), + 'E' => + array ( + 'EasySwoole\\Spl\\Test\\' => 20, + 'EasySwoole\\Spl\\' => 15, + 'EasySwoole\\DDL\\Test\\' => 20, + 'EasySwoole\\DDL\\' => 15, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'WebSocket\\' => + array ( + 0 => __DIR__ . '/..' . '/textalk/websocket/lib', + ), + 'EasySwoole\\Spl\\Test\\' => + array ( + 0 => __DIR__ . '/..' . '/easyswoole/spl/test', + ), + 'EasySwoole\\Spl\\' => + array ( + 0 => __DIR__ . '/..' . '/easyswoole/spl/src', + ), + 'EasySwoole\\DDL\\Test\\' => + array ( + 0 => __DIR__ . '/..' . '/easyswoole/ddl/test', + ), + 'EasySwoole\\DDL\\' => + array ( + 0 => __DIR__ . '/..' . '/easyswoole/ddl/src', + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInite4e760d3dabd5a5ecb618c06e992f333::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInite4e760d3dabd5a5ecb618c06e992f333::$prefixDirsPsr4; + + }, null, ClassLoader::class); + } +} diff --git a/extend/mysql_dll/composer/installed.json b/extend/mysql_dll/composer/installed.json new file mode 100644 index 0000000..d8f3c2f --- /dev/null +++ b/extend/mysql_dll/composer/installed.json @@ -0,0 +1,139 @@ +[ + { + "name": "easyswoole/ddl", + "version": "1.0.4", + "version_normalized": "1.0.4.0", + "source": { + "type": "git", + "url": "https://github.com/easy-swoole/ddl.git", + "reference": "84dbada2c49115b2bacc6a4cc10b166205fae14a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-swoole/ddl/zipball/84dbada2c49115b2bacc6a4cc10b166205fae14a", + "reference": "84dbada2c49115b2bacc6a4cc10b166205fae14a", + "shasum": "" + }, + "require": { + "easyswoole/spl": "^1.2" + }, + "time": "2019-11-08T11:12:30+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "EasySwoole\\DDL\\": "src/", + "EasySwoole\\DDL\\Test\\": "test/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "YF", + "email": "291323003@qq.com" + } + ], + "description": "An efficient swoole framework", + "homepage": "https://www.easyswoole.com/", + "keywords": [ + "async", + "easyswoole", + "framework", + "swoole" + ] + }, + { + "name": "easyswoole/spl", + "version": "1.3.3", + "version_normalized": "1.3.3.0", + "source": { + "type": "git", + "url": "https://github.com/easy-swoole/spl.git", + "reference": "d0fb72ee0a9febf64a241ebc1cbcaad47d657570" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-swoole/spl/zipball/d0fb72ee0a9febf64a241ebc1cbcaad47d657570", + "reference": "d0fb72ee0a9febf64a241ebc1cbcaad47d657570", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.1.0" + }, + "require-dev": { + "easyswoole/phpunit": "^1.0" + }, + "time": "2019-12-11T03:16:51+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "EasySwoole\\Spl\\": "src/", + "EasySwoole\\Spl\\Test\\": "test/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "YF", + "email": "291323003@qq.com" + } + ], + "description": "php stander lib", + "homepage": "https://www.easyswoole.com/", + "keywords": [ + "async", + "easyswoole", + "framework", + "swoole" + ] + }, + { + "name": "textalk/websocket", + "version": "1.2.0", + "version_normalized": "1.2.0.0", + "source": { + "type": "git", + "url": "https://github.com/Textalk/websocket-php.git", + "reference": "bfa18bb6bf523680c7803f6b04694fbbf2f67bbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Textalk/websocket-php/zipball/bfa18bb6bf523680c7803f6b04694fbbf2f67bbf", + "reference": "bfa18bb6bf523680c7803f6b04694fbbf2f67bbf", + "shasum": "" + }, + "require-dev": { + "cboden/ratchet": "0.3.*", + "phpunit/phpunit": "4.1.*", + "phpunit/phpunit-selenium": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "time": "2015-10-09T07:32:42+00:00", + "type": "library", + "installation-source": "source", + "autoload": { + "psr-4": { + "WebSocket\\": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fredrik Liljegren", + "email": "fredrik.liljegren@textalk.se" + } + ], + "description": "WebSocket client and server" + } +] diff --git a/extend/mysql_dll/easyswoole/ddl/README.md b/extend/mysql_dll/easyswoole/ddl/README.md new file mode 100644 index 0000000..6132e69 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/README.md @@ -0,0 +1,117 @@ +# DDL +数据库模式定义语言DDL(Data Definition Language),是用于描述数据库中要存储的现实世界实体的语言。 +其实就是我们在创建表的时候用到的一些sql,比如说:CREATE、ALTER、DROP等。 + +## 测试代码 + +```php + +use EasySwoole\DDL\Blueprint\Table; +use EasySwoole\DDL\DDLBuilder; +use EasySwoole\DDL\Enum\Character; +use EasySwoole\DDL\Enum\Engine; + +$sql = DDLBuilder::table('user', function (Table $table) { + $table->setIfNotExists()->setTableComment('用户表'); //设置表名称/ + $table->setTableEngine(Engine::MYISAM); //设置表引擎 + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('user_id', 10)->setColumnComment('用户ID')->setIsAutoIncrement()->setIsPrimaryKey(); //创建user_id设置主键并自动增长 + $table->colVarChar('username', 30)->setIsNotNull()->setColumnComment('用户名')->setDefaultValue(''); + $table->colChar('sex', 1)->setIsNotNull()->setColumnComment('性别:1男,2女')->setDefaultValue(1); + $table->colTinyInt('age')->setIsNotNull()->setColumnComment('年龄')->setIsUnsigned(); + $table->colText('intro')->setIsNotNull()->setColumnComment('简介'); + $table->colDate('birthday')->setIsNotNull()->setColumnComment('出生日期'); + $table->colDecimal('money', 10, 2)->setIsNotNull()->setColumnComment('金额')->setDefaultValue(0); + $table->colInt('created_at', 10)->setIsNotNull()->setColumnComment('创建时间'); + $table->colInt('updated_at', 10)->setIsNotNull()->setColumnComment('更新时间'); + $table->indexUnique('username_index', 'username')->setIndexComment('用户名唯一索引');//设置索引 + $table->indexNormal('username_age_index', ['username', 'age'])->setIndexComment('用户名-年龄'); +}); +//以下是生成的sql的语句 +CREATE TABLE IF NOT EXISTS `user` ( + `user_id` int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '用户ID', + `username` varchar(30) NOT NULL DEFAULT '' COMMENT '用户名', + `sex` char(1) NOT NULL DEFAULT 1 COMMENT '性别:1男,2女', + `age` tinyint UNSIGNED NOT NULL COMMENT '年龄', + `intro` text NOT NULL COMMENT '简介', + `birthday` date NOT NULL COMMENT '出生日期', + `money` decimal(10,2) NOT NULL DEFAULT 0 COMMENT '金额', + `created_at` int(10) NOT NULL COMMENT '创建时间', + `updated_at` int(10) NOT NULL COMMENT '更新时间', + UNIQUE INDEX `username_index` (`username`) COMMENT '用户名唯一索引', + INDEX `username_age_index` (`username`,`age`) COMMENT '用户名-年龄' +) +ENGINE = MYISAM DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '用户表'; + +------------------------------------------------------------------------------------ + +$stuQql = DDLBuilder::table('student', function (Table $table) { + $table->setIfNotExists()->setTableComment('学生表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('stu_id')->setIsAutoIncrement()->setIsPrimaryKey()->setIsUnsigned()->setColumnComment('学生ID'); //创建stu_id设置主键并自动增长 + $table->colVarChar('stu_name', 30)->setColumnComment('学生姓名'); + $table->colChar('sex', 1)->setColumnComment('性别:1男,2女')->setDefaultValue(1); + $table->colDate('birthday')->setIsNotNull(false)->setColumnComment('出生日期'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); + $table->colInt('updated_at', 10)->setColumnComment('更新时间'); + $table->indexNormal('stu_name_index', 'stu_name')->setIndexComment('学生姓名--普通索引');//设置索引 +}); + +CREATE TABLE IF NOT EXISTS `student` ( + `stu_id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '学生ID', + `stu_name` varchar(30) NOT NULL COMMENT '学生姓名', + `sex` char(1) NOT NULL DEFAULT 1 COMMENT '性别:1男,2女', + `birthday` date NULL DEFAULT NULL COMMENT '出生日期', + `created_at` int(10) NOT NULL COMMENT '创建时间', + `updated_at` int(10) NOT NULL COMMENT '更新时间', + INDEX `stu_name_index` (`stu_name`) COMMENT '学生姓名--普通索引' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '学生表'; + +------------------------------------------------------------------------------------ + +$courseSql = DDLBuilder::table('course', function (Table $table) { + $table->setIfNotExists()->setTableComment('课程表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('id', 3)->setIsPrimaryKey()->setIsAutoIncrement()->setIsUnsigned()->setZeroFill()->setColumnComment('课程id'); + $table->colVarChar('course_name', 100)->setColumnComment('课程名称'); + $table->colChar('status', 1)->setDefaultValue(1)->setColumnComment('课程状态:1正常,0隐藏'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); + $table->colInt('updated_at', 10)->setColumnComment('更新时间'); + $table->indexUnique('course_name_index', 'course_name')->setIndexComment('课程名称--唯一索引');//设置索引 +}); + + +CREATE TABLE IF NOT EXISTS `course` ( + `id` int(3) UNSIGNED ZEROFILL NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '课程id', + `course_name` varchar(100) NOT NULL COMMENT '课程名称', + `status` char(1) NOT NULL DEFAULT 1 COMMENT '课程状态:1正常,0隐藏', + `created_at` int(10) NOT NULL COMMENT '创建时间', + `updated_at` int(10) NOT NULL COMMENT '更新时间', + UNIQUE INDEX `course_name_index` (`course_name`) COMMENT '课程名称--唯一索引' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '课程表'; + +------------------------------------------------------------------------------------ + +$scoreSql = DDLBuilder::table('score', function (Table $table) { + $table->setIfNotExists()->setTableComment('成绩表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('id')->setIsUnsigned()->setIsAutoIncrement()->setIsPrimaryKey()->setColumnComment('自增ID'); + $table->colInt('stu_id')->setIsUnsigned()->setColumnComment('学生id'); + $table->colInt('course_id')->setIsUnsigned()->setZeroFill()->setColumnComment('课程id'); + $table->colFloat('score', 3, 1)->setColumnComment('成绩'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); +}); + +CREATE TABLE IF NOT EXISTS `score` ( + `id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID', + `stu_id` int UNSIGNED NOT NULL COMMENT '学生id', + `course_id` int UNSIGNED ZEROFILL NOT NULL COMMENT '课程id', + `score` float(3,1) NOT NULL COMMENT '成绩', + `created_at` int(10) NOT NULL COMMENT '创建时间' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '成绩表'; + +``` + diff --git a/extend/mysql_dll/easyswoole/ddl/composer.json b/extend/mysql_dll/easyswoole/ddl/composer.json new file mode 100644 index 0000000..e9a2ac5 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/composer.json @@ -0,0 +1,28 @@ +{ + "name": "easyswoole/ddl", + "type": "library", + "description": "An efficient swoole framework", + "keywords": [ + "swoole", + "framework", + "async", + "easyswoole" + ], + "homepage": "https://www.easyswoole.com/", + "license": "Apache-2.0", + "authors": [ + { + "name": "YF", + "email": "291323003@qq.com" + } + ], + "autoload": { + "psr-4": { + "EasySwoole\\DDL\\": "src/", + "EasySwoole\\DDL\\Test\\":"test/" + } + }, + "require": { + "easyswoole/spl": "^1.2" + } +} diff --git a/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Column.php b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Column.php new file mode 100644 index 0000000..d966591 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Column.php @@ -0,0 +1,416 @@ +setColumnName($columnName); + $this->setColumnType($columnType); + } + + /** + * 是否无符号 + * @param bool $enable + * @return Column + */ + function setIsUnsigned(bool $enable = true): Column + { + // TODO 暂未做规范判断 + // 同样需要做规范判断 字段为文本/日期时间/BLOB时不能设置为无符号 + $this->unsigned = $enable; + return $this; + } + + /** + * 是否值自增 + * @param bool $enable + * @return Column + */ + function setIsAutoIncrement(bool $enable = true): Column + { + // TODO 暂未做规范判断 + // 同样需要做规范判断 只有数字类型才允许自增 + $this->autoIncrement = $enable; + return $this; + } + + /** + * 转化为字符串 + * @return string + */ + function __toString() + { + return $this->__createDDL(); + } + + /** + * 创建DDL + * 带下划线的方法请不要外部调用 + * @return string + */ + function __createDDL(): string + { + FilterLimit::run($this);//检测limit是否合法 + FilterUnsigned::run($this); //检测无符号类型 + FilterZerofill::run($this); //检测是否补充长度 + $default = $this->parseDefaultValue(); + $columnCharset = $this->columnCharset ? explode('_', $this->columnCharset)[0] : false; + return implode(' ', + array_filter( + [ + '`' . $this->columnName . '`', + (string)$this->parseDataType(), + $this->isBinary ? 'BINARY' : null, + $this->columnCharset ? 'CHARACTER SET ' . strtoupper($columnCharset) . ' COLLATE ' . strtoupper($this->columnCharset) : null, + $this->unsigned ? 'UNSIGNED' : null, + $this->zeroFill ? 'ZEROFILL' : null, + $this->isUnique ? 'UNIQUE' : null, + $this->isNotNull ? 'NOT NULL' : 'NULL', + $default !== false ? 'DEFAULT ' . $default : null, + $this->isPrimaryKey ? 'PRIMARY KEY' : null, + $this->autoIncrement ? 'AUTO_INCREMENT' : null, + $this->columnComment ? sprintf("COMMENT '%s'", addslashes($this->columnComment)) : null + ] + ) + ); + } + + /** + * 处理字段的默认值 + * @return bool|string + */ + private function parseDefaultValue() + { + // AUTO_INCREMENT 和默认值不能同时出现 + if ($this->autoIncrement) { + return false; + } + // 如果当前允许NULL值 而没有设置默认值 那么默认就为NULL + if (!$this->isNotNull && ($this->defaultValue == null || $this->defaultValue == 'NULL')) { + return 'NULL'; + } + // 否则字段是不允许NULL值的 如果默认值是文本应该加入引号 + if (is_string($this->defaultValue) && !DataType::typeIsDatetime($this->parseDataType())) { + return "'" . $this->defaultValue . "'"; + } else if (is_bool($this->defaultValue)) { // 布尔类型强转0和1 + return $this->defaultValue ? '1' : '0'; + } else if (is_null($this->defaultValue)) { + return false; + } else if (DataType::typeIsDatetime($this->parseDataType())) { // 其他类型强转String + if (stripos($this->defaultValue, "CURRENT_TIMESTAMP") === false) { + return "'" . $this->defaultValue . "'"; + } + return $this->defaultValue; + } else { + return (string)$this->defaultValue; + } + } + + /** + * 处理数据类型 + * @return string + */ + private function parseDataType() + { + $columnLimit = $this->parseColumnLimit(); + $columnType = $this->columnType; + if ($columnLimit) { + $columnType .= $columnLimit; + } + return $columnType; + } + + /** + * 处理字段的类型宽度限制 + * @return bool|string + */ + private function parseColumnLimit() + { + // 是一个数组需要用逗号接起来 + if (is_array($this->columnLimit)) { + return "(" . implode(',', $this->columnLimit) . ")"; + } + // 是一个数字可以直接设置在类型后面 + if (is_numeric($this->columnLimit)) { + return "(" . $this->columnLimit . ")"; + } + // 否则没有设置 + return false; + } + + /** + * @return mixed + */ + public function getColumnName() + { + return $this->columnName; + } + + /** + * 设置字段名称 + * @param string $name 字段名称 + * @return Column + */ + function setColumnName(string $name): Column + { + $name = trim($name); + if (empty($name)) { + throw new InvalidArgumentException('The column name cannot be empty'); + } + $this->columnName = $name; + return $this; + } + + /** + * @return mixed + */ + public function getColumnType() + { + return $this->columnType; + } + + /** + * 设置字段类型 + * @param string $type + * @return Column + */ + function setColumnType(string $type): Column + { + $type = trim($type); + if (!DataType::isValidValue($type)) { + throw new InvalidArgumentException('The column type ' . $type . ' is invalid'); + } + $this->columnType = $type; + return $this; + } + + /** + * @return mixed + */ + public function getColumnLimit() + { + return $this->columnLimit; + } + + /** + * 设置字段列宽限制 + * @param integer|array $limit + * @return Column + */ + function setColumnLimit($limit): Column + { + // TODO 暂未做规范判断 + // 此处根据类型的不同实际上还应该判断 TEXT/BLOB 不可能存在limit + // 另外数字类型如 INT DisplayWidth < 256 | DECIMAL (1,5) 总精度必须大于小数部分精度等限制 + $this->columnLimit = $limit; + return $this; + } + + /** + * @return mixed + */ + public function getColumnComment() + { + return $this->columnComment; + } + + /** + * 设置字段备注 + * @param string $comment + * @return Column + */ + function setColumnComment(string $comment): Column + { + $this->columnComment = $comment; + return $this; + } + + /** + * @return mixed + */ + public function getColumnCharset() + { + return $this->columnCharset; + } + + /** + * 设置字段编码 + * @param string $charset + * @return Column + */ + function setColumnCharset(string $charset): Column + { + $this->columnCharset = $charset; + return $this; + } + + /** + * @return mixed + */ + public function getIsBinary() + { + return $this->isBinary; + } + + /** + * 是否二进制 + * 在字符列上设置了二进制会使得该列严格区分大小写 + * @param bool $enable + * @return Column + */ + function setIsBinary(bool $enable = true): Column + { + // TODO 暂未做规范判断 + // 同样需要做规范判断 只有字符串类型才允许二进制 + $this->isBinary = $enable; + return $this; + } + + /** + * @return mixed + */ + public function getIsUnique() + { + return $this->isUnique; + } + + /** + * 字段设置为Unique + * 请不要和索引互相重复设置 + * @param bool $enable + * @return Column + */ + function setIsUnique(bool $enable = true): Column + { + $this->isUnique = $enable; + return $this; + } + + /** + * @return mixed + */ + public function getUnsigned() + { + return $this->unsigned; + } + + /** + * @return mixed + */ + public function getZeroFill() + { + return $this->zeroFill; + } + + /** + * 是否零填充 + * @param bool $enable + * @return Column + */ + function setZeroFill(bool $enable = true): Column + { + $this->zeroFill = $enable; + return $this; + } + + /** + * @return mixed + */ + public function getDefaultValue() + { + return $this->defaultValue; + } + + /** + * 字段默认值 + * @param $value + * @return Column + */ + function setDefaultValue($value): Column + { + // TODO 暂未做规范判断 + // 同样需要做规范判断 字段为文本/BLOB时不能设置默认值 + $this->defaultValue = $value; + return $this; + } + + /** + * @return bool + */ + public function getIsNotNull(): bool + { + return $this->isNotNull; + } + + /** + * 设置不可空 + * @param bool $enable + * @return Column + */ + function setIsNotNull(bool $enable = true): Column + { + $this->isNotNull = $enable; + return $this; + } + + /** + * @return mixed + */ + public function getAutoIncrement() + { + return $this->autoIncrement; + } + + /** + * @return mixed + */ + public function getIsPrimaryKey() + { + return $this->isPrimaryKey; + } + + /** + * 直接在字段上设置PK + * 请不要和索引互相重复设置 + * @param bool $enable + * @return Column + */ + function setIsPrimaryKey(bool $enable = true): Column + { + $this->isPrimaryKey = $enable; + return $this; + } +} diff --git a/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Index.php b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Index.php new file mode 100644 index 0000000..002fca7 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Index.php @@ -0,0 +1,132 @@ +setIndexName($indexName); + $this->setIndexType($indexType); + $this->setIndexColumns($indexColumns); + } + + /** + * 设置索引名称 + * @param string $name + * @return Index + */ + function setIndexName(?string $name = null): Index + { + $name = is_string($name) ? trim($name) : null; + $this->indexName = $name; + return $this; + } + + /** + * 设置索引类型 + * @param string $type + * @return Index + */ + function setIndexType(string $type): Index + { + $type = trim($type); + if (!IndexType::isValidValue($type)) { + throw new InvalidArgumentException('The index type ' . $type . ' is invalid'); + } + $this->indexType = $type; + return $this; + } + + /** + * 设置索引字段 + * @param string|array $columns 可以设置字符串和数组 + * @return Index + */ + function setIndexColumns($columns): Index + { + $this->indexColumns = $columns; + return $this; + } + + /** + * 设置索引备注 + * @param string $comment + * @return Index + */ + function setIndexComment(string $comment): Index + { + $this->indexComment = $comment; + return $this; + } + + /** + * 组装索引字段名 + * @return string + */ + function parseIndexColumns() + { + $columnDDLs = []; + $indexColumns = $this->indexColumns; + if (is_string($indexColumns)) { + $indexColumns = array($indexColumns); + } + foreach ($indexColumns as $indexedColumn) { + $columnDDLs[] = '`' . $indexedColumn . '`'; + } + return '(' . implode(',', $columnDDLs) . ')'; + } + + /** + * 生成索引DDL结构 + * 带有下划线的方法请不要自行调用 + * @return string + */ + function __createDDL() + { + $indexPrefix = [ + IndexType::NORMAL => 'INDEX', + IndexType::UNIQUE => 'UNIQUE INDEX', + IndexType::PRIMARY => 'PRIMARY KEY', + IndexType::FULLTEXT => 'FULLTEXT INDEX', + ]; + return implode(' ', + array_filter( + [ + $indexPrefix[$this->indexType], + $this->indexName !== null ? '`' . $this->indexName . '`' : null, + $this->parseIndexColumns(), + $this->indexComment ? "COMMENT '" . addslashes($this->indexComment) . "'" : null + ] + ) + ); + } + + /** + * 转化为字符串 + * @return string + */ + function __toString() + { + return $this->__createDDL(); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Table.php b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Table.php new file mode 100644 index 0000000..e8e2437 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Blueprint/Table.php @@ -0,0 +1,572 @@ +table = $tableName; + } + + // 以下为字段构造方法 + + /** + * 整数 INT + * @param string $name 字段名称 + * @param null|integer $limit INT 4Bytes(2^31) + * @return mixed + */ + function colInt(string $name, int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::INT); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 创建一个列对象 + * 继承可以改变返回的类对象以使用自定义对象 + * @param string $columnName + * @param string $columnType + * @return Column + */ + protected function createColumn(string $columnName, string $columnType) + { + return new Column($columnName, $columnType); + } + + /** + * 整数 BIGINT + * @param string $name 字段名称 + * @param int|null $limit BIGINT 8Bytes(2^63) + * @return Column + */ + function colBigInt(string $name, int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::BIGINT); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 整数 TINYINT + * @param string $name 字段名称 + * @param int|null $limit TINYINT 1Bytes(2^7) + * @return Column + */ + function colTinyInt(string $name, int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::TINYINT); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 整数 SMALLINT + * @param string $name 字段名称 + * @param int|null $limit TINYINT 2Bytes(2^15) + * @return Column + */ + function colSmallInt(string $name, int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::SMALLINT); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 整数 MEDIUMINT + * @param string $name 字段名称 + * @param int|null $limit MEDIUMINT 3Bytes(2^23) + * @return Column + */ + function colMediumInt(string $name, int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::MEDIUMINT); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 单精度浮点 - FLOAT + * 注: 当设置总精度为24-53内部实际上是DOUBLE序列 + * @param string $name 字段名称 + * @param int|null $precision 字段总精度(允许储存多少位数|含小数点) + * @param int|null $digits 小数点部分的精度(可空) + * @return Column + */ + function colFloat(string $name, int $precision = null, int $digits = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::FLOAT); + if (is_numeric($precision) && is_numeric($digits)) { + $this->columns[$name]->setColumnLimit([$precision, $digits]); + } elseif (is_numeric($precision)) { + $this->columns[$name]->setColumnLimit($precision); + } + return $this->columns[$name]; + } + + /** + * 双精度浮点 - DOUBLE + * @param string $name 字段名称 + * @param int|null $precision 字段总精度(允许储存多少位数|含小数点) + * @param int|null $digits 小数点部分的精度(可空) + * @return Column + */ + function colDouble(string $name, int $precision = null, int $digits = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::DOUBLE); + if (is_numeric($precision) && is_numeric($digits)) { + $this->columns[$name]->setColumnLimit([$precision, $digits]); + } elseif (is_numeric($precision)) { + $this->columns[$name]->setColumnLimit($precision); + } + return $this->columns[$name]; + } + + /** + * 定点小数 - DECIMAL + * 注意当设置小数精度和总精度一致时整数部分只能为零 + * 注: 当未设置精度时MYSQL默认按 DECIMAL(10,0) 所以此处给出默认值 + * @param string $name 字段名称 + * @param int $precision 字段总精度(允许储存多少位数|含小数点) + * @param int $digits 小数点部分的精度 + * @return Column + */ + function colDecimal(string $name, int $precision = 10, int $digits = 0): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::DECIMAL); + $this->columns[$name]->setColumnLimit([$precision, $digits]); + return $this->columns[$name]; + } + + /** + * 日期时间 - DATE + * @param string $name 字段名称 + * @return Column + */ + function colDate(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::DATE); + return $this->columns[$name]; + } + + /** + * 日期时间 - YEAR + * @param string $name 字段名称 + * @return Column + */ + function colYear(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::YEAR); + return $this->columns[$name]; + } + + /** + * 日期时间 - TIME + * @param string $name 字段名称 + * @param int|null $fsp 精度分数(详见MYSQL文档) + * @return Column + */ + function colTime(string $name, ?int $fsp = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::TIME); + if (is_numeric($fsp)) $this->columns[$name]->setColumnLimit($fsp); + return $this->columns[$name]; + } + + /** + * 日期时间 - DATETIME + * @param string $name 字段名称 + * @param int|null $fsp 精度分数(详见MYSQL文档) + * @return Column + */ + function colDateTime(string $name, ?int $fsp = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::DATETIME); + if (is_numeric($fsp)) $this->columns[$name]->setColumnLimit($fsp); + return $this->columns[$name]; + } + + /** + * 日期时间 - TIMESTAMP + * @param string $name 字段名称 + * @param int|null $fsp 精度分数(详见MYSQL文档) + * @return Column + */ + function colTimestamp(string $name, ?int $fsp = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::TIMESTAMP); + if (is_numeric($fsp)) $this->columns[$name]->setColumnLimit($fsp); + return $this->columns[$name]; + } + + /** + * 字符串 - CHAR + * @param string $name 字段名称 + * @param int|null $limit + * @return Column + */ + function colChar(string $name, ?int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::CHAR); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 字符串 - VARCHAR + * @param string $name 字段名称 + * @param int|null $limit + * @return Column + */ + function colVarChar(string $name, ?int $limit = null): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::VARCHAR); + $this->columns[$name]->setColumnLimit($limit); + return $this->columns[$name]; + } + + /** + * 字符串 - TEXT + * @param string $name 字段名称 + * @return Column + */ + function colText(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::TEXT); + return $this->columns[$name]; + } + + /** + * 字符串 - TINYTEXT + * @param string $name 字段名称 + * @return Column + */ + function colTinyText(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::TINYTEXT); + return $this->columns[$name]; + } + + /** + * 字符串 - LONGTEXT + * @param string $name 字段名称 + * @return Column + */ + function colLongText(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::LONGTEXT); + return $this->columns[$name]; + } + + /** + * 字符串 - MEDIUMTEXT + * @param string $name 字段名称 + * @return Column + */ + function colMediumText(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::MEDIUMTEXT); + return $this->columns[$name]; + } + + /** + * 二进制字符串 - BLOB + * @param string $name 字段名称 + * @return Column + */ + function colBlob(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::BLOB); + return $this->columns[$name]; + } + + /** + * 二进制字符串 - LONGBLOB + * @param string $name 字段名称 + * @return Column + */ + function colLongBlob(string $name): Column + { + $this->columns[$name] = $this->createColumn($name, DataType::LONGBLOB); + return $this->columns[$name]; + } + + /** + * 二进制字符串 - TINYBLOB + * @param string $name 字段名称 + * @return mixed + */ + function colTinyBlob(string $name) + { + $this->columns[$name] = $this->createColumn($name, DataType::TINYBLOB); + return $this->columns[$name]; + } + + + // 以下为索引构造方法 + + /** + * 二进制字符串 - MEDIUMBLOB + * @param string $name 字段名称 + * @return mixed + */ + function colMediumBlob(string $name) + { + $this->columns[$name] = $this->createColumn($name, DataType::MEDIUMBLOB); + return $this->columns[$name]; + } + + /** + * 普通索引 + * @param string|null $name 索引名称(不需要名称也可以传null) + * @param string|array $columns 索引字段(多个字段可以传入数组) + * @return mixed + */ + function indexNormal(string $name, $columns): Index + { + $this->indexes[$name] = $this->createIndex($name, IndexType::NORMAL, $columns); + return $this->indexes[$name]; + } + + /** + * 创建一个索引对象 + * 继承可以改变返回的类对象以使用自定义对象 + * @param string|null $indexName + * @param $indexType + * @param $indexColumns + * @return Index + */ + protected function createIndex(?string $indexName, $indexType, $indexColumns) + { + return new Index($indexName, $indexType, $indexColumns); + } + + /** + * 唯一索引 + * 请注意这属于约束的一种类型 不要和字段上的约束重复定义 + * @param string|null $name 索引名称(不需要名称也可以传null) + * @param string|array $columns 索引字段(多个字段可以传入数组) + * @return mixed + */ + function indexUnique(string $name, $columns): Index + { + $this->indexes[$name] = $this->createIndex($name, IndexType::UNIQUE, $columns); + return $this->indexes[$name]; + } + + // 以下为表本身属性的设置方法 + + /** + * 主键索引 + * 请注意这属于约束的一种类型 不要和字段上的约束重复定义 + * @param string|null $name 索引名称(不需要名称也可以传null) + * @param string|array $columns 索引字段(多个字段可以传入数组) + * @return mixed + */ + function indexPrimary(string $name, $columns): Index + { + $this->indexes[$name] = $this->createIndex($name, IndexType::PRIMARY, $columns); + return $this->indexes[$name]; + } + + /** + * 全文索引 + * 请注意该类型的索引只能施加在TEXT类型的字段上 + * @param string|null $name 索引名称(不需要名称也可以传null) + * @param string|array $columns 索引字段(多个字段可以传入数组) + * @return mixed + */ + function indexFullText(string $name, $columns): Index + { + $this->indexes[$name] = $this->createIndex($name, IndexType::FULLTEXT, $columns); + return $this->indexes[$name]; + } + + /** + * 这是一个临时表 + * @param bool $enable + * @return Table + */ + function setIsTemporary($enable = true): Table + { + $this->isTemporary = $enable; + return $this; + } + + /** + * CREATE IF NOT EXISTS + * @param bool $enable + * @return Table + */ + function setIfNotExists($enable = true): Table + { + $this->ifNotExists = $enable; + return $this; + } + + /** + * 设置表名称 + * @param string $name + * @return Table + */ + function setTableName(string $name): Table + { + $name = trim($name); + if (empty($name)) { + throw new \InvalidArgumentException('The table name cannot be empty'); + } + $this->table = $name; + return $this; + } + + /** + * 设置储存引擎 + * @param string $engine + * @return Table + */ + function setTableEngine(string $engine): Table + { + $engine = trim($engine); + if (!Engines::isValidValue($engine)) { + throw new \InvalidArgumentException('The engine ' . $engine . ' is invalid'); + } + $this->engine = $engine; + return $this; + } + + /** + * 设置表注释 + * @param string $comment + * @return Table + */ + function setTableComment(string $comment): Table + { + $this->comment = $comment; + return $this; + } + + /** + * 设置表字符集 + * @param string $charset + * @return Table + */ + function setTableCharset(string $charset): Table + { + $charset = trim($charset); + if (!Character::isValidValue($charset)) { + throw new \InvalidArgumentException('The character ' . $charset . ' is invalid'); + } + $this->charset = $charset; + return $this; + } + + // 生成表结构 带有下划线的方法请不要自行调用 + + /** + * 设置起始自增值 + * @param int $startIncrement + */ + function setTableAutoIncrement(int $startIncrement) + { + $this->autoIncrement = $startIncrement; + + } + + function __getCols() + { + // 表格字段定义 + $columnDefinitions = []; + foreach ($this->columns as $name => $column) { + $columnDefinitions[$name] = ' ' . (string)$column; + } + return $columnDefinitions; + } + + /** + * 转化为字符串 + * @return string + */ + function __toString() + { + return $this->__createDDL(); + } + + function __createDDL() + { + // 表名称定义 + $tableName = "`{$this->table}`"; // 安全起见引号包裹 + + // 表格字段定义 + $columnDefinitions = []; + foreach ($this->columns as $name => $column) { + $columnDefinitions[] = ' ' . (string)$column; + } + + // 表格索引定义 + $indexDefinitions = []; + foreach ($this->indexes as $name => $index) { + $indexDefinitions[] = ' ' . (string)$index; + } + // 表格属性定义 + $tableOptions = array_filter( + [ + $this->engine ? 'ENGINE = ' . strtoupper($this->engine) : null, + $this->charset ? "DEFAULT COLLATE = '" . $this->charset . "'" : null, + $this->comment ? "COMMENT = '" . addslashes($this->comment) . "'" : null + ] + ); + $ifNotExists = $this->ifNotExists ? 'IF NOT EXISTS ' : ''; + // 构建表格DDL + $createDDL = implode( + "\n", + array_filter( + [ + "CREATE TABLE {$ifNotExists}{$tableName} (", + implode(",\n", + array_merge( + $columnDefinitions, + $indexDefinitions + ) + ), + ')', + implode(" ", $tableOptions), + ] + ) + ) . ';'; + + return $createDDL; + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Contracts/FilterInterface.php b/extend/mysql_dll/easyswoole/ddl/src/Contracts/FilterInterface.php new file mode 100644 index 0000000..cd2d8de --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Contracts/FilterInterface.php @@ -0,0 +1,17 @@ +__createDDL(); + } + + static function cols(callable $callable) + { + $blueprint = new Table(""); + $callable($blueprint); + return $blueprint->__getCols(); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Enum/Character.php b/extend/mysql_dll/easyswoole/ddl/src/Enum/Character.php new file mode 100644 index 0000000..a06b3d4 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Enum/Character.php @@ -0,0 +1,236 @@ +definition = $definition; + } + + /** + * Definition Getter + * @return mixed + */ + public function getDefinition() + { + return $this->definition; + } + + /** + * Definition Setter + * @param mixed $definition + */ + public function setDefinition($definition): void + { + $this->definition = $definition; + } + + /** + * 转为字符串 + * @return string + */ + function __toString() + { + return (string)$this->definition; + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Enum/Index.php b/extend/mysql_dll/easyswoole/ddl/src/Enum/Index.php new file mode 100644 index 0000000..5e87f21 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Enum/Index.php @@ -0,0 +1,18 @@ +getColumnType()), 'run'], $column); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterUnsigned.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterUnsigned.php new file mode 100644 index 0000000..9098f50 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterUnsigned.php @@ -0,0 +1,21 @@ +getColumnType()), 'run'], $column); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterZerofill.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterZerofill.php new file mode 100644 index 0000000..a73fe70 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/FilterZerofill.php @@ -0,0 +1,21 @@ +getColumnType()), 'run'], $column); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBigint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBigint.php new file mode 100644 index 0000000..6708f7f --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBigint.php @@ -0,0 +1,41 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type bigint(limit), limit must be range 1 to 255'); + } + } + + public static function limit(Column $column) + { + if ($column->getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type bigint(limit), limit must be range 1 to 255'); + } + } + + public static function unsigned(Column $column) + { + + } + + public static function zerofill(Column $column) + { + + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBlob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBlob.php new file mode 100644 index 0000000..5fa028b --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterBlob.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type blob no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterChar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterChar.php new file mode 100644 index 0000000..c1d20e2 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterChar.php @@ -0,0 +1,24 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type char(limit), limit must be range 1 to 255'); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDate.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDate.php new file mode 100644 index 0000000..235d33a --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDate.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type date no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDatetime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDatetime.php new file mode 100644 index 0000000..842b4a3 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDatetime.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 6) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type datetime(fsp), fsp must be range 0 to 6'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDecimal.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDecimal.php new file mode 100644 index 0000000..cc46cc2 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDecimal.php @@ -0,0 +1,27 @@ +getColumnLimit())) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type decimal(M,D), params is error'); + } + list($precision, $digits) = $column->getColumnLimit(); + if (is_numeric($precision) && is_numeric($digits) && ($digits > $precision)) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type decimal(M,D), M must be >= D'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDouble.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDouble.php new file mode 100644 index 0000000..064b32c --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterDouble.php @@ -0,0 +1,29 @@ +getColumnLimit())) { + list($precision, $digits) = $column->getColumnLimit(); + if (is_numeric($precision) && is_numeric($digits) && ($digits > $precision)) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type double(M,D), M must be >= D'); + } + } elseif ($column->getColumnLimit() < 0) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type double(M), M must be >= 0'); + } + + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterFloat.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterFloat.php new file mode 100644 index 0000000..ad83742 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterFloat.php @@ -0,0 +1,28 @@ +getColumnLimit())) { + list($precision, $digits) = $column->getColumnLimit(); + if (is_numeric($precision) && is_numeric($digits) && ($digits > $precision)) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type double(M,D), M must be >= D'); + } + } elseif ($column->getColumnLimit() < 0) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type double(M), M must be >= 0'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterInt.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterInt.php new file mode 100644 index 0000000..baa5635 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterInt.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type int(limit), limit must be range 1 to 255'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongblob.php new file mode 100644 index 0000000..2b59756 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongblob.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longblob no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongtext.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongtext.php new file mode 100644 index 0000000..b587f3e --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterLongtext.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longtext no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumblob.php new file mode 100644 index 0000000..4fb1dc3 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumblob.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumblob no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumint.php new file mode 100644 index 0000000..2ffae5e --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumint.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumint(limit), limit must be range 1 to 255'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumtext.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumtext.php new file mode 100644 index 0000000..c27d222 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterMediumtext.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumtext no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterSmallint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterSmallint.php new file mode 100644 index 0000000..7801881 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterSmallint.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type smallint(limit), limit must be range 1 to 255'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterText.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterText.php new file mode 100644 index 0000000..e09ffc6 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterText.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type text no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTime.php new file mode 100644 index 0000000..cdf6b8d --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTime.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 6) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type time(fsp), fsp must be range 0 to 6'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTimestamp.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTimestamp.php new file mode 100644 index 0000000..e008058 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTimestamp.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 6) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type timestamp(fsp), fsp must be range 0 to 6'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyblob.php new file mode 100644 index 0000000..616a554 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyblob.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinyblob no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyint.php new file mode 100644 index 0000000..c5c12b7 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinyint.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 255) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinyint(limit), limit must be range 1 to 255'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinytext.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinytext.php new file mode 100644 index 0000000..a5fb654 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterTinytext.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinytext no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterVarchar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterVarchar.php new file mode 100644 index 0000000..7f6cd37 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterVarchar.php @@ -0,0 +1,23 @@ +getColumnLimit() < 0 || $column->getColumnLimit() > 65535) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type varchar(limit), limit must be range 1 to 255'); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterYear.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterYear.php new file mode 100644 index 0000000..afc3b6f --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Limit/FilterYear.php @@ -0,0 +1,23 @@ +getColumnLimit()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type year no require fsp '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterBigint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterBigint.php new file mode 100644 index 0000000..7c1dedb --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterBigint.php @@ -0,0 +1,21 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type blob no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterChar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterChar.php new file mode 100644 index 0000000..9934100 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterChar.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type blob no require unsigned '); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDate.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDate.php new file mode 100644 index 0000000..6cc5354 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDate.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type date no require unsigned '); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDatetime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDatetime.php new file mode 100644 index 0000000..3dfffb3 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDatetime.php @@ -0,0 +1,23 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type datetime no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDecimal.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDecimal.php new file mode 100644 index 0000000..cb4fdc2 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterDecimal.php @@ -0,0 +1,21 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longblob no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterLongtext.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterLongtext.php new file mode 100644 index 0000000..b2a2404 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterLongtext.php @@ -0,0 +1,23 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longtext no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumblob.php new file mode 100644 index 0000000..5f1273c --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumblob.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumblob no require unsigned '); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumint.php new file mode 100644 index 0000000..a24adf2 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterMediumint.php @@ -0,0 +1,21 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumtext no require unsigned '); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterSmallint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterSmallint.php new file mode 100644 index 0000000..da3c5ae --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterSmallint.php @@ -0,0 +1,22 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type text no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTime.php new file mode 100644 index 0000000..4810dea --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTime.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type time no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTimestamp.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTimestamp.php new file mode 100644 index 0000000..d489041 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTimestamp.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type timestamp no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyblob.php new file mode 100644 index 0000000..41d0975 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyblob.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinyblob no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyint.php new file mode 100644 index 0000000..7698aeb --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterTinyint.php @@ -0,0 +1,23 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinytext no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterVarchar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterVarchar.php new file mode 100644 index 0000000..34b7a55 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterVarchar.php @@ -0,0 +1,24 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type varchar no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterYear.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterYear.php new file mode 100644 index 0000000..1a69eed --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Unsigned/FilterYear.php @@ -0,0 +1,23 @@ +getUnsigned()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type year no require unsigned '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterBigint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterBigint.php new file mode 100644 index 0000000..67840fc --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterBigint.php @@ -0,0 +1,21 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type blob no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterChar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterChar.php new file mode 100644 index 0000000..bf41cc6 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterChar.php @@ -0,0 +1,24 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type char no require zerofill '); + } + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDate.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDate.php new file mode 100644 index 0000000..a7e12b9 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDate.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type date no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDatetime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDatetime.php new file mode 100644 index 0000000..7b565ff --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDatetime.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type datetime no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDecimal.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDecimal.php new file mode 100644 index 0000000..76822a4 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterDecimal.php @@ -0,0 +1,21 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longblob no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterLongtext.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterLongtext.php new file mode 100644 index 0000000..c1300ce --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterLongtext.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type longtext no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumblob.php new file mode 100644 index 0000000..385189c --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumblob.php @@ -0,0 +1,24 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumblob no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumint.php new file mode 100644 index 0000000..9c4753a --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterMediumint.php @@ -0,0 +1,21 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type mediumtext no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterSmallint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterSmallint.php new file mode 100644 index 0000000..c99b8a1 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterSmallint.php @@ -0,0 +1,21 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type text no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTime.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTime.php new file mode 100644 index 0000000..bd71ec8 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTime.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type time no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTimestamp.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTimestamp.php new file mode 100644 index 0000000..6095b45 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTimestamp.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type timestamp no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyblob.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyblob.php new file mode 100644 index 0000000..0aa7130 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyblob.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinyblob no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyint.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyint.php new file mode 100644 index 0000000..dd3d0ae --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterTinyint.php @@ -0,0 +1,21 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type tinytext no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterVarchar.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterVarchar.php new file mode 100644 index 0000000..b2e97c8 --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterVarchar.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type varchar no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterYear.php b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterYear.php new file mode 100644 index 0000000..6ae7e2f --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/src/Filter/Zerofill/FilterYear.php @@ -0,0 +1,23 @@ +getZeroFill()) { + throw new \InvalidArgumentException('col ' . $column->getColumnName() . ' type year no require zerofill '); + } + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/ddl/test/create.php b/extend/mysql_dll/easyswoole/ddl/test/create.php new file mode 100644 index 0000000..1ac15de --- /dev/null +++ b/extend/mysql_dll/easyswoole/ddl/test/create.php @@ -0,0 +1,85 @@ +setIfNotExists()->setTableComment('学生表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('stu_id')->setIsAutoIncrement()->setIsPrimaryKey()->setIsUnsigned()->setColumnComment('学生ID'); //创建stu_id设置主键并自动增长 + $table->colVarChar('stu_name', 30)->setColumnComment('学生姓名'); + $table->colChar('sex', 1)->setColumnComment('性别:1男,2女')->setDefaultValue(1); + $table->colDate('birthday')->setIsNotNull(false)->setColumnComment('出生日期'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); + $table->colInt('updated_at', 10)->setColumnComment('更新时间'); + $table->indexNormal('stu_name_index', 'stu_name')->setIndexComment('学生姓名--普通索引');//设置索引 +}); +echo $stuQql . "\r\n"; + +$courseSql = DDLBuilder::table('course', function (Table $table) { + $table->setIfNotExists()->setTableComment('课程表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('id', 3)->setIsPrimaryKey()->setIsAutoIncrement()->setIsUnsigned()->setZeroFill()->setColumnComment('课程id'); + $table->colVarChar('course_name', 100)->setColumnComment('课程名称'); + $table->colChar('status', 1)->setDefaultValue(1)->setColumnComment('课程状态:1正常,0隐藏'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); + $table->colInt('updated_at', 10)->setColumnComment('更新时间'); + $table->indexUnique('course_name_index', 'course_name')->setIndexComment('课程名称--唯一索引');//设置索引 +}); +echo $courseSql . "\r\n"; + +$scoreSql = DDLBuilder::table('score', function (Table $table) { + $table->setIfNotExists()->setTableComment('成绩表'); //设置表名称/ + $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);//设置表字符集 + $table->colInt('id')->setIsUnsigned()->setIsAutoIncrement()->setIsPrimaryKey()->setColumnComment('自增ID'); + $table->colInt('stu_id')->setIsUnsigned()->setColumnComment('学生id'); + $table->colInt('course_id')->setIsUnsigned()->setZeroFill()->setColumnComment('课程id'); + $table->colFloat('score', 3, 1)->setColumnComment('成绩'); + $table->colInt('created_at', 10)->setColumnComment('创建时间'); +}); +echo $scoreSql; +//以下是输出sql语句 +/* +CREATE TABLE IF NOT EXISTS `student` ( + `stu_id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '学生ID', + `stu_name` varchar(30) NOT NULL COMMENT '学生姓名', + `sex` char(1) NOT NULL DEFAULT 1 COMMENT '性别:1男,2女', + `birthday` date NOT NULL COMMENT '出生日期', + `created_at` int(10) NOT NULL COMMENT '创建时间', + `updated_at` int(10) NOT NULL COMMENT '更新时间', + INDEX `stu_name_index` (`stu_name`) COMMENT '学生姓名--普通索引' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '学生表'; + +CREATE TABLE IF NOT EXISTS `course` ( + `id` int(3) UNSIGNED ZEROFILL NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '课程id', + `course_name` varchar(100) NOT NULL COMMENT '课程名称', + `status` char(1) NOT NULL DEFAULT 1 COMMENT '课程状态:1正常,0隐藏', + `created_at` int(10) NOT NULL COMMENT '创建时间', + `updated_at` int(10) NOT NULL COMMENT '更新时间', + UNIQUE INDEX `course_name_index` (`course_name`) COMMENT '课程名称--唯一索引' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '课程表'; + +CREATE TABLE IF NOT EXISTS `score` ( + `id` int UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID', + `stu_id` int UNSIGNED NOT NULL COMMENT '学生id', + `course_id` int UNSIGNED ZEROFILL NOT NULL COMMENT '课程id', + `score` float(3,1) NOT NULL COMMENT '成绩', + `created_at` int(10) NOT NULL COMMENT '创建时间' +) +ENGINE = INNODB DEFAULT COLLATE = 'utf8mb4_general_ci' COMMENT = '成绩表'; + +*/ diff --git a/extend/mysql_dll/easyswoole/spl/LICENSE b/extend/mysql_dll/easyswoole/spl/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/extend/mysql_dll/easyswoole/spl/README.md b/extend/mysql_dll/easyswoole/spl/README.md new file mode 100644 index 0000000..2fd2fc7 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/README.md @@ -0,0 +1 @@ +# spl \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/composer.json b/extend/mysql_dll/easyswoole/spl/composer.json new file mode 100644 index 0000000..464c830 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/composer.json @@ -0,0 +1,27 @@ +{ + "name": "easyswoole/spl", + "type": "library", + "description": "php stander lib", + "keywords" : ["swoole", "framework", "async","easyswoole"], + "homepage" : "https://www.easyswoole.com/", + "license" : "Apache-2.0", + "authors": [ + { + "name": "YF", + "email": "291323003@qq.com" + } + ], + "require": { + "php": ">=7.1.0", + "ext-json": "*" + }, + "require-dev": { + "easyswoole/phpunit": "^1.0" + }, + "autoload": { + "psr-4": { + "EasySwoole\\Spl\\": "src/", + "EasySwoole\\Spl\\Test\\": "test/" + } + } +} diff --git a/extend/mysql_dll/easyswoole/spl/src/Exception/Exception.php b/extend/mysql_dll/easyswoole/spl/src/Exception/Exception.php new file mode 100644 index 0000000..a338a1d --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/Exception/Exception.php @@ -0,0 +1,15 @@ + 1 && $key = array_shift($path)) { + $temp = &$temp[$key]; + } + $finalKey = array_shift($path); + if (isset($temp[$finalKey])) { + unset($temp[$finalKey]); + } + } + + function get($path) + { + $paths = explode(".", $path); + $data = $this->getArrayCopy(); + while ($key = array_shift($paths)) { + if (isset($data[$key])) { + $data = $data[$key]; + } else { + if ($key == '*') { + $temp = []; + if (is_array($data)) { + if (!empty($paths)) { + $path = implode("/", $paths); + } else { + $path = null; + } + foreach ($data as $key => $datum) { + if (is_array($datum)) { + $ctemp = (new SplArray($datum))->get($path); + if ($ctemp !== null) { + $temp[][$path] = $ctemp; + } + } else if ($datum !== null) { + $temp[$key] = $datum; + } + + } + } + return $temp; + } else { + return null; + } + } + } + return $data; + } + + public function delete($key): void + { + $this->unset($key); + } + + /** + * 数组去重取唯一的值 + * @return SplArray + */ + public function unique(): SplArray + { + return new SplArray(array_unique($this->getArrayCopy(), SORT_REGULAR)); + } + + /** + * 获取数组中重复的值 + * @return SplArray + */ + public function multiple(): SplArray + { + $unique_arr = array_unique($this->getArrayCopy(), SORT_REGULAR); + return new SplArray(array_udiff_uassoc($this->getArrayCopy(), $unique_arr, function ($key1, $key2) { + if ($key1 === $key2) { + return 0; + } + return 1; + }, function ($value1, $value2) { + if ($value1 === $value2) { + return 0; + } + return 1; + })); + } + + /** + * 按照键值升序 + * @return SplArray + */ + public function asort(): SplArray + { + parent::asort(); + return $this; + } + + /** + * 按照键升序 + * @return SplArray + */ + public function ksort(): SplArray + { + parent::ksort(); + return $this; + } + + /** + * 自定义排序 + * @param int $sort_flags + * @return SplArray + */ + public function sort($sort_flags = SORT_REGULAR): SplArray + { + $temp = $this->getArrayCopy(); + sort($temp, $sort_flags); + return new SplArray($temp); + } + + /** + * 取得某一列 + * @param string $column + * @param null|string $index_key + * @return SplArray + */ + public function column($column, $index_key = null): SplArray + { + return new SplArray(array_column($this->getArrayCopy(), $column, $index_key)); + } + + /** + * 交换数组中的键和值 + * @return SplArray + */ + public function flip(): SplArray + { + return new SplArray(array_flip($this->getArrayCopy())); + } + + /** + * 过滤本数组 + * @param string|array $keys 需要取得/排除的键 + * @param bool $exclude true则排除设置的键名 false则仅获取设置的键名 + * @return SplArray + */ + public function filter($keys, $exclude = false): SplArray + { + if (is_string($keys)) { + $keys = explode(',', $keys); + } + $new = array(); + foreach ($this->getArrayCopy() as $name => $value) { + if (!$exclude) { + in_array($name, $keys) ? $new[$name] = $value : null; + } else { + in_array($name, $keys) ? null : $new[$name] = $value; + } + } + return new SplArray($new); + } + + + public function keys($path = null): array + { + if (!empty($path)) { + $temp = $this->get($path); + if (is_array($temp)) { + return array_keys($temp); + } else { + return []; + } + } + return array_keys((array)$this); + } + + /** + * 提取数组中的值 + * @return SplArray + */ + public function values(): SplArray + { + return new SplArray(array_values($this->getArrayCopy())); + } + + public function flush(): SplArray + { + foreach ($this->getArrayCopy() as $key => $item) { + unset($this[$key]); + } + return $this; + } + + public function loadArray(array $data) + { + parent::__construct($data); + return $this; + } + + function merge(array $data) + { + return $this->loadArray($data + $this->getArrayCopy()); + } + + /* + $test = new \EasySwoole\Spl\SplArray([ + 'title'=>'title', + 'items'=>[ + ['title'=>'Some string', 'number' => 1], + ['title'=>'Some string', 'number' => 2], + ['title'=>'Some string', 'number' => 3] + ] + ]); + */ + public function toXML($CD_DATA = false, $rootName = 'xml', $encoding = 'UTF-8') + { + $data = $this->getArrayCopy(); + if ($CD_DATA) { + /* + * 默认制定 + */ + $xml = new class('' . "<{$rootName}>") extends \SimpleXMLElement + { + public function addCData($cdata_text) + { + $dom = dom_import_simplexml($this); + $cdata = $dom->ownerDocument->createCDATASection($cdata_text); + $dom->appendChild($cdata); + } + }; + } else { + $xml = new \SimpleXMLElement('' . "<{$rootName} >"); + } + $parser = function ($xml, $data) use (&$parser, $CD_DATA) { + foreach ($data as $k => $v) { + if (is_array($v)) { + if (!is_numeric($k)) { + $ch = $xml->addChild($k); + } else { + $ch = $xml->addChild(substr($xml->getName(), 0, -1)); + } + $parser($ch, $v); + } else { + if (is_numeric($k)) { + $xml->addChild($k, $v); + } else { + if ($CD_DATA) { + $n = $xml->addChild($k); + $n->addCData($v); + } else { + $xml->addChild($k, $v); + } + } + } + } + }; + $parser($xml, $data); + unset($parser); + $str = $xml->asXML(); + return substr($str, strpos($str, "\n") + 1); + } + +} diff --git a/extend/mysql_dll/easyswoole/spl/src/SplBean.php b/extend/mysql_dll/easyswoole/spl/src/SplBean.php new file mode 100644 index 0000000..9353aca --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplBean.php @@ -0,0 +1,282 @@ +arrayToBean($data, $autoCreateProperty); + } + $this->initialize(); + $this->classMap(); + } + + final public function allProperty(): array + { + $data = []; + $class = new \ReflectionClass($this); + $protectedAndPublic = $class->getProperties( + \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED + ); + foreach ($protectedAndPublic as $item) { + if ($item->isStatic()) { + continue; + } + array_push($data, $item->getName()); + } + $data = array_flip($data); + unset($data['_keyMap']); + unset($data['_classMap']); + return array_flip($data); + } + + function toArray(array $columns = null, $filter = null): array + { + $data = $this->jsonSerialize(); + if ($columns) { + $data = array_intersect_key($data, array_flip($columns)); + } + if ($filter === self::FILTER_NOT_NULL) { + return array_filter($data, function ($val) { + return !is_null($val); + }); + } else if ($filter === self::FILTER_NOT_EMPTY) { + return array_filter($data, function ($val) { + return !empty($val); + }); + } else if ($filter === self::FILTER_NULL) { + return array_filter($data, function ($val) { + return is_null($val); + }); + } else if ($filter === self::FILTER_EMPTY) { + return array_filter($data, function ($val) { + return empty($val); + }); + } else if (is_callable($filter)) { + return array_filter($data, $filter); + } + return $data; + } + + /* + * 返回转化后的array + */ + function toArrayWithMapping(array $columns = null, $filter = null) + { + $array = $this->toArray(); + $array = $this->beanKeyMap($array); + + if ($columns) { + $array = array_intersect_key($array, array_flip($columns)); + } + if ($filter === self::FILTER_NOT_NULL) { + return array_filter($array, function ($val) { + return !is_null($val); + }); + } else if ($filter === self::FILTER_NOT_EMPTY) { + return array_filter($array, function ($val) { + if ($val === 0 || $val === '0') { + return true; + } else { + return !empty($val); + } + }); + } else if (is_callable($filter)) { + return array_filter($array, $filter); + } + return $array; + } + + final private function arrayToBean(array $data, $autoCreateProperty = false): SplBean + { + + $data = $this->dataKeyMap($data); + + if ($autoCreateProperty == false) { + $data = array_intersect_key($data, array_flip($this->allProperty())); + } + foreach ($data as $key => $item) { + $this->addProperty($key, $item); + } + return $this; + } + + final public function addProperty($name, $value = null): void + { + $this->$name = $value; + } + + final public function getProperty($name) + { + if (isset($this->$name)) { + return $this->$name; + } else { + return null; + } + } + + final public function jsonSerialize(): array + { + $data = []; + foreach ($this as $key => $item) { + $data[$key] = $item; + } + unset($data['_keyMap']); + unset($data['_classMap']); + return $data; + } + + public function __toString() + { + return json_encode($this->jsonSerialize(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + } + + /* + * 在子类中重写该方法,可以在类初始化的时候进行一些操作 + */ + protected function initialize(): void + { + + } + + /* + * 如果需要用到keyMap 请在子类重构并返回对应的map数据 + * return ['beanKey'=>'dataKey'] + * return ['实际的键名'=>'传人的键名'] + */ + protected function setKeyMapping(): array + { + return []; + } + + /* + * return ['property'=>class string] + */ + protected function setClassMapping(): array + { + return []; + } + + /* + * 恢复到属性定义的默认值 + */ + public function restore(array $data = [], $autoCreateProperty = false) + { + $this->clear(); + $this->arrayToBean($data + get_class_vars(static::class), $autoCreateProperty); + $this->initialize(); + $this->classMap(); + return $this; + } + + private function clear() + { + $keys = $this->allProperty(); + $ref = new \ReflectionClass(static::class); + $fields = array_keys($ref->getDefaultProperties()); + $fields = array_merge($fields, array_values($this->setKeyMapping())); + // 多余的key + $extra = array_diff($keys, $fields); + + foreach ($extra as $key => $value) { + unset($this->$value); + } + } + + private function classMap() + { + $propertyList = $this->allProperty(); + foreach ($this->setClassMapping() as $property => $class) { + if (in_array($property, $propertyList)) { + $val = $this->$property; + $force = true; + if (strpos($class, '@') !== false) { + $force = false; + $class = substr($class, 1); + } + if (is_object($val)) { + if (!$val instanceof $class) { + throw new Exception("value for property:{$property} dot not match in " . (static::class)); + } + } else if ($val === null) { + if ($force) { + $this->$property = $this->createClass($class); + } + } else { + $this->$property = $this->createClass($class, $val); + } + } else { + throw new Exception("property:{$property} not exist in " . (static::class)); + } + } + } + + /** + * @param string $class + * @param null $arg + * @return object + * @throws \ReflectionException + */ + private function createClass(string $class, $arg = null) + { + $ref = new \ReflectionClass($class); + return $ref->newInstance($arg); + } + + /** + * beanKeyMap + * 将Bean的属性名转化为data数据键名 + * + * @param array $array + * @return array + */ + final private function beanKeyMap(array $array): array + { + foreach ($this->setKeyMapping() as $dataKey => $beanKey) { + if (array_key_exists($beanKey, $array)) { + $array[$dataKey] = $array[$beanKey]; + unset($array[$beanKey]); + } + } + return $array; + } + + /** + * dataKeyMap + * 将data中的键名 转化为Bean的属性名 + * + * @param array $array + * @return array + */ + final private function dataKeyMap(array $array): array + { + foreach ($this->setKeyMapping() as $dataKey => $beanKey) { + if (array_key_exists($dataKey, $array)) { + $array[$beanKey] = $array[$dataKey]; + unset($array[$dataKey]); + } + } + return $array; + } +} diff --git a/extend/mysql_dll/easyswoole/spl/src/SplDoubleLink.php b/extend/mysql_dll/easyswoole/spl/src/SplDoubleLink.php new file mode 100644 index 0000000..a55a33a --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplDoubleLink.php @@ -0,0 +1,56 @@ +next; + } + + function hashPre():bool + { + return (bool)$this->pre; + } + + function next(...$arg):SplDoubleLink + { + if(!$this->next){ + $this->next = $this->newInstance(...$arg); + } + return $this->next; + } + + function pre(...$arg):SplDoubleLink + { + if(!$this->pre){ + $this->pre = $this->newInstance(...$arg); + } + return $this->pre; + } + + function delPre() + { + $this->pre = null; + return $this; + } + + function delNext() + { + $this->next = null; + return $this; + } + + private function newInstance(...$arg):SplDoubleLink + { + $ref = new \ReflectionClass(static::class); + return $ref->newInstanceArgs($arg); + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/src/SplEnum.php b/extend/mysql_dll/easyswoole/spl/src/SplEnum.php new file mode 100644 index 0000000..41fe459 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplEnum.php @@ -0,0 +1,77 @@ +val = $val; + $this->name = self::isValidValue($val); + if($this->name === false){ + throw new \Exception("invalid value"); + } + } + + final public function getName():string + { + return $this->name; + } + + final public function getValue() + { + return $this->val; + } + + final public static function isValidName(string $name):bool + { + $list = self::getConstants(); + if(isset($list[$name])){ + return true; + }else{ + return false; + } + } + + final public static function isValidValue($val) + { + $list = self::getConstants(); + return array_search($val,$list); + } + + final public static function getEnumList():array + { + return self::getConstants(); + } + + private final static function getConstants():array + { + try{ + return (new \ReflectionClass(static::class))->getConstants(); + }catch (\Throwable $throwable){ + return []; + } + } + + function __toString() + { + // TODO: Implement __toString() method. + return (string)$this->getName(); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/src/SplFileStream.php b/extend/mysql_dll/easyswoole/spl/src/SplFileStream.php new file mode 100644 index 0000000..85cd958 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplFileStream.php @@ -0,0 +1,27 @@ +getStreamResource(),$mode); + } + + function unlock($mode = LOCK_UN){ + return flock($this->getStreamResource(),$mode); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/src/SplStream.php b/extend/mysql_dll/easyswoole/spl/src/SplStream.php new file mode 100644 index 0000000..959439d --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplStream.php @@ -0,0 +1,231 @@ + true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, + 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, + 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, + 'x+t' => true, 'c+t' => true, 'a+' => true + ]; + private $writeList = [ + 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, + 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, + 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, + 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true + ]; + function __construct($resource = '',$mode = 'r+') + { + switch (gettype($resource)) { + case 'resource': { + $this->stream = $resource; + break; + } + case 'object':{ + if(method_exists($resource, '__toString')) { + $resource = $resource->__toString(); + $this->stream = fopen('php://memory', $mode); + if ($resource !== '') { + fwrite($this->stream, $resource); + } + break; + }else{ + throw new \InvalidArgumentException('Invalid resource type: ' . gettype($resource)); + } + } + default:{ + $this->stream = fopen('php://memory', $mode); + try{ + $resource = (string)$resource; + if ($resource !== '') { + fwrite($this->stream, $resource); + } + }catch (\Exception $exception){ + throw new \InvalidArgumentException('Invalid resource type: ' . gettype($resource)); + } + } + } + $info = stream_get_meta_data($this->stream); + $this->seekable = $info['seekable']; + $this->seek(0); + $this->readable = isset($this->readList[$info['mode']]); + $this->writable = isset($this->writeList[$info['mode']]); + } + + public function __toString() + { + // TODO: Implement __toString() method. + try { + $this->seek(0); + return (string) stream_get_contents($this->stream); + } catch (\Exception $e) { + return ''; + } + } + + public function close() + { + // TODO: Implement close() method. + $res = $this->detach(); + if(is_resource($res)){ + fclose($res); + } + } + + public function detach() + { + // TODO: Implement detach() method. + if (!isset($this->stream)) { + return null; + } + $this->readable = $this->writable = $this->seekable = false; + $result = $this->stream; + unset($this->stream); + return $result; + } + + public function getSize() + { + // TODO: Implement getSize() method. + $stats = fstat($this->stream); + if (isset($stats['size'])) { + return $stats['size']; + }else{ + return null; + } + } + + public function tell() + { + // TODO: Implement tell() method. + $result = ftell($this->stream); + if ($result === false) { + throw new \RuntimeException('Unable to determine stream position'); + } + return $result; + } + + public function eof() + { + // TODO: Implement eof() method. + return !$this->stream || feof($this->stream); + } + + public function isSeekable() + { + // TODO: Implement isSeekable() method. + return $this->seekable; + } + + public function seek($offset, $whence = SEEK_SET) + { + // TODO: Implement seek() method. + if (!$this->seekable) { + throw new \RuntimeException('Stream is not seekable'); + } elseif (fseek($this->stream, $offset, $whence) === -1) { + throw new \RuntimeException('Unable to seek to stream position ' + . $offset . ' with whence ' . var_export($whence, true)); + } + } + + public function rewind() + { + // TODO: Implement rewind() method. + $this->seek(0); + } + + public function isWritable() + { + // TODO: Implement isWritable() method. + return $this->writable; + } + + public function write($string) + { + // TODO: Implement write() method. + if (!$this->writable) { + throw new \RuntimeException('Cannot write to a non-writable stream'); + } + $result = fwrite($this->stream, $string); + if ($result === false) { + throw new \RuntimeException('Unable to write to stream'); + } + return $result; + } + + public function isReadable() + { + // TODO: Implement isReadable() method. + return $this->readable; + } + + public function read($length) + { + // TODO: Implement read() method. + if (!$this->readable) { + throw new \RuntimeException('Cannot read from non-readable stream'); + } + if ($length < 0) { + throw new \RuntimeException('Length parameter cannot be negative'); + } + if (0 === $length) { + return ''; + } + $string = fread($this->stream, $length); + if (false === $string) { + throw new \RuntimeException('Unable to read from stream'); + } + return $string; + } + + public function getContents() + { + // TODO: Implement getContents() method. + //注意与__toString的区别 + $contents = stream_get_contents($this->stream); + if ($contents === false) { + throw new \RuntimeException('Unable to read stream contents'); + } + return $contents; + } + + public function getMetadata($key = null) + { + // TODO: Implement getMetadata() method. + if (!isset($this->stream)) { + return $key ? null : []; + } elseif (!$key) { + return stream_get_meta_data($this->stream); + } else { + $meta = stream_get_meta_data($this->stream); + return isset($meta[$key]) ? $meta[$key] : null; + } + } + + public function __destruct() + { + // TODO: Implement __destruct() method. + $this->close(); + } + + function getStreamResource(){ + return $this->stream; + } + + function truncate($size = 0){ + return ftruncate($this->stream,$size); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/src/SplString.php b/extend/mysql_dll/easyswoole/spl/src/SplString.php new file mode 100644 index 0000000..6e2b022 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/SplString.php @@ -0,0 +1,356 @@ +__toString(), $length ) ); + } + + function explode( string $delimiter ) : SplArray + { + return new SplArray( explode( $delimiter, $this->__toString() ) ); + } + + function subString( int $start, int $length ) : SplString + { + return $this->setString( substr( $this->__toString(), $start, $length ) ); + } + + function encodingConvert( string $desEncoding, $detectList + = [ + 'UTF-8', + 'ASCII', + 'GBK', + 'GB2312', + 'LATIN1', + 'BIG5', + "UCS-2", + ] ) : SplString + { + $fileType = mb_detect_encoding( $this->__toString(), $detectList ); + if( $fileType != $desEncoding ){ + $this->setString( mb_convert_encoding( $this->__toString(), $desEncoding, $fileType ) ); + } + return $this; + } + + function utf8() : SplString + { + return $this->encodingConvert( "UTF-8" ); + } + + /* + * special function for unicode + */ + function unicodeToUtf8() : SplString + { + + $string = preg_replace_callback( '/\\\\u([0-9a-f]{4})/i', function( $matches ){ + return mb_convert_encoding( pack( "H*", $matches[1] ), "UTF-8", "UCS-2BE" ); + }, $this->__toString() ); + return $this->setString( $string ); + } + + function toUnicode() : SplString + { + $raw = (string)$this->encodingConvert( "UCS-2" ); + $len = strlen( $raw ); + $str = ''; + for( $i = 0 ; $i < $len - 1 ; $i = $i + 2 ){ + $c = $raw[$i]; + $c2 = $raw[$i + 1]; + if( ord( $c ) > 0 ){ //两个字节的文字 + $str .= '\u'.base_convert( ord( $c ), 10, 16 ).str_pad( base_convert( ord( $c2 ), 10, 16 ), 2, 0, STR_PAD_LEFT ); + } else{ + $str .= '\u'.str_pad( base_convert( ord( $c2 ), 10, 16 ), 4, 0, STR_PAD_LEFT ); + } + } + $string = strtoupper( $str );//转换为大写 + return $this->setString( $string ); + } + + function compare( string $str, int $ignoreCase = 0 ) : int + { + if( $ignoreCase ){ + return strcasecmp( $this->__toString(), $str ); + } else{ + return strcmp( $this->__toString(), $str ); + } + } + + function lTrim( string $charList = " \t\n\r\0\x0B" ) : SplString + { + return $this->setString( ltrim( $this->__toString(), $charList ) ); + } + + function rTrim( string $charList = " \t\n\r\0\x0B" ) : SplString + { + return $this->setString( rtrim( $this->__toString(), $charList ) ); + } + + function trim( string $charList = " \t\n\r\0\x0B" ) : SplString + { + return $this->setString( trim( $this->__toString(), $charList ) ); + } + + function pad( int $length, string $padString = null, int $pad_type = STR_PAD_RIGHT ) : SplString + { + return $this->setString( str_pad( $this->__toString(), $length, $padString, $pad_type ) ); + } + + function repeat( int $times ) : SplString + { + return $this->setString( str_repeat( $this->__toString(), $times ) ); + } + + function length() : int + { + return strlen( $this->__toString() ); + } + + function upper() : SplString + { + return $this->setString( strtoupper( $this->__toString() ) ); + } + + function lower() : SplString + { + return $this->setString( strtolower( $this->__toString() ) ); + } + + function stripTags( string $allowable_tags = null ) : SplString + { + return $this->setString( strip_tags( $this->__toString(), $allowable_tags ) ); + } + + function replace( string $find, string $replaceTo ) : SplString + { + return $this->setString( str_replace( $find, $replaceTo, $this->__toString() ) ); + } + + function between( string $startStr, string $endStr ) : SplString + { + $explode_arr = explode( $startStr, $this->__toString() ); + if( isset( $explode_arr[1] ) ){ + $explode_arr = explode( $endStr, $explode_arr[1] ); + return $this->setString( $explode_arr[0] ); + } else{ + return $this->setString( '' ); + } + } + + public function regex( $regex, bool $rawReturn = false ) + { + preg_match( $regex, $this->__toString(), $result ); + if( !empty( $result ) ){ + if( $rawReturn ){ + return $result; + } else{ + return $result[0]; + } + } else{ + return null; + } + } + + public function exist( string $find, bool $ignoreCase = true ) : bool + { + if( $ignoreCase ){ + $label = stripos( $this->__toString(), $find ); + } else{ + $label = strpos( $this->__toString(), $find ); + } + return $label === false ? false : true; + } + + /** + * 转换为烤串 + */ + function kebab() : SplString + { + return $this->snake( '-' ); + } + + /** + * 转为蛇的样子 + * @param string $delimiter + */ + function snake( string $delimiter = '_' ) : SplString + { + $string = $this->__toString(); + if( !ctype_lower( $string ) ){ + $string = preg_replace( '/\s+/u', '', ucwords( $this->__toString() ) ); + $string = $this->setString( preg_replace( '/(.)(?=[A-Z])/u', '$1'.$delimiter, $string ) ); + $this->setString( $string ); + $this->lower(); + } + return $this; + } + + + /** + * 转为大写的大写 + */ + function studly() : SplString + { + $value = ucwords( str_replace( ['-', '_'], ' ', $this->__toString() ) ); + return $this->setString( str_replace( ' ', '', $value ) ); + } + + /** + * 驼峰 + * + */ + function camel() : SplString + { + $this->studly(); + return $this->setString( lcfirst( $this->__toString() ) ); + } + + + /** + * 用数组逐个字符 + * @param string $search + * @param array $replace + */ + public function replaceArray( string $search, array $replace ) : SplString + { + foreach( $replace as $value ){ + $this->setString( $this->replaceFirst( $search, $value ) ); + } + return $this; + } + + /** + * 替换字符串中给定值的第一次出现。 + * @param string $search + * @param string $replace + */ + public function replaceFirst( string $search, string $replace ) : SplString + { + if( $search == '' ){ + return $this; + } + + $position = strpos( $this->__toString(), $search ); + + if( $position !== false ){ + return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) ); + } + + return $this; + } + + /** + * 替换字符串中给定值的最后一次出现。 + * @param string $search + * @param string $replace + */ + public function replaceLast( string $search, string $replace ) : SplString + { + $position = strrpos( $this->__toString(), $search ); + + if( $position !== false ){ + return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) ); + } + + return $this; + } + + /** + * 以一个给定值的单一实例开始一个字符串 + * + * @param string $prefix + */ + public function start( string $prefix ) : SplString + { + $quoted = preg_quote( $prefix, '/' ); + return $this->setString( $prefix.preg_replace( '/^(?:'.$quoted.')+/u', '', $this->__toString() ) ); + } + + /** + * 在给定的值之后返回字符串的其余部分。 + * + * @param string $search + */ + function after( string $search ) : SplString + { + if( $search === '' ){ + return $this; + } else{ + return $this->setString( array_reverse( explode( $search, $this->__toString(), 2 ) )[0] ); + } + } + + /** + * 在给定的值之前获取字符串的一部分 + * + * @param string $search + */ + function before( string $search ) : SplString + { + if( $search === '' ){ + return $this; + } else{ + return $this->setString( explode( $search, $this->__toString() )[0] ); + } + } + + /** + * 确定给定的字符串是否以给定的子字符串结束 + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ + public function endsWith( $needles ) : bool + { + foreach( (array)$needles as $needle ){ + if( substr( $this->__toString(), - strlen( $needle ) ) === (string)$needle ){ + return true; + } + } + return false; + } + + /** + * 确定给定的字符串是否从给定的子字符串开始 + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ + public function startsWith( $needles ) : bool + { + foreach( (array)$needles as $needle ){ + if( $needle !== '' && substr( $this->__toString(), 0, strlen( $needle ) ) === (string)$needle ){ + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/src/StrictArray.php b/extend/mysql_dll/easyswoole/spl/src/StrictArray.php new file mode 100644 index 0000000..195fb98 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/src/StrictArray.php @@ -0,0 +1,87 @@ +class = $itemClass; + } + + public function offsetExists($offset) + { + return isset($this->data[$offset]); + } + + public function offsetGet($offset) + { + if(isset($this->data[$offset])){ + return $this->data[$offset]; + }else{ + return null; + } + } + + public function offsetSet($offset, $value) + { + if(is_a($value,$this->class)){ + $this->data[$offset] = $value; + return true; + } + throw new \Exception("StrictArray can only set {$this->class} object"); + } + + public function offsetUnset($offset) + { + if(isset($this->data[$offset])){ + unset($this->data[$offset]); + return true; + }else{ + return false; + } + } + + public function count() + { + return count($this->data); + } + + public function current() + { + return $this->data[$this->currentKey]; + } + + public function next() + { + $this->currentKey = array_shift($this->keys); + } + + public function key() + { + if($this->currentKey === null){ + $this->rewind(); + } + return $this->currentKey; + } + + public function valid() + { + return isset($this->data[$this->currentKey]); + } + + public function rewind() + { + $this->currentKey = null; + $this->keys = []; + $this->keys = array_keys($this->data); + $this->currentKey = array_shift($this->keys); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/AllProperty74Test.php b/extend/mysql_dll/easyswoole/spl/test/AllProperty74Test.php new file mode 100644 index 0000000..933be4d --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/AllProperty74Test.php @@ -0,0 +1,33 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: 兼容php7.4约束类型单测 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\Test\Bean\TestAllProperty; +use EasySwoole\Spl\Test\Bean\TestAllProperty74; +use PHPUnit\Framework\TestCase; + +class AllProperty74Test extends TestCase +{ + function testGetAllProperty() + { + $allProperty = new TestAllProperty(); + $this->assertEquals( + [ + 'a', 'b', 'aInit', 'bInit' + ] + , $allProperty->allProperty()); + } + + function testGetAllProperty74() + { + $allProperty74 = new TestAllProperty74(); + $this->assertEquals([ + 'a', 'b', 'aInit', 'bInit', 'typeA', 'typeB', 'typeInitA', 'typeInitB' + ], $allProperty74->allProperty()); + } +} diff --git a/extend/mysql_dll/easyswoole/spl/test/ArrayTest.php b/extend/mysql_dll/easyswoole/spl/test/ArrayTest.php new file mode 100644 index 0000000..02aa676 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/ArrayTest.php @@ -0,0 +1,419 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplArray 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use PHPUnit\Framework\TestCase; + +use EasySwoole\Spl\SplArray; + +class ArrayTest extends TestCase { + + /** + * 设置参数 + * + * @return SplArray + * CreateTime: 2019/9/10 下午11:30 + */ + public function testSet() { + $data = [ + 'fruit' => [ + 'apple' => 2, + 'orange' => 1, + 'grape' => 4 + ], + 'color' => [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ] + ]; + $splArrayObj = new SplArray($data); + $splArrayObj->set('fruit.apple', 3); + $this->assertEquals(3, $splArrayObj->get('fruit.apple')); + return $splArrayObj; + } + + /** + * 获取参数 + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testGet( SplArray $splArrayObj) { + + // 测试第一层的key + $this->assertEquals( + [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ], + $splArrayObj->get('color') + ); + + // 测试第二层的key + $this->assertEquals( + 12, + $splArrayObj->get('color.red') + ); + } + + /** + * 转字符 + * + * @depends clone testSet + * CreateTime: 2019/9/10 下午11:29 + */ + public function testTostring(SplArray $splArrayObj) { + $this->assertJsonStringEqualsJsonString( + json_encode($splArrayObj, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), + $splArrayObj->__toString() + ); + } + + /** + * 数组的复制 + * + * @depends clone testSet + * @param SplArray $splArrayObj + * CreateTime: 2019/9/10 下午11:37 + */ + public function testGetArrayCopy(SplArray $splArrayObj) { + $this->assertEquals( + [ + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ], + 'color' => [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ] + ], + $splArrayObj->getArrayCopy() + ); + } + + /** + * 销毁数组元素 + * + * @depends clone testSet + * @param $splArrayObj SplArray + * CreateTime: 2019/9/10 下午11:44 + */ + public function testUnset(SplArray $splArrayObj) { + + // 销毁red元素 + $splArrayObj->unset('color.red'); + $this->assertEquals( + [ + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ], + 'color' => [ + 'blue' => 8, + 'green' => 6 + ] + ], + $splArrayObj->getArrayCopy() + ); + + // 销毁color元素 + $splArrayObj->unset('color'); + $this->assertEquals( + [ + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ] + ], + $splArrayObj->getArrayCopy() + ); + } + + /** + * 去除某个数据项(unset和delete方法其实是实现统一效果,因考虑旧版本用户使用情况,故而保留。) + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testDelete(SplArray $splArrayObj) { + $splArrayObj->delete('color'); + $this->assertEquals( + [ + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ] + ], + $splArrayObj->getArrayCopy() + ); + } + + /** + * 数组值唯一 + * + * CreateTime: 2019/9/10 下午11:55 + * @param SplArray $splArrayObj + * @return bool + */ + public function testUnique() { + $splArrayObj = new SplArray( + [ + 'name1' => 'es', + 'name2' => 'es' + ] + ); + $this->assertEquals( + ['name1'=>'es'] + , $splArrayObj->unique()->getArrayCopy()); + } + + /** + * 获取数组中重复的值 + * + * @depends clone testSet + * CreateTime: 2019/9/11 上午12:22 + * @return bool + */ + public function testMultiple() { + $splArrayObj = new SplArray( + [ + 'name1' => 'es', + 'name2' => 'es' + ] + ); + $this->assertEquals(['name2'=>'es'], $splArrayObj->multiple()->getArrayCopy()); + } + + /** + * 进行排序并保持索引关系 + * + * @depends clone testSet + * CreateTime: 2019/9/11 上午12:32 + * @param SplArray $splArrayObj + */ + public function testAsort(SplArray $splArrayObj) { + $this->assertEquals( + [ + 'color' => [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ], + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ] + ] + ,$splArrayObj->asort()->getArrayCopy() + ); + } + + /** + * 按照键名排序 + * + * @depends clone testSet + * CreateTime: 2019/9/11 上午12:35 + * @param SplArray $splArrayObj + */ + public function testKsort(SplArray $splArrayObj) { + $this->assertEquals( + [ + 'color' => [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ], + 'fruit' => [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ] + ], + $splArrayObj->ksort()->getArrayCopy() + ); + } + + /** + * 排序 + * + * @depends clone testSet + * CreateTime: 2019/9/11 上午12:35 + * @param SplArray $splArrayObj + */ + public function testSort(SplArray $splArrayObj) { + $this->assertEquals( + [ + [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ], + [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ] + ], + $splArrayObj->sort()->getArrayCopy() + ); + } + + /** + * 取得某一列 + * + * @depends clone testSet + * CreateTime: 2019/9/11 上午12:35 + * @param SplArray $splArrayObj + * @return bool + */ + public function testColumn(SplArray $splArrayObj) { + $this->assertEquals( + [12], + $splArrayObj->column('red')->getArrayCopy() + ); + } + + /** + * 交换数组中的键和值 + */ + public function testFlip() { + $splArrayObj = new SplArray([ + 'es' => 'easyswoole' + ]); + $this->assertEquals( + [ + 'easyswoole' => 'es' + ], + $splArrayObj->flip()->getArrayCopy() + ); + } + + /** + * 过滤数组数据 + */ + public function testFilter() { + $splArrayObj = new SplArray( + [ + 'apple' => 2, + 'orange' => 1, + 'grape' => 2, + 'pear' => 4, + 'banana' => 8 + ] + ); + + // 获取设置的键名 + $this->assertEquals( + [ + 'apple' => 2, + 'pear' => 4 + ], + $splArrayObj->filter('apple,pear', false)->getArrayCopy() + ); + + // 排除设置的键名 + $this->assertEquals( + [ + 'apple' => 2, + 'pear' => 4 + ], + $splArrayObj->filter('orange,grape,banana', true)->getArrayCopy() + ); + } + + /** + * 获取数组索引 + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testKeys(SplArray $splArrayObj) { + $this->assertEquals( + ['red', 'blue', 'green'], + $splArrayObj->keys('color') + ); + } + + /** + * 获取数组中所有的值 + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testValues(SplArray $splArrayObj) { + $this->assertEquals( + [ + [ + 'apple' => 3, + 'orange' => 1, + 'grape' => 4 + ], + [ + 'red' => 12, + 'blue' => 8, + 'green' => 6 + ] + ], + $splArrayObj->values()->getArrayCopy() + ); + } + + /** + * 清空数据 + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testFlush(SplArray $splArrayObj) { + $this->assertEquals( + [], + $splArrayObj->flush()->getArrayCopy() + ); + } + + /** + * 重新加载数据 + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testLoadArray(SplArray $splArrayObj) { + $this->assertEquals( + [ + 'name' => 'easyswoole' + ], + $splArrayObj->loadArray( + [ + 'name' => 'easyswoole' + ] + )->getArrayCopy() + ); + } + + /** + * 转化成xml + * + * @depends clone testSet + * @param SplArray $splArrayObj + */ + public function testToXML(SplArray $splArrayObj) { + $this->assertEquals( + "3141286\n", + $splArrayObj->toXML() + ); + } +} diff --git a/extend/mysql_dll/easyswoole/spl/test/Bean/Shops.php b/extend/mysql_dll/easyswoole/spl/test/Bean/Shops.php new file mode 100644 index 0000000..c6ac9e0 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/Bean/Shops.php @@ -0,0 +1,9 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: 兼容php7.4约束类型单测 + */ +namespace EasySwoole\Spl\Test\Bean; + +use EasySwoole\Spl\SplBean; + +class TestAllProperty extends SplBean{ + + // static + public static $staticA; + protected static $staticB; + private static $staticC; + + // static赋初值 + public static $staticInitA=''; + protected static $staticInitB=''; + private static $staticInitC=''; + + // 普通 + public $a; + protected $b; + private $c; + + // 普通赋初值 + public $aInit=''; + protected $bInit=''; + private $cInit=''; + +} + +class TestAllProperty74 extends SplBean{ + + // static + public static $staticA; + protected static $staticB; + private static $staticC; + + // static赋初值 + public static $staticInitA=''; + protected static $staticInitB=''; + private static $staticInitC=''; + + // 普通 + public $a; + protected $b; + private $c; + + // 普通赋初值 + public $aInit=''; + protected $bInit=''; + private $cInit=''; + + // 约束类型 + public string $typeA; + protected int $typeB; + private bool $typeC; + + // 约束类型赋初值 + public string $typeInitA=''; + protected int $typeInitB=1; + private bool $typeInitC=true; + +} diff --git a/extend/mysql_dll/easyswoole/spl/test/Bean/TestBean.php b/extend/mysql_dll/easyswoole/spl/test/Bean/TestBean.php new file mode 100644 index 0000000..2c26572 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/Bean/TestBean.php @@ -0,0 +1,30 @@ +"d_d" + ]; + } + +// protected function setClassMapping(): array +// { +// return [ +// 'shops' => Shops::class +// ]; +// } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/BeanTest.php b/extend/mysql_dll/easyswoole/spl/test/BeanTest.php new file mode 100644 index 0000000..a01c201 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/BeanTest.php @@ -0,0 +1,237 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplBean 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\Test\Bean\Shops; +use PHPUnit\Framework\TestCase; +use EasySwoole\Spl\Test\Bean\TestBean; + +class BeanTest extends TestCase +{ + + /** + * 获取类所有的public和protected 成员变量 + */ + function testAllProperty() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $this->assertEquals( + ['a', 'b', 'd_d'], + $bean->allProperty() + ); + } + + /** + * 过滤并转换成数组数据 + */ + function testToArray() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $res = $bean->toArray(null, function ($a) { + if (in_array($a, ['d_d'])) { + return $a; + } + }); + $this->assertEquals( + ['d_d' => 'd_d'], + $res + ); + } + + /** + *获取过滤后带有字段别名的数组数据 + */ + function testToArrayWithMapping() { + $bean = new TestBean([ + 'a'=>1, + 'b'=>2, + 'c'=>3, + 'd_d'=>4 + ]); + $res = $bean->toArrayWithMapping(['a', 'b', 'd-d'], function ($val) { + return $val; + }); + $this->assertEquals( + [ + 'a' => 1, + 'b' => 2, + 'd-d' => 4 + ], + $res + ); + } + + /** + * 设置类属性 + */ + function testArrayToBean() + { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $this->assertEquals([ + 'a'=>'a', + 'b'=>'b', + 'd_d'=>'d_d' + ],$bean->toArray()); + + $this->assertEquals([ + 'a'=>'a', + 'b'=>'b', + ],$bean->toArray(['a','b'])); + + $this->assertEquals([ + 'a'=>'a', + 'd-d'=>'d_d' + ],$bean->toArrayWithMapping(['a','d-d'])); + } + + /** + * 设置类成员变量 + */ + function testAddProperty() { + $bean = new TestBean(); + $bean->addProperty('a', 'es'); + $bean->addProperty('b', 'es'); + $bean->addProperty('d_d', 'es'); + $this->assertEquals( + [ + 'a' => 'es', + 'b' => 'es', + 'd_d' => 'es', + ], + $bean->toArray() + ); + } + + /** + * 获取类成员变量值 + */ + function testGetProperty() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $this->assertEquals('a', $bean->getProperty('a')); + } + + /** + * 获取类成员变量集合 + */ + function testJsonSerialize() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $this->assertEquals( + [ + 'a'=>'a', + 'b'=>'b', + 'd_d'=>'d_d' + ], + $bean->jsonSerialize() + ); + } + + /** + * 初始化操作 + */ + function testInitialize() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + $this->assertEquals( + [ + 'a'=>'a', + 'b'=>'b', + 'd_d'=>'d_d' + ], + $bean->jsonSerialize() + ); + } + + /** + * 设置keyMapping关系,也就是字段别名 + */ + function testSetKeyMapping() { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd-d'=>'d' + ]); + $this->assertEquals( + [ + 'a'=>'a', + 'b'=>'b', + 'd_d'=>'d' + ], + $bean->jsonSerialize() + ); + } + + /** + * 设置classMapping关系,也就是关联类 + */ +// function testSetClassMapping() { +// return true; +// $bean = new TestBean([ +// 'a'=>'a', +// 'b'=>'b', +// 'c'=>'c', +// 'd-d'=>'d' +// ]); +// $this->assertEquals( +// Shops::class, +// get_class($bean->jsonSerialize()['shops']) +// ); +// } + + function testRestore() + { + $bean = new TestBean([ + 'a'=>'a', + 'b'=>'b', + 'c'=>'c', + 'd_d'=>'d_d' + ]); + + $this->assertEquals([ + 'a'=>2, + 'b'=>null, + 'd_d'=>null + ],$bean->restore()->toArray()); + + + $this->assertEquals([ + 'a'=>2 + ],$bean->restore()->toArray(null,$bean::FILTER_NOT_NULL)); + + + $bean->restore(['a'=>2,'b'=>3]); + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/Enum/Month.php b/extend/mysql_dll/easyswoole/spl/test/Enum/Month.php new file mode 100644 index 0000000..13aec16 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/Enum/Month.php @@ -0,0 +1,25 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplArray 单元测试 + */ +namespace EasySwoole\Spl\Test\Enum; + +use EasySwoole\Spl\SplEnum; + +class Month extends SplEnum { + const JANUARY = 1; + const FEBRUARY = 2; + const MARCH = 3; + const APRIL = 4; + const MAY = 5; + const JUNE = 6; + const JULY = 7; + const AUGUST = 8; + const SEPTEMBER = 9; + const OCTOBER = 10; + const NOVEMBER = 11; + const DECEMBER = 12; +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/EnumTest.php b/extend/mysql_dll/easyswoole/spl/test/EnumTest.php new file mode 100644 index 0000000..c52faef --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/EnumTest.php @@ -0,0 +1,72 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplEnum 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\Test\Enum\Month; +use PHPUnit\Framework\TestCase; + +class EnumTest extends TestCase { + + public function testConstruct() { + $month = new Month(1); + $this->assertEquals( + 'JANUARY', + $month->getName() + ); + } + + public function testGetName() { + $month = new Month(1); + $this->assertEquals( + 'JANUARY', + $month->getName() + ); + } + + public function testGetValue() { + $month = new Month(1); + $this->assertEquals( + 1, + $month->getValue() + ); + } + + public function testIsValidName() { + $this->assertTrue( + Month::isValidName('JANUARY') + ); + } + + public function testIsValidValue() { + $this->assertEquals( + 'JANUARY', + Month::isValidValue(1) + ); + } + + public function testGetEnumList() { + $this->assertEquals( + [ + 'JANUARY' => 1, + 'FEBRUARY' => 2, + 'MARCH' => 3, + 'APRIL' => 4, + 'MAY' => 5, + 'JUNE' => 6, + 'JULY' => 7, + 'AUGUST' => 8, + 'SEPTEMBER' => 9, + 'OCTOBER' => 10, + 'NOVEMBER' => 11, + 'DECEMBER' => 12, + ], + Month::getEnumList() + ); + } + +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/FileStreamTest.php b/extend/mysql_dll/easyswoole/spl/test/FileStreamTest.php new file mode 100644 index 0000000..9cceaa6 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/FileStreamTest.php @@ -0,0 +1,29 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplFileStream 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\SplFileStream; +use PHPUnit\Framework\TestCase; + +class FileStreamTest extends TestCase { + + public function testConstruct() { + $fileStream = new SplFileStream('./test.txt'); + $this->assertEquals('STDIO', $fileStream->getMetadata('stream_type')); + } + + public function testLock() { + $fileStream = new SplFileStream('./test.txt'); + $this->assertTrue($fileStream->lock()); + } + + public function testUnlock() { + $fileStream = new SplFileStream('./test.txt'); + $this->assertTrue($fileStream->unlock()); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/Stream/TestStream.php b/extend/mysql_dll/easyswoole/spl/test/Stream/TestStream.php new file mode 100644 index 0000000..8db916c --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/Stream/TestStream.php @@ -0,0 +1,11 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplStream 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\SplStream; +use EasySwoole\Spl\Test\Stream\TestStream; +use PHPUnit\Framework\TestCase; + +class StreamTest extends TestCase { + + public function testConstruct() { + $resource = fopen('./test.txt', 'ab+'); + $stream = new SplStream($resource); + $this->assertEquals( + 'Easyswoole', + $stream->__toString() + ); + + $stream = new SplStream(new TestStream()); + $this->assertEquals( + 'EsObject', + $stream->__toString() + ); + + $stream = new SplStream('Es'); + $this->assertEquals( + 'Es', + $stream->__toString() + ); + + } + + public function testToString() { + $stream = new SplStream('Es'); + $this->assertEquals( + 'Es', + $stream->__toString() + ); + } + + public function testClose() { + $resource = fopen('./test.txt', 'ab+'); + $stream = new SplStream($resource); + $stream->close(); + $this->assertEquals('', $stream->__toString()); + } + + public function testDetach() { + $stream = new SplStream('Es'); + $stream->detach(); + // 抛异常,所以返回为'' + $this->assertEquals('', $stream->__toString()); + } + + public function testGetSize() { + $stream = new SplStream('Es'); + $this->assertEquals(2, $stream->getSize()); + } + + public function testTell() { + $stream = new SplStream('Es'); + $stream->seek(1); + $this->assertEquals(1, $stream->tell()); + } + + public function testEof() { + $stream = new SplStream('Es'); + $stream->seek(1); + $this->assertNotTrue($stream->eof()); + } + + public function testIsSeekable() { + $stream = new SplStream('Es'); + $this->assertTrue($stream->isSeekable()); + } + + public function testSeek() { + $stream = new SplStream('Es'); + $stream->seek(1); + $this->assertEquals(1, $stream->tell()); + } + + public function testRewind() { + $stream = new SplStream('Es'); + $stream->rewind(); + $this->assertEquals(0, $stream->tell()); + } + + public function testIsWritable() { + $stream = new SplStream('Es'); + $this->assertEquals(true, $stream->isWritable()); + } + + public function testWrite() { + $stream = new SplStream(''); + $stream->write('Es'); + $this->assertEquals('Es', $stream->__toString()); + } + + public function testIsReadable() { + $stream = new SplStream('Es'); + $this->assertTrue($stream->isReadable()); + } + + public function testRead() { + $resource = fopen('./test.txt', 'rb'); + $stream = new SplStream($resource); + $this->assertEquals('E', $stream->read(1)); + } + + public function testGetContents() { + $stream = new SplStream('Es'); + $stream->seek(0); + $this->assertEquals('Es', $stream->getContents()); + } + + public function testGetMetadata() { + $stream = new SplStream('Es'); + $this->assertEquals('MEMORY', $stream->getMetadata()['stream_type']); + } + + public function testGetStreamResource() { + $stream = new SplStream('Es'); + $source = $stream->getStreamResource(); + fseek($source, 0, SEEK_SET); + $this->assertEquals('Es', stream_get_contents($source)); + } + + public function testTruncate() { + $stream = new SplStream('Es'); + $stream->truncate(1); + $this->assertEquals('E', $stream->__toString()); + } +} \ No newline at end of file diff --git a/extend/mysql_dll/easyswoole/spl/test/StringTest.php b/extend/mysql_dll/easyswoole/spl/test/StringTest.php new file mode 100644 index 0000000..cd3c4f1 --- /dev/null +++ b/extend/mysql_dll/easyswoole/spl/test/StringTest.php @@ -0,0 +1,197 @@ + + * @Copyright: copyright(2019) Easyswoole all rights reserved + * @Description: SplString 单元测试 + */ +namespace EasySwoole\Spl\Test; + +use EasySwoole\Spl\SplString; +use PHPUnit\Framework\TestCase; + +class StringTest extends TestCase { + + public function testSetString() { + $splString = new SplString(); + $splString->setString('Easyswoole'); + $this->assertEquals('Easyswoole', $splString->__toString()); + } + + public function testSplit() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals([ + 'Hello', ', Eas', 'yswoo', 'le' + ], $splString->split(5)->getArrayCopy()); + } + + public function testExplode() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals([ + 'Hello', 'Easyswoole' + ], $splString->explode(', ')->getArrayCopy()); + } + + public function testSubString() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals('Hello', $splString->subString(0, 5)->__toString()); + } + + public function testEncodingConvert() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals('Hello, Easyswoole', $splString->encodingConvert('UTF-8')->__toString()); + } + + public function testUtf8() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals('Hello, Easyswoole', $splString->utf8()->__toString()); + } + + public function testUnicodeToUtf8() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals('Hello, Easyswoole', $splString->unicodeToUtf8()->__toString()); + } + + public function testToUnicode() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals('\U0048\U0065\U006C\U006C\U006F\U002C\U0020\U0045\U0061\U0073\U0079\U0073\U0077\U006F\U006F\U006C\U0065', $splString->toUnicode()->__toString()); + } + + public function testCompare() { + $splString = new SplString('Hello, Easyswoole'); + $this->assertEquals(-18, $splString->compare('Hello, Es')); + } + + public function testLtrim() { + $splString = new SplString(' es'); + $this->assertEquals('es', $splString->lTrim()); + } + + public function testRtrim() { + $splString = new SplString('es '); + $this->assertEquals('es', $splString->rTrim()); + } + + public function testTrime() { + $splString = new SplString(' es '); + $this->assertEquals('es', $splString->trim()); + } + + public function testPad() { + $splString = new SplString('Easy'); + $splString->pad(10, 'swoole'); + $this->assertEquals('Easyswoole', $splString->__toString()); + + $splString->pad(16, 'Hello,', STR_PAD_LEFT); + $this->assertEquals('Hello,Easyswoole', $splString->__toString()); + + $splString->pad(18, '@', STR_PAD_BOTH); + $this->assertEquals('@Hello,Easyswoole@', $splString->__toString()); + } + + public function testRepeat() { + $splString = new SplString('EasySwoole'); + $splString->repeat(2); + $this->assertEquals('EasySwooleEasySwoole', $splString->__toString()); + } + + public function testLength() { + $splString = new SplString('EasySwoole'); + $this->assertEquals(10, $splString->length()); + } + + public function testUpper() { + $splString = new SplString('EasySwoole'); + $this->assertEquals('EASYSWOOLE', $splString->upper()); + } + + public function testLower() { + $splString = new SplString('EasySwoole'); + $this->assertEquals('easyswoole', $splString->lower()); + } + + public function testStripTags() { + $splString = new SplString('Easyswoole'); + $this->assertEquals('Easyswoole', $splString->stripTags()->__toString()); + } + + public function testReplace() { + $splString = new SplString('Hello, es!'); + $this->assertEquals('Hello, Easyswoole!', $splString->replace('es', 'Easyswoole')); + } + + public function testBetween() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertEquals(',', $splString->between('Hello', 'Easyswoole')->__toString()); + } + + public function testRegex() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertEquals('Easyswoole', $splString->regex('/Easyswoole/')); + } + + public function testExist() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertTrue($splString->exist('Easyswoole')); + } + + public function testKebab() { + $splString = new SplString('EasySwoole'); + $this->assertEquals('easy-swoole', $splString->kebab()->__toString()); + } + + public function testSnake() { + $splString = new SplString('EasySwoole'); + $this->assertEquals('easy_swoole', $splString->snake()->__toString()); + } + + public function testStudly() { + $splString = new SplString('easy_swoole'); + $this->assertEquals('EasySwoole', $splString->studly()->__toString()); + } + + public function testCamel() { + $splString = new SplString('easy_swoole'); + $this->assertEquals('easySwoole', $splString->camel()->__toString()); + } + + public function testReplaceArray() { + $splString = new SplString('easy_easy_easy'); + $this->assertEquals('as_bs_cs', $splString->replaceArray('easy', ['as', 'bs', 'cs'])->__toString()); + } + + public function testReplaceFirst() { + $splString = new SplString('easy_easy_easy'); + $this->assertEquals('as_easy_easy', $splString->replaceFirst('easy', 'as')->__toString()); + } + + public function testReplaceLast() { + $splString = new SplString('easy_easy_easy'); + $this->assertEquals('easy_easy_as', $splString->replaceLast('easy', 'as')->__toString()); + } + + public function testStart() { + $splString = new SplString('Easyswoole'); + $this->assertEquals('Hello,Easyswoole', $splString->start('Hello,')->__toString()); + } + + public function testAfter() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertEquals('Easyswoole', $splString->after('Hello,')->__toString()); + } + + public function testBefore() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertEquals('Hello,', $splString->before('Easyswoole')->__toString()); + } + + public function testEndsWith() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertTrue($splString->endsWith('Easyswoole')); + } + + public function testStartsWith() { + $splString = new SplString('Hello,Easyswoole'); + $this->assertTrue($splString->startsWith('Hello')); + } +} diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..cbc7868 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,8 @@ + + Options +FollowSymlinks -Multiviews + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e71815a Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..bb770ab --- /dev/null +++ b/public/index.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- + +// [ 应用入口文件 ] +namespace think; + +require __DIR__ . '/../vendor/autoload.php'; +require __DIR__ . "/../extend/mysql_dll/autoload.php"; +// 执行HTTP应用并响应 +$http = (new App())->http; + +$response = $http->run(); + +$response->send(); + +$http->end($response); diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/public/router.php b/public/router.php new file mode 100644 index 0000000..9b39a62 --- /dev/null +++ b/public/router.php @@ -0,0 +1,19 @@ + +// +---------------------------------------------------------------------- +// $Id$ + +if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { + return false; +} else { + $_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php'; + + require __DIR__ . "/index.php"; +} diff --git a/public/static/.gitignore b/public/static/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/public/static/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/route/app.php b/route/app.php new file mode 100644 index 0000000..d8e09e3 --- /dev/null +++ b/route/app.php @@ -0,0 +1,17 @@ + +// +---------------------------------------------------------------------- +use think\facade\Route; + +Route::get('think', function () { + return 'hello,ThinkPHP6!'; +}); + +Route::get('hello/:name', 'index/hello'); diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/think b/think new file mode 100644 index 0000000..2429d22 --- /dev/null +++ b/think @@ -0,0 +1,10 @@ +#!/usr/bin/env php +console->run(); \ No newline at end of file diff --git a/view/README.md b/view/README.md new file mode 100644 index 0000000..360eb24 --- /dev/null +++ b/view/README.md @@ -0,0 +1 @@ +如果不使用模板,可以删除该目录 \ No newline at end of file