diff --git a/app/biz/ResCode.php b/app/biz/ResCode.php new file mode 100644 index 0000000..e973ade --- /dev/null +++ b/app/biz/ResCode.php @@ -0,0 +1,35 @@ + '内部错误', + self::SUCCESS => '操作成功', + self::FAILED => '操作失败', + self::NOT_LOGGED => '用户未登录', + self::HEARTBEAT => '心跳', + self::NOT_ALLOWED => '没有权限', + self::NOT_FOUND => '请求路径不正确', + self::INTERNAL_ERROR => '系统错误', + self::NO_DATA => '数据不存在', + self::LOGIN_FAILED => '登录失败', + self::NO_CHANGE => '无数据变化', + self::TOKEN_ERROR => '令牌无效', + self::TIMEOUT => '超时', + ]; +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 3515a48..51e2630 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -2,6 +2,7 @@ namespace app\controller; +use support\Container; use support\Log; use support\Request; use Wandoubaba\Res; @@ -10,7 +11,7 @@ class IndexController { public function index(Request $request) { - $res = new Res(); + $res = Container::make(Res::class); $res1 = \jsonrpc\Client::service('default', 'Demo')->hello('Json'); $res2 = \jsonrpc\Client::service('user', 'User')->login('admin', '123456'); $res3 = \jsonrpc\Client::service('default', 'Demo')->text(); diff --git a/composer.lock b/composer.lock index fdc41ff..4f1ddae 100644 --- a/composer.lock +++ b/composer.lock @@ -285,7 +285,7 @@ }, { "name": "illuminate/bus", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/bus.git", @@ -338,7 +338,7 @@ }, { "name": "illuminate/collections", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", @@ -393,7 +393,7 @@ }, { "name": "illuminate/conditionable", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -439,7 +439,7 @@ }, { "name": "illuminate/container", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", @@ -490,7 +490,7 @@ }, { "name": "illuminate/contracts", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -538,7 +538,7 @@ }, { "name": "illuminate/database", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/database.git", @@ -611,7 +611,7 @@ }, { "name": "illuminate/events", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/events.git", @@ -666,7 +666,7 @@ }, { "name": "illuminate/macroable", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -712,7 +712,7 @@ }, { "name": "illuminate/pagination", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/pagination.git", @@ -762,7 +762,7 @@ }, { "name": "illuminate/pipeline", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/pipeline.git", @@ -810,16 +810,16 @@ }, { "name": "illuminate/redis", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/redis.git", - "reference": "69771c1ef8d76a0066d86e41f26598d6650eb79f" + "reference": "e0d81f4f9972b0b9dd416516a1f4c209939ef15a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/redis/zipball/69771c1ef8d76a0066d86e41f26598d6650eb79f", - "reference": "69771c1ef8d76a0066d86e41f26598d6650eb79f", + "url": "https://api.github.com/repos/illuminate/redis/zipball/e0d81f4f9972b0b9dd416516a1f4c209939ef15a", + "reference": "e0d81f4f9972b0b9dd416516a1f4c209939ef15a", "shasum": "" }, "require": { @@ -860,20 +860,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-09-11T19:51:35+00:00" + "time": "2023-12-25T01:10:57+00:00" }, { "name": "illuminate/support", - "version": "v10.38.2", + "version": "v10.39.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "a9f486d76d5403b0c95b8532cd151a0a960f9565" + "reference": "6705007f24091863fefdf1f9320ac2c121cf37f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/a9f486d76d5403b0c95b8532cd151a0a960f9565", - "reference": "a9f486d76d5403b0c95b8532cd151a0a960f9565", + "url": "https://api.github.com/repos/illuminate/support/zipball/6705007f24091863fefdf1f9320ac2c121cf37f1", + "reference": "6705007f24091863fefdf1f9320ac2c121cf37f1", "shasum": "" }, "require": { @@ -931,7 +931,67 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-12-19T15:11:55+00:00" + "time": "2023-12-25T01:11:56+00:00" + }, + { + "name": "laravel/serializable-closure", + "version": "v1.3.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/serializable-closure.git", + "reference": "3dbf8a8e914634c48d389c1234552666b3d43754" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/3dbf8a8e914634c48d389c1234552666b3d43754", + "reference": "3dbf8a8e914634c48d389c1234552666b3d43754", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "nesbot/carbon": "^2.61", + "pestphp/pest": "^1.21.3", + "phpstan/phpstan": "^1.8.2", + "symfony/var-dumper": "^5.4.11" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Laravel\\SerializableClosure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + }, + { + "name": "Nuno Maduro", + "email": "nuno@laravel.com" + } + ], + "description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.", + "keywords": [ + "closure", + "laravel", + "serializable" + ], + "support": { + "issues": "https://github.com/laravel/serializable-closure/issues", + "source": "https://github.com/laravel/serializable-closure" + }, + "time": "2023-11-08T14:08:06+00:00" }, { "name": "monolog/monolog", @@ -1192,6 +1252,134 @@ }, "time": "2018-02-13T20:26:39+00:00" }, + { + "name": "php-di/invoker", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/Invoker.git", + "reference": "33234b32dafa8eb69202f950a1fc92055ed76a86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/33234b32dafa8eb69202f950a1fc92055ed76a86", + "reference": "33234b32dafa8eb69202f950a1fc92055ed76a86", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "psr/container": "^1.0|^2.0" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "mnapoli/hard-mode": "~0.3.0", + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Invoker\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Generic and extensible callable invoker", + "homepage": "https://github.com/PHP-DI/Invoker", + "keywords": [ + "callable", + "dependency", + "dependency-injection", + "injection", + "invoke", + "invoker" + ], + "support": { + "issues": "https://github.com/PHP-DI/Invoker/issues", + "source": "https://github.com/PHP-DI/Invoker/tree/2.3.4" + }, + "funding": [ + { + "url": "https://github.com/mnapoli", + "type": "github" + } + ], + "time": "2023-09-08T09:24:21+00:00" + }, + { + "name": "php-di/php-di", + "version": "7.0.6", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/PHP-DI.git", + "reference": "8097948a89f6ec782839b3e958432f427cac37fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/8097948a89f6ec782839b3e958432f427cac37fd", + "reference": "8097948a89f6ec782839b3e958432f427cac37fd", + "shasum": "" + }, + "require": { + "laravel/serializable-closure": "^1.0", + "php": ">=8.0", + "php-di/invoker": "^2.0", + "psr/container": "^1.1 || ^2.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3", + "friendsofphp/proxy-manager-lts": "^1", + "mnapoli/phpunit-easymock": "^1.3", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^4.6" + }, + "suggest": { + "friendsofphp/proxy-manager-lts": "Install it if you want to use lazy injection (version ^1)" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "DI\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The dependency injection container for humans", + "homepage": "https://php-di.org/", + "keywords": [ + "PSR-11", + "container", + "container-interop", + "dependency injection", + "di", + "ioc", + "psr11" + ], + "support": { + "issues": "https://github.com/PHP-DI/PHP-DI/issues", + "source": "https://github.com/PHP-DI/PHP-DI/tree/7.0.6" + }, + "funding": [ + { + "url": "https://github.com/mnapoli", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/php-di/php-di", + "type": "tidelift" + } + ], + "time": "2023-11-02T10:04:50+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.2", @@ -1471,16 +1659,16 @@ }, { "name": "symfony/console", - "version": "v6.4.1", + "version": "v6.4.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "a550a7c99daeedef3f9d23fb82e3531525ff11fd" + "reference": "0254811a143e6bc6c8deea08b589a7e68a37f625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/a550a7c99daeedef3f9d23fb82e3531525ff11fd", - "reference": "a550a7c99daeedef3f9d23fb82e3531525ff11fd", + "url": "https://api.github.com/repos/symfony/console/zipball/0254811a143e6bc6c8deea08b589a7e68a37f625", + "reference": "0254811a143e6bc6c8deea08b589a7e68a37f625", "shasum": "" }, "require": { @@ -1545,7 +1733,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.1" + "source": "https://github.com/symfony/console/tree/v6.4.2" }, "funding": [ { @@ -1561,7 +1749,7 @@ "type": "tidelift" } ], - "time": "2023-11-30T10:54:28+00:00" + "time": "2023-12-10T16:15:48+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2045,21 +2233,21 @@ }, { "name": "symfony/service-contracts", - "version": "v3.4.0", + "version": "v3.4.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838" + "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/b3313c2dbffaf71c8de2934e2ea56ed2291a3838", - "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/fe07cbc8d837f60caf7018068e350cc5163681a0", + "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^2.0" + "psr/container": "^1.1|^2.0" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -2107,7 +2295,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.4.1" }, "funding": [ { @@ -2123,20 +2311,20 @@ "type": "tidelift" } ], - "time": "2023-07-30T20:28:31+00:00" + "time": "2023-12-26T14:02:43+00:00" }, { "name": "symfony/string", - "version": "v6.4.0", + "version": "v6.4.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "b45fcf399ea9c3af543a92edf7172ba21174d809" + "reference": "7cb80bc10bfcdf6b5492741c0b9357dac66940bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/b45fcf399ea9c3af543a92edf7172ba21174d809", - "reference": "b45fcf399ea9c3af543a92edf7172ba21174d809", + "url": "https://api.github.com/repos/symfony/string/zipball/7cb80bc10bfcdf6b5492741c0b9357dac66940bc", + "reference": "7cb80bc10bfcdf6b5492741c0b9357dac66940bc", "shasum": "" }, "require": { @@ -2193,7 +2381,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.4.0" + "source": "https://github.com/symfony/string/tree/v6.4.2" }, "funding": [ { @@ -2209,20 +2397,20 @@ "type": "tidelift" } ], - "time": "2023-11-28T20:41:49+00:00" + "time": "2023-12-10T16:15:48+00:00" }, { "name": "symfony/translation", - "version": "v6.4.0", + "version": "v6.4.2", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "b1035dbc2a344b21f8fa8ac451c7ecec4ea45f37" + "reference": "a2ab2ec1a462e53016de8e8d5e8912bfd62ea681" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/b1035dbc2a344b21f8fa8ac451c7ecec4ea45f37", - "reference": "b1035dbc2a344b21f8fa8ac451c7ecec4ea45f37", + "url": "https://api.github.com/repos/symfony/translation/zipball/a2ab2ec1a462e53016de8e8d5e8912bfd62ea681", + "reference": "a2ab2ec1a462e53016de8e8d5e8912bfd62ea681", "shasum": "" }, "require": { @@ -2288,7 +2476,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v6.4.0" + "source": "https://github.com/symfony/translation/tree/v6.4.2" }, "funding": [ { @@ -2304,20 +2492,20 @@ "type": "tidelift" } ], - "time": "2023-11-29T08:14:36+00:00" + "time": "2023-12-18T09:25:29+00:00" }, { "name": "symfony/translation-contracts", - "version": "v3.4.0", + "version": "v3.4.1", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5" + "reference": "06450585bf65e978026bda220cdebca3f867fde7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/dee0c6e5b4c07ce851b462530088e64b255ac9c5", - "reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/06450585bf65e978026bda220cdebca3f867fde7", + "reference": "06450585bf65e978026bda220cdebca3f867fde7", "shasum": "" }, "require": { @@ -2366,7 +2554,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/translation-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/translation-contracts/tree/v3.4.1" }, "funding": [ { @@ -2382,20 +2570,20 @@ "type": "tidelift" } ], - "time": "2023-07-25T15:08:44+00:00" + "time": "2023-12-26T14:02:43+00:00" }, { "name": "symfony/var-dumper", - "version": "v6.4.0", + "version": "v6.4.2", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "c40f7d17e91d8b407582ed51a2bbf83c52c367f6" + "reference": "68d6573ec98715ddcae5a0a85bee3c1c27a4c33f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/c40f7d17e91d8b407582ed51a2bbf83c52c367f6", - "reference": "c40f7d17e91d8b407582ed51a2bbf83c52c367f6", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/68d6573ec98715ddcae5a0a85bee3c1c27a4c33f", + "reference": "68d6573ec98715ddcae5a0a85bee3c1c27a4c33f", "shasum": "" }, "require": { @@ -2451,7 +2639,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v6.4.0" + "source": "https://github.com/symfony/var-dumper/tree/v6.4.2" }, "funding": [ { @@ -2467,7 +2655,7 @@ "type": "tidelift" } ], - "time": "2023-11-09T08:28:32+00:00" + "time": "2023-12-28T19:16:56+00:00" }, { "name": "vlucas/phpdotenv", @@ -2629,23 +2817,24 @@ }, { "name": "wandoubaba/res", - "version": "v1.0.4", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/wandoubaba/res.git", - "reference": "679dfee8fa357bc98fe6c585e12a01994aee0046" + "reference": "abcbdb34400cc5f151f689b392901d8ca2b9a275" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wandoubaba/res/zipball/679dfee8fa357bc98fe6c585e12a01994aee0046", - "reference": "679dfee8fa357bc98fe6c585e12a01994aee0046", + "url": "https://api.github.com/repos/wandoubaba/res/zipball/abcbdb34400cc5f151f689b392901d8ca2b9a275", + "reference": "abcbdb34400cc5f151f689b392901d8ca2b9a275", "shasum": "" }, "require": { - "php": ">=7.4" + "php": ">=7.4", + "php-di/php-di": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^10.4" + "phpunit/phpunit": "^9.6" }, "type": "library", "autoload": { @@ -2666,9 +2855,9 @@ "description": "一个简单的Res模型,包含code、msg、data属性,可用于HTTP接口的返回值", "support": { "issues": "https://github.com/wandoubaba/res/issues", - "source": "https://github.com/wandoubaba/res/tree/v1.0.4" + "source": "https://github.com/wandoubaba/res/tree/v1.1.1" }, - "time": "2023-10-18T08:08:05+00:00" + "time": "2024-01-03T06:48:17+00:00" }, { "name": "webman/console", @@ -2725,16 +2914,16 @@ }, { "name": "workerman/webman-framework", - "version": "v1.5.13", + "version": "v1.5.14", "source": { "type": "git", "url": "https://github.com/walkor/webman-framework.git", - "reference": "699c9c9509d472679fa1d8461b9a9bb58fbe79a7" + "reference": "d9304dfa142b610f2ce307267a32ddbd0553e474" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/walkor/webman-framework/zipball/699c9c9509d472679fa1d8461b9a9bb58fbe79a7", - "reference": "699c9c9509d472679fa1d8461b9a9bb58fbe79a7", + "url": "https://api.github.com/repos/walkor/webman-framework/zipball/d9304dfa142b610f2ce307267a32ddbd0553e474", + "reference": "d9304dfa142b610f2ce307267a32ddbd0553e474", "shasum": "" }, "require": { @@ -2783,7 +2972,7 @@ "source": "https://github.com/walkor/webman-framework", "wiki": "https://doc.workerman.net/" }, - "time": "2023-11-16T04:06:19+00:00" + "time": "2024-01-03T07:32:40+00:00" }, { "name": "workerman/workerman", diff --git a/config/container.php b/config/container.php index 106b7b4..29e7ac9 100644 --- a/config/container.php +++ b/config/container.php @@ -12,4 +12,10 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -return new Webman\Container; \ No newline at end of file +// return new Webman\Container; + +$builder = new \DI\ContainerBuilder(); +$builder->addDefinitions(config('dependence', [])); +$builder->useAutowiring(true); +$builder->useAttributes(true); +return $builder->build(); \ No newline at end of file diff --git a/config/dependence.php b/config/dependence.php index 8e964ed..2ac0916 100644 --- a/config/dependence.php +++ b/config/dependence.php @@ -12,4 +12,7 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -return []; \ No newline at end of file + return [ + // 注入自定义错误码和错误提示 + 'code_messages' => app\biz\ResCode::CODE_MESSAGES, +]; \ No newline at end of file diff --git a/support/helpers.php b/support/helpers.php index e200040..dc5db77 100644 --- a/support/helpers.php +++ b/support/helpers.php @@ -380,7 +380,7 @@ function copy_dir(string $source, string $dest, bool $overwrite = false) $files = scandir($source); foreach ($files as $file) { if ($file !== "." && $file !== "..") { - copy_dir("$source/$file", "$dest/$file"); + copy_dir("$source/$file", "$dest/$file", $overwrite); } } } else if (file_exists($source) && ($overwrite || !file_exists($dest))) { @@ -515,3 +515,14 @@ function cpu_count(): int } return $count > 0 ? $count : 4; } + +/** + * get GET or POST request parameters, if no parameter name is passed, an array of all values is returned, default values is supported + * @param string|null $param param's name + * @param string|null $default default value + * @return mixed|null + */ +function input(string $param = null, string $default = null) +{ + return is_null($param) ? request()->all() : request()->input($param, $default); +} diff --git a/windows.php b/windows.php index d1975d6..21fa888 100644 --- a/windows.php +++ b/windows.php @@ -61,6 +61,7 @@ function write_process_file($runtimeProcessPath, $processName, $firm): string require_once __DIR__ . '/../../vendor/autoload.php'; use Workerman\Worker; +use Workerman\Connection\TcpConnection; use Webman\Config; use support\App; @@ -77,6 +78,7 @@ worker_start('$processParam', $configParam); if (DIRECTORY_SEPARATOR != "/") { Worker::\$logFile = config('server')['log_file'] ?? Worker::\$logFile; + TcpConnection::\$defaultMaxPackageSize = config('server')['max_package_size'] ?? 10*1024*1024; } Worker::runAll();