From b02a2cc73f211f372fbc2c6eda044b100aa449e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Thu, 28 Apr 2022 21:25:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(handler):=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李东云 --- composer.json | 5 +- composer.lock | 1214 +++++++++++++---- .../Exceptions/Handler/ClassicHandler.php | 302 ++++ .../Exceptions/Handler/RestfulHandler.php | 326 +++++ 4 files changed, 1568 insertions(+), 279 deletions(-) create mode 100644 src/Utils/Exceptions/Handler/ClassicHandler.php create mode 100644 src/Utils/Exceptions/Handler/RestfulHandler.php diff --git a/composer.json b/composer.json index cdca996..a131592 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ }, "require": { "php": "~8.0", - "composer/composer": "*", + "ext-redis": "^5.3", + "composer/composer": ">=2.0", "ergebnis/http-method": "^2.2", "hyperf/config": "^2.2", "hyperf/constants": "^2.2", @@ -30,11 +31,13 @@ "hyperf/translation": "^2.2", "lmc/http-constants": "^1.2", "roave/dont": "^1.5", + "symfony/mailer": "^6.0", "teapot/status-code": "^1.1" }, "require-dev": { "firebase/php-jwt": "^6.1", "hyperf/session": "^2.2", + "hyperf/validation": "^2.2", "phpunit/phpunit": "^9.5", "roave/security-advisories": "dev-latest" }, diff --git a/composer.lock b/composer.lock index a569116..e76b0aa 100644 --- a/composer.lock +++ b/composer.lock @@ -1,20 +1,20 @@ { - "_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": "99d0d3be0980cd8eae389f105bcc613a", - "packages": [ - { - "name": "composer/ca-bundle", - "version": "1.3.1", - "source": { - "type": "git", - "url": "https://github.com/composer/ca-bundle.git", - "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b" - }, - "dist": { + "_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": "1bce2eb63c6ab8e4ff6b851d39b3cd61", + "packages": [ + { + "name": "composer/ca-bundle", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b" + }, + "dist": { "type": "zip", "url": "https://api.github.com/repos/composer/ca-bundle/zipball/4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", @@ -920,26 +920,100 @@ }, { "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" + "type": "patreon" }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", - "type": "tidelift" - } + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", + "type": "tidelift" + } ], - "time": "2022-02-28T11:07:21+00:00" + "time": "2022-02-28T11:07:21+00:00" }, + { + "name": "egulias/email-validator", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/egulias/EmailValidator.git", + "reference": "ee0db30118f661fb166bcffbf5d82032df484697" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ee0db30118f661fb166bcffbf5d82032df484697", + "reference": "ee0db30118f661fb166bcffbf5d82032df484697", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "doctrine/lexer": "^1.2", + "php": ">=7.2", + "symfony/polyfill-intl-idn": "^1.15" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^8.5.8|^9.3.3", + "vimeo/psalm": "^4" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Egulias\\EmailValidator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { - "name": "ergebnis/http-method", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/ergebnis/http-method.git", - "reference": "d5211663783f2d2be21b10f5279c70defcd20976" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ergebnis/http-method/zipball/d5211663783f2d2be21b10f5279c70defcd20976", + "name": "Eduardo Gulias Davis" + } + ], + "description": "A library for validating emails against several RFCs", + "homepage": "https://github.com/egulias/EmailValidator", + "keywords": [ + "email", + "emailvalidation", + "emailvalidator", + "validation", + "validator" + ], + "support": { + "issues": "https://github.com/egulias/EmailValidator/issues", + "source": "https://github.com/egulias/EmailValidator/tree/3.1.2" + }, + "funding": [ + { + "url": "https://github.com/egulias", + "type": "github" + } + ], + "time": "2021-10-11T09:18:27+00:00" + }, + { + "name": "ergebnis/http-method", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/ergebnis/http-method.git", + "reference": "d5211663783f2d2be21b10f5279c70defcd20976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ergebnis/http-method/zipball/d5211663783f2d2be21b10f5279c70defcd20976", "reference": "d5211663783f2d2be21b10f5279c70defcd20976", "shasum": "", "mirrors": [ @@ -3897,26 +3971,26 @@ }, "time": "2021-12-10T11:20:11+00:00" }, - { - "name": "symfony/console", - "version": "v5.4.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "900275254f0a1a2afff1ab0e11abd5587a10e1d6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/900275254f0a1a2afff1ab0e11abd5587a10e1d6", - "reference": "900275254f0a1a2afff1ab0e11abd5587a10e1d6", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + { + "name": "symfony/console", + "version": "v5.4.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "ffe3aed36c4d60da2cf1b0a1cee6b8f2e5fa881b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/ffe3aed36c4d60da2cf1b0a1cee6b8f2e5fa881b", + "reference": "ffe3aed36c4d60da2cf1b0a1cee6b8f2e5fa881b", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { "php": ">=7.2.5", "symfony/deprecation-contracts": "^2.1|^3", @@ -3984,7 +4058,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.7" + "source": "https://github.com/symfony/console/tree/v5.4.8" }, "funding": [ { @@ -4000,7 +4074,7 @@ "type": "tidelift" } ], - "time": "2022-03-31T17:09:19+00:00" + "time": "2022-04-12T16:02:29+00:00" }, { "name": "symfony/deprecation-contracts", @@ -4066,26 +4140,200 @@ }, { "url": "https://github.com/fabpot", - "type": "github" + "type": "github" }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } ], - "time": "2021-11-01T23:48:49+00:00" + "time": "2021-11-01T23:48:49+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v6.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "6472ea2dd415e925b90ca82be64b8bc6157f3934" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/6472ea2dd415e925b90ca82be64b8bc6157f3934", + "reference": "6472ea2dd415e925b90ca82be64b8bc6157f3934", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=8.0.2", + "symfony/event-dispatcher-contracts": "^2|^3" + }, + "conflict": { + "symfony/dependency-injection": "<5.4" + }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "2.0|3.0" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/error-handler": "^5.4|^6.0", + "symfony/expression-language": "^5.4|^6.0", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/stopwatch": "^5.4|^6.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { - "name": "symfony/filesystem", - "version": "v6.0.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff", + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/event-dispatcher/tree/v6.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, + { + "name": "symfony/event-dispatcher-contracts", + "version": "v3.0.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "7bc61cc2db649b4637d331240c5346dcc7708051" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7bc61cc2db649b4637d331240c5346dcc7708051", + "reference": "7bc61cc2db649b4637d331240c5346dcc7708051", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=8.0.2", + "psr/event-dispatcher": "^1" + }, + "suggest": { + "symfony/event-dispatcher-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\EventDispatcher\\": "" + } + }, + "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": "Generic abstractions related to dispatching event", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.0.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v6.0.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff", "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff", "shasum": "", "mirrors": [ @@ -4144,26 +4392,26 @@ ], "time": "2022-04-01T12:54:51+00:00" }, - { - "name": "symfony/finder", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/231313534dded84c7ecaa79d14bc5da4ccb69b7d", - "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + { + "name": "symfony/finder", + "version": "v5.4.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "9b630f3427f3ebe7cd346c277a1408b00249dad9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/9b630f3427f3ebe7cd346c277a1408b00249dad9", + "reference": "9b630f3427f3ebe7cd346c277a1408b00249dad9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { "php": ">=7.2.5", "symfony/deprecation-contracts": "^2.1|^3", @@ -4185,33 +4433,200 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "email": "fabien@symfony.com" }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } ], - "description": "Finds files and directories via an intuitive fluent interface", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.3" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, + "description": "Finds files and directories via an intuitive fluent interface", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/finder/tree/v5.4.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-04-15T08:07:45+00:00" + }, + { + "name": "symfony/mailer", + "version": "v6.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/mailer.git", + "reference": "706af6b3e99ebcbc639c9c664f5579aaa869409b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mailer/zipball/706af6b3e99ebcbc639c9c664f5579aaa869409b", + "reference": "706af6b3e99ebcbc639c9c664f5579aaa869409b", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "egulias/email-validator": "^2.1.10|^3", + "php": ">=8.0.2", + "psr/event-dispatcher": "^1", + "psr/log": "^1|^2|^3", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/mime": "^5.4|^6.0", + "symfony/service-contracts": "^1.1|^2|^3" + }, + "conflict": { + "symfony/http-kernel": "<5.4" + }, + "require-dev": { + "symfony/http-client-contracts": "^1.1|^2|^3", + "symfony/messenger": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mailer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps sending emails", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/mailer/tree/v6.0.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-04-27T17:10:30+00:00" + }, + { + "name": "symfony/mime", + "version": "v6.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/mime.git", + "reference": "c1701e88ad0ca49fc6ad6cdf360bc0e1209fb5e1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mime/zipball/c1701e88ad0ca49fc6ad6cdf360bc0e1209fb5e1", + "reference": "c1701e88ad0ca49fc6ad6cdf360bc0e1209fb5e1", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=8.0.2", + "symfony/polyfill-intl-idn": "^1.10", + "symfony/polyfill-mbstring": "^1.0" + }, + "conflict": { + "egulias/email-validator": "~3.0.0", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/mailer": "<5.4" + }, + "require-dev": { + "egulias/email-validator": "^2.1.10|^3.1", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/serializer": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mime\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows manipulating MIME messages", + "homepage": "https://symfony.com", + "keywords": [ + "mime", + "mime-type" + ], + "support": { + "source": "https://github.com/symfony/mime/tree/v6.0.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2022-01-26T16:34:36+00:00" + "time": "2022-04-12T16:11:42+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4379,26 +4794,119 @@ }, { "url": "https://github.com/fabpot", - "type": "github" + "type": "github" }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } ], - "time": "2021-11-23T21:10:46+00:00" + "time": "2021-11-23T21:10:46+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.25.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" }, { - "name": "symfony/polyfill-intl-normalizer", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.25.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-09-14T14:02:44+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.25.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", "shasum": "", "mirrors": [ @@ -4558,26 +5066,108 @@ }, { "url": "https://github.com/fabpot", - "type": "github" + "type": "github" }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } ], - "time": "2021-11-30T18:21:41+00:00" + "time": "2021-11-30T18:21:41+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.25.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" }, { - "name": "symfony/polyfill-php73", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", + "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" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.25.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-27T09:17:38+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.25.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5", "shasum": "", "mirrors": [ @@ -4896,26 +5486,26 @@ ], "time": "2022-03-13T20:10:05+00:00" }, - { - "name": "symfony/string", - "version": "v6.0.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/string.git", - "reference": "522144f0c4c004c80d56fa47e40e17028e2eefc2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/522144f0c4c004c80d56fa47e40e17028e2eefc2", - "reference": "522144f0c4c004c80d56fa47e40e17028e2eefc2", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + { + "name": "symfony/string", + "version": "v6.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/string.git", + "reference": "ac0aa5c2282e0de624c175b68d13f2c8f2e2649d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/string/zipball/ac0aa5c2282e0de624c175b68d13f2c8f2e2649d", + "reference": "ac0aa5c2282e0de624c175b68d13f2c8f2e2649d", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { "php": ">=8.0.2", "symfony/polyfill-ctype": "~1.8", @@ -4969,7 +5559,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.0.3" + "source": "https://github.com/symfony/string/tree/v6.0.8" }, "funding": [ { @@ -4985,28 +5575,28 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:55:41+00:00" + "time": "2022-04-22T08:18:02+00:00" }, - { - "name": "symfony/translation", - "version": "v6.0.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/translation.git", - "reference": "b2792b39d74cf41ea3065f27fd2ddf0b556ac7a1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/b2792b39d74cf41ea3065f27fd2ddf0b556ac7a1", - "reference": "b2792b39d74cf41ea3065f27fd2ddf0b556ac7a1", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + { + "name": "symfony/translation", + "version": "v6.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "3d38cf8f8834148c4457681d539bc204de701501" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/3d38cf8f8834148c4457681d539bc204de701501", + "reference": "3d38cf8f8834148c4457681d539bc204de701501", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { "php": ">=8.0.2", "symfony/polyfill-mbstring": "~1.0", @@ -5070,7 +5660,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v6.0.7" + "source": "https://github.com/symfony/translation/tree/v6.0.8" }, "funding": [ { @@ -5086,7 +5676,7 @@ "type": "tidelift" } ], - "time": "2022-03-31T17:18:25+00:00" + "time": "2022-04-22T08:18:02+00:00" }, { "name": "symfony/translation-contracts", @@ -5429,25 +6019,90 @@ "php", "session" ], - "support": { - "docs": "https://hyperf.wiki", - "issues": "https://github.com/hyperf/hyperf/issues", - "pull-request": "https://github.com/hyperf/hyperf/pulls", - "source": "https://github.com/hyperf/hyperf" - }, - "time": "2022-04-03T10:50:03+00:00" + "support": { + "docs": "https://hyperf.wiki", + "issues": "https://github.com/hyperf/hyperf/issues", + "pull-request": "https://github.com/hyperf/hyperf/pulls", + "source": "https://github.com/hyperf/hyperf" + }, + "time": "2022-04-03T10:50:03+00:00" }, - { - "name": "myclabs/deep-copy", - "version": "1.11.0", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", + { + "name": "hyperf/validation", + "version": "v2.2.13", + "source": { + "type": "git", + "url": "https://github.com/hyperf/validation.git", + "reference": "6b7b22707a178018d55f15ce0a6ff5f31a54ec2b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hyperf/validation/zipball/6b7b22707a178018d55f15ce0a6ff5f31a54ec2b", + "reference": "6b7b22707a178018d55f15ce0a6ff5f31a54ec2b", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "egulias/email-validator": "^3.0", + "hyperf/contract": "~2.2.0", + "hyperf/database": "~2.2.0", + "hyperf/di": "~2.2.0", + "hyperf/framework": "~2.2.0", + "hyperf/http-server": "~2.2.0", + "hyperf/macroable": "~2.2.0", + "hyperf/translation": "~2.2.0", + "hyperf/utils": "~2.2.0", + "nesbot/carbon": "^2.21", + "php": ">=7.2", + "psr/container": "^1.0|^2.0", + "psr/event-dispatcher": "^1.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + }, + "hyperf": { + "config": "Hyperf\\Validation\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Hyperf\\Validation\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "hyperf validation", + "keywords": [ + "hyperf", + "validation" + ], + "support": { + "issues": "https://github.com/hyperf/validation/issues", + "source": "https://github.com/hyperf/validation/tree/v2.2.13" + }, + "time": "2021-10-25T01:29:21+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", "shasum": "", "mirrors": [ @@ -6339,19 +6994,19 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "e5e096c731d21614b952983804581389eb2a484f" + "reference": "576d0458fe9635731c50be2ed74febec4edc08d8" }, "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/e5e096c731d21614b952983804581389eb2a484f", - "reference": "e5e096c731d21614b952983804581389eb2a484f", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] + "type": "zip", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/576d0458fe9635731c50be2ed74febec4edc08d8", + "reference": "576d0458fe9635731c50be2ed74febec4edc08d8", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] }, "conflict": { "3f/pygmentize": "<1.2", @@ -6399,26 +7054,27 @@ "codeigniter4/framework": "<4.1.9", "codiad/codiad": "<=2.8.4", "composer/composer": "<1.10.26|>=2-alpha.1,<2.2.12|>=2.3,<2.3.5", - "concrete5/concrete5": "<9", - "concrete5/core": "<8.5.7", - "contao-components/mediaelement": ">=2.14.2,<2.21.1", - "contao/core": ">=2,<3.5.39", - "contao/core-bundle": "<4.9.18|>=4.10,<4.11.7|= 4.10.0", - "contao/listing-bundle": ">=4,<4.4.8", - "contao/managed-edition": "<=1.5", - "craftcms/cms": "<3.7.29", - "croogo/croogo": "<3.0.7", - "cuyz/valinor": ">=0.5,<0.7", - "datadog/dd-trace": ">=0.30,<0.30.2", - "david-garcia/phpwhois": "<=4.3.1", - "derhansen/sf_event_mgt": "<4.3.1|>=5,<5.1.1", - "directmailteam/direct-mail": "<5.2.4", - "doctrine/annotations": ">=1,<1.2.7", - "doctrine/cache": ">=1,<1.3.2|>=1.4,<1.4.2", - "doctrine/common": ">=2,<2.4.3|>=2.5,<2.5.1", - "doctrine/dbal": ">=2,<2.0.8|>=2.1,<2.1.2|>=3,<3.1.4", - "doctrine/doctrine-bundle": "<1.5.2", - "doctrine/doctrine-module": "<=0.7.1", + "concrete5/concrete5": "<9", + "concrete5/core": "<8.5.7", + "contao-components/mediaelement": ">=2.14.2,<2.21.1", + "contao/core": ">=2,<3.5.39", + "contao/core-bundle": "<4.9.18|>=4.10,<4.11.7|= 4.10.0", + "contao/listing-bundle": ">=4,<4.4.8", + "contao/managed-edition": "<=1.5", + "craftcms/cms": "<3.7.29", + "croogo/croogo": "<3.0.7", + "cuyz/valinor": ">=0.5,<0.7", + "czproject/git-php": "<4.0.3", + "datadog/dd-trace": ">=0.30,<0.30.2", + "david-garcia/phpwhois": "<=4.3.1", + "derhansen/sf_event_mgt": "<4.3.1|>=5,<5.1.1", + "directmailteam/direct-mail": "<5.2.4", + "doctrine/annotations": ">=1,<1.2.7", + "doctrine/cache": ">=1,<1.3.2|>=1.4,<1.4.2", + "doctrine/common": ">=2,<2.4.3|>=2.5,<2.5.1", + "doctrine/dbal": ">=2,<2.0.8|>=2.1,<2.1.2|>=3,<3.1.4", + "doctrine/doctrine-bundle": "<1.5.2", + "doctrine/doctrine-module": "<=0.7.1", "doctrine/mongodb-odm": ">=1,<1.0.2", "doctrine/mongodb-odm-bundle": ">=2,<3.0.1", "doctrine/orm": ">=2,<2.4.8|>=2.5,<2.5.1|>=2.8.3,<2.8.4", @@ -6441,26 +7097,27 @@ "ezsystems/ezplatform": "<=1.13.6|>=2,<=2.5.24", "ezsystems/ezplatform-admin-ui": ">=1.3,<1.3.5|>=1.4,<1.4.6|>=1.5,<1.5.27", "ezsystems/ezplatform-admin-ui-assets": ">=4,<4.2.1|>=5,<5.0.1|>=5.1,<5.1.1", - "ezsystems/ezplatform-kernel": "<=1.2.5|>=1.3,<1.3.12", - "ezsystems/ezplatform-rest": ">=1.2,<=1.2.2|>=1.3,<1.3.8", - "ezsystems/ezplatform-richtext": ">=2.3,<=2.3.7", - "ezsystems/ezplatform-user": ">=1,<1.0.1", - "ezsystems/ezpublish-kernel": "<=6.13.8.1|>=7,<7.5.26", - "ezsystems/ezpublish-legacy": "<=2017.12.7.3|>=2018.6,<=2019.3.5.1", - "ezsystems/platform-ui-assets-bundle": ">=4.2,<4.2.3", - "ezsystems/repository-forms": ">=2.3,<2.3.2.1", - "ezyang/htmlpurifier": "<4.1.1", - "facade/ignition": "<1.16.15|>=2,<2.4.2|>=2.5,<2.5.2", - "feehi/cms": "<=2.1.1", - "feehi/feehicms": "<=0.1.3", - "fenom/fenom": "<=2.12.1", - "firebase/php-jwt": "<2", - "flarum/core": ">=1,<=1.0.1", - "flarum/sticky": ">=0.1-beta.14,<=0.1-beta.15", - "flarum/tags": "<=0.1-beta.13", - "fluidtypo3/vhs": "<5.1.1", - "fooman/tcpdf": "<6.2.22", - "forkcms/forkcms": "<5.11.1", + "ezsystems/ezplatform-kernel": "<=1.2.5|>=1.3,<1.3.12", + "ezsystems/ezplatform-rest": ">=1.2,<=1.2.2|>=1.3,<1.3.8", + "ezsystems/ezplatform-richtext": ">=2.3,<=2.3.7", + "ezsystems/ezplatform-user": ">=1,<1.0.1", + "ezsystems/ezpublish-kernel": "<=6.13.8.1|>=7,<7.5.26", + "ezsystems/ezpublish-legacy": "<=2017.12.7.3|>=2018.6,<=2019.3.5.1", + "ezsystems/platform-ui-assets-bundle": ">=4.2,<4.2.3", + "ezsystems/repository-forms": ">=2.3,<2.3.2.1", + "ezyang/htmlpurifier": "<4.1.1", + "facade/ignition": "<1.16.15|>=2,<2.4.2|>=2.5,<2.5.2", + "facturascripts/facturascripts": "<2022.4", + "feehi/cms": "<=2.1.1", + "feehi/feehicms": "<=0.1.3", + "fenom/fenom": "<=2.12.1", + "firebase/php-jwt": "<2", + "flarum/core": ">=1,<=1.0.1", + "flarum/sticky": ">=0.1-beta.14,<=0.1-beta.15", + "flarum/tags": "<=0.1-beta.13", + "fluidtypo3/vhs": "<5.1.1", + "fooman/tcpdf": "<6.2.22", + "forkcms/forkcms": "<5.11.1", "fossar/tcpdf-parser": "<6.2.22", "francoisjacquet/rosariosis": "<8.1.1", "friendsofsymfony/oauth2-php": "<1.3", @@ -6643,27 +7300,27 @@ "silverstripe/graphql": "<3.5.2|>=4-alpha.1,<4-alpha.2|= 4.0.0-alpha1", "silverstripe/registry": ">=2.1,<2.1.2|>=2.2,<2.2.1", "silverstripe/restfulserver": ">=1,<1.0.9|>=2,<2.0.4", - "silverstripe/subsites": ">=2,<2.1.1", - "silverstripe/taxonomy": ">=1.3,<1.3.1|>=2,<2.0.1", - "silverstripe/userforms": "<3", - "simple-updates/phpwhois": "<=1", - "simplesamlphp/saml2": "<1.10.6|>=2,<2.3.8|>=3,<3.1.4", - "simplesamlphp/simplesamlphp": "<1.18.6", - "simplesamlphp/simplesamlphp-module-infocard": "<1.0.1", - "simplito/elliptic-php": "<1.0.6", - "slim/slim": "<2.6", - "smarty/smarty": "<3.1.43|>=4,<4.0.3", - "snipe/snipe-it": "<5.4.2|>= 6.0.0-RC-1, <= 6.0.0-RC-5", - "socalnick/scn-social-auth": "<1.15.2", - "socialiteproviders/steam": "<1.1", - "spipu/html2pdf": "<5.2.4", - "spoonity/tcpdf": "<6.2.22", - "squizlabs/php_codesniffer": ">=1,<2.8.1|>=3,<3.0.1", - "ssddanbrown/bookstack": "<22.2.3", - "statamic/cms": "<3.2.39|>=3.3,<3.3.2", - "stormpath/sdk": ">=0,<9.9.99", - "studio-42/elfinder": "<2.1.59", - "subrion/cms": "<=4.2.1", + "silverstripe/subsites": ">=2,<2.1.1", + "silverstripe/taxonomy": ">=1.3,<1.3.1|>=2,<2.0.1", + "silverstripe/userforms": "<3", + "simple-updates/phpwhois": "<=1", + "simplesamlphp/saml2": "<1.10.6|>=2,<2.3.8|>=3,<3.1.4", + "simplesamlphp/simplesamlphp": "<1.18.6", + "simplesamlphp/simplesamlphp-module-infocard": "<1.0.1", + "simplito/elliptic-php": "<1.0.6", + "slim/slim": "<2.6", + "smarty/smarty": "<3.1.43|>=4,<4.0.3", + "snipe/snipe-it": "<5.4.3|>= 6.0.0-RC-1, <= 6.0.0-RC-5", + "socalnick/scn-social-auth": "<1.15.2", + "socialiteproviders/steam": "<1.1", + "spipu/html2pdf": "<5.2.4", + "spoonity/tcpdf": "<6.2.22", + "squizlabs/php_codesniffer": ">=1,<2.8.1|>=3,<3.0.1", + "ssddanbrown/bookstack": "<22.2.3", + "statamic/cms": "<3.2.39|>=3.3,<3.3.2", + "stormpath/sdk": ">=0,<9.9.99", + "studio-42/elfinder": "<2.1.59", + "subrion/cms": "<=4.2.1", "sulu/sulu": "= 2.4.0-RC1|<1.6.44|>=2,<2.2.18|>=2.3,<2.3.8", "swiftmailer/swiftmailer": ">=4,<5.4.5", "sylius/admin-bundle": ">=1,<1.0.17|>=1.1,<1.1.9|>=1.2,<1.2.2", @@ -6820,7 +7477,7 @@ "type": "tidelift" } ], - "time": "2022-04-22T22:04:12+00:00" + "time": "2022-04-27T21:04:28+00:00" }, { "name": "sebastian/cli-parser", @@ -8011,7 +8668,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "~8.0" + "php": "~8.0", + "ext-redis": "^5.3" }, "platform-dev": [], "plugin-api-version": "2.1.0" diff --git a/src/Utils/Exceptions/Handler/ClassicHandler.php b/src/Utils/Exceptions/Handler/ClassicHandler.php new file mode 100644 index 0000000..17e7d84 --- /dev/null +++ b/src/Utils/Exceptions/Handler/ClassicHandler.php @@ -0,0 +1,302 @@ +stopPropagation(); + + $is_testing = config('app_status') === true; + $this->request?->url(); + + $is_debug = $this->request?->hasHeader('Postman-Token') + || $this->request?->header('User-Agent') === 'apifox/2.1.8 (https://www.apifox.cn)'; + + $error_type = get_class($throwable); + $request_time = date('Y-m-d H:i:s'); + $request_data = json_encode($this->request?->getParsedBody(), JSON_UNESCAPED_UNICODE); + $request_headers = json_encode($this->request?->getHeaders(), JSON_UNESCAPED_UNICODE); + + // 901 程序语法错误 + + // 902 SQL 语法错误 + if ($throwable instanceof QueryException) { + $code = CommonErrorCode::PROGRAM_SQL_ERROR; + if ($throwable->getCode() === '42S22') { + $code = CommonErrorCode::PROGRAM_SQL_COLUMN_NOT_FOUND; + } + $data = [ + 'code' => $code, + 'message' => CommonErrorCode::getMessage( + $is_testing + ? $code + : CommonErrorCode::PROGRAM_SQL_ERROR + ), + 'details' => $is_testing + ? [ + 'sql' => $throwable->getSql(), + 'error' => $throwable->getMessage(), + ] + : [], + ]; + } + + // 101 请求方式错误 + if ($throwable instanceof MethodNotAllowedHttpException) { + $message = explode(': ', $throwable->getMessage()); + $allow_method = explode(', ', $message[1]); + $code = CommonErrorCode::REQUEST_METHOD_ERROR; + $data = [ + 'code' => $code, + 'message' => CommonErrorCode::getMessage($code, [ + 'methods' => join(', ', $allow_method), + ]), + 'currentMethod' => $this->request?->getMethod(), + 'allowedMethod' => $allow_method, + ]; + } + + // 验证失败 + if ($throwable instanceof BadRequestHttpException) { + $data = [ + 'code' => CommonErrorCode::REQUEST_PARAMS_ERROR, + 'message' => $is_testing + ? $throwable->getMessage() + : CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR), + ]; + } + + if ($throwable instanceof ValidationException) { + $data = $throwable->validator->errors()->first(); + + if (is_numeric($data)) { + $code = (int)$data; + $data = CommonErrorCode::getMessage($data); + } + $data = [ + 'code' => $code ?? CommonErrorCode::REQUEST_PARAMS_ERROR, + 'message' => $data, + ]; + } + if ($throwable instanceof ValidateException) { + $code = $throwable->getCode(); + $data = [ + 'code' => $code, + 'message' => CommonErrorCode::getMessage($code, [ + 'param' => $throwable->getFieldName(), + ]), + ]; + if ($is_debug) { + $data['currentValue'] = $throwable->getCurrentValue(); + $data['availableValue'] = $throwable->getAvailableValue(); + } + } + + // 路由不存在 + if ($throwable instanceof NotFoundHttpException) { + $code = CommonErrorCode::ROUTE_NOT_FOUND; + $data = [ + 'code' => $code, + 'message' => CommonErrorCode::getMessage($code), + ]; + } + // 模型不存在 + if ($throwable instanceof ModelNotFoundException) { + $code = empty($throwable->getCode()) ? CommonErrorCode::MODEL_NOT_FOUND : $throwable->getCode(); + $message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, [ + 'resource' => '资源', + ]) : $throwable->getMessage(); + $data = [ + 'code' => $code, + 'message' => $message, + ]; + } + + // 未登录或验证失败 + if ($throwable instanceof Unauthorized) { + $invalidate_result = $this->authentication->invalid(); + $response = $response + ->withHeader( + Header::WWW_AUTHENTICATE, + join(' ', [ + $throwable->getAuthenticationType(), + 'realm="' . config('app_name') . '"', + 'charset="UTF-8"', + ]) + ); + switch (get_class($invalidate_result)) { + case Cookie::class: + $response = $response->withHeader( + 'Set-Cookie', + (string)$invalidate_result + ); + break; + default: + break; + } + } + + // 300 服务出错 + // 303 缓存异常 + if ($throwable instanceof RedisException) { + $code = CommonErrorCode::SERVER_CACHE_REDIS_ERROR; + if ($throwable->getMessage() === 'Connection refused') { + $code = CommonErrorCode::SERVER_CACHE_REDIS_REFUSED_ERROR; + } + $data = [ + 'code' => $code, + 'message' => CommonErrorCode::getMessage( + $is_testing + ? $code + : CommonErrorCode::SERVER_CACHE_REDIS_ERROR + ), + ]; + } + + if (empty($data)) { + // 其他情况 + $data = [ + 'code' => $is_testing + ? ($throwable->getCode() == 0 + ? CommonErrorCode::SERVER_ERROR + : $throwable->getCode()) + : CommonErrorCode::SERVER_ERROR, + 'message' => $is_testing ? $throwable->getMessage() : __( + CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR) + ), + ]; + + // 其他错误 + if ($throwable instanceof HttpException) { + $data = [ + 'code' => $throwable->getCode() ?? $throwable->getStatusCode(), + 'message' => $throwable->getMessage(), + ]; + } + } + + $response = $response->withHeader( + Header::CONTENT_TYPE, + 'application/json; charset=utf-8' + ); + + if ($is_debug && $is_testing) { + $data['trace'] = [ + 'errorType' => $error_type, + 'errorTrack' => $throwable->getTrace(), + ]; + } + $cookies = json_encode($this->request->getCookieParams(), JSON_UNESCAPED_UNICODE); + $this->logger->error( + <<getMessage()} +------------------------------- +REQUEST_TIME: $request_time +------------------------------- +REQUEST_HEADERS: +$request_headers +------------------------------- +REQUEST_COOKIES: +$cookies +------------------------------- +REQUEST_METHOD: +{$this->request?->getMethod()} +------------------------------- +REQUEST_URL: +{$this->request?->getUri()} +------------------------------- +REQUEST_QUERY: +{$this->request?->getQueryString()} +------------------------------- +REQUEST_DATA: +$request_data +------------------------------- +TRACE: +{$throwable->getTraceAsString()} +=============================== + +ERROR_LOG + ); + + $data['data'] ??= []; + $data = Json::encode($data); + + return $response + ->withBody( + new SwooleStream($data) + ); + } + + /** + * 判断该异常处理器是否要对该异常进行处理. + */ + public function isValid(Throwable $throwable): bool + { + return true; + } +} diff --git a/src/Utils/Exceptions/Handler/RestfulHandler.php b/src/Utils/Exceptions/Handler/RestfulHandler.php new file mode 100644 index 0000000..5c207c9 --- /dev/null +++ b/src/Utils/Exceptions/Handler/RestfulHandler.php @@ -0,0 +1,326 @@ +stopPropagation(); + + $is_testing = config('app_status') === true; + $this->request?->url(); + + $is_debug = $this->request?->hasHeader('Postman-Token') + || $this->request?->header('User-Agent') === 'apifox/2.1.8 (https://www.apifox.cn)'; + + $error_type = get_class($throwable); + $request_time = date('Y-m-d H:i:s'); + $request_data = json_encode($this->request?->getParsedBody(), JSON_UNESCAPED_UNICODE); + $request_headers = json_encode($this->request?->getHeaders(), JSON_UNESCAPED_UNICODE); + + // 901 程序语法错误 + + // 902 SQL 语法错误 + if ($throwable instanceof QueryException) { + $code = CommonErrorCode::PROGRAM_SQL_ERROR; + if ($throwable->getCode() === '42S22') { + $code = CommonErrorCode::PROGRAM_SQL_COLUMN_NOT_FOUND; + } + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage( + $is_testing + ? $code + : CommonErrorCode::PROGRAM_SQL_ERROR + ), + ]; + if ($is_testing) { + $data['details'] = [ + 'sql' => $throwable->getSql(), + 'error' => $throwable->getMessage(), + ]; + } + } + + // 101 请求方式错误 + if ($throwable instanceof MethodNotAllowedHttpException) { + $message = explode(': ', $throwable->getMessage()); + $allow_method = explode(', ', $message[1]); + $code = CommonErrorCode::REQUEST_METHOD_ERROR; + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage($code, [ + 'methods' => join(', ', $allow_method), + ]), + 'currentMethod' => $this->request?->getMethod(), + 'allowedMethod' => $allow_method, + ]; + } + + // 验证失败 + if ($throwable instanceof BadRequestHttpException) { + $data = [ + 'errorCode' => CommonErrorCode::REQUEST_PARAMS_ERROR, + 'errorMsg' => $is_testing + ? $throwable->getMessage() + : CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR), + ]; + } + + if ($throwable instanceof ValidationException) { + $data = $throwable->validator->errors()->first(); + + if (is_numeric($data)) { + $code = (int)$data; + $data = CommonErrorCode::getMessage($data); + } + $data = [ + 'errorCode' => $code ?? CommonErrorCode::REQUEST_PARAMS_ERROR, + 'errorMsg' => $data, + ]; + } + if ($throwable instanceof ValidateException) { + $code = $throwable->getCode(); + // $code = $is_testing ? $code : CommonErrorCode::REQUEST_PARAMS_ERROR; + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage($code, [ + 'param' => $throwable->getFieldName(), + ]), + ]; + if ($is_debug) { + $data['currentValue'] = $throwable->getCurrentValue(); + $data['availableValue'] = $throwable->getAvailableValue(); + } + } + + // 路由不存在 + if ($throwable instanceof NotFoundHttpException) { + $code = CommonErrorCode::ROUTE_NOT_FOUND; + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage($code), + ]; + $status_code = 404; + } + // 模型不存在 + if ($throwable instanceof ModelNotFoundException) { + $code = empty($throwable->getCode()) ? CommonErrorCode::MODEL_NOT_FOUND : $throwable->getCode(); + $message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, [ + 'resource' => '资源', + ]) : $throwable->getMessage(); + $data = [ + 'errorCode' => $code, + 'errorMsg' => $message, + ]; + $status_code = 404; + } + + // 未登录或验证失败 + if ($throwable instanceof Unauthorized) { + $invalidate_result = $this->tokenService->invalid(); + $response = $response + ->withHeader( + Header::WWW_AUTHENTICATE, + join(' ', [ + $throwable->getAuthenticationType(), + 'realm="' . config('app_name') . '"', + 'charset="UTF-8"', + ]) + ); + switch (get_class($invalidate_result)) { + case Cookie::class: + $response = $response->withHeader( + 'Set-Cookie', + (string)$invalidate_result + ); + break; + default: + break; + } + } + + // 300 服务出错 + // 303 缓存异常 + if ($throwable instanceof RedisException) { + $code = CommonErrorCode::SERVER_CACHE_REDIS_ERROR; + if ($throwable->getMessage() === 'Connection refused') { + $code = CommonErrorCode::SERVER_CACHE_REDIS_REFUSED_ERROR; + } + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage( + $is_testing + ? $code + : CommonErrorCode::SERVER_CACHE_REDIS_ERROR + ), + ]; + } + + // 306 消息异常 + // 30601 邮箱发件异常 + if ($throwable instanceof TransportException) { + $code = CommonErrorCode::SERVER_MESSAGE_EMAIL_ERROR; + if (strpos($throwable->getMessage(), '500 Error: bad syntax')) { + $code = CommonErrorCode::SERVER_MESSAGE_EMAIL_NOT_FOUND; + } + $data = [ + 'errorCode' => $code, + 'errorMsg' => CommonErrorCode::getMessage( + $is_testing + ? $code + : CommonErrorCode::SERVER_MESSAGE_EMAIL_ERROR + ), + ]; + } + + if (empty($data)) { + // 其他情况 + $data = [ + 'errorCode' => $is_testing + ? ($throwable->getCode() == 0 + ? CommonErrorCode::SERVER_ERROR + : $throwable->getCode()) + : CommonErrorCode::SERVER_ERROR, + 'errorMsg' => $is_testing ? $throwable->getMessage() : __( + CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR) + ), + ]; + + // 其他错误 + if ($throwable instanceof HttpException) { + $data = [ + 'errorCode' => $throwable->getCode() ?? $throwable->getStatusCode(), + 'errorMsg' => $throwable->getMessage(), + ]; + } + } + + $response = $response->withHeader( + Header::CONTENT_TYPE, + 'application/json; charset=utf-8' + ); + + if ($is_debug && $is_testing) { + $data['trace'] = [ + 'errorType' => $error_type, + 'errorTrack' => $throwable->getTrace(), + ]; + } + $cookies = json_encode($this->request->getCookieParams(), JSON_UNESCAPED_UNICODE); + $this->logger->error( + <<getMessage()} +------------------------------- +REQUEST_TIME: $request_time +------------------------------- +REQUEST_HEADERS: +$request_headers +------------------------------- +REQUEST_COOKIES: +$cookies +------------------------------- +REQUEST_METHOD: +{$this->request?->getMethod()} +------------------------------- +REQUEST_URL: +{$this->request?->getUri()} +------------------------------- +REQUEST_QUERY: +{$this->request?->getQueryString()} +------------------------------- +REQUEST_DATA: +$request_data +------------------------------- +TRACE: +{$throwable->getTraceAsString()} +=============================== + +ERROR_LOG + ); + $data = json_encode($data, JSON_UNESCAPED_UNICODE); + + // 交给下一个异常处理器 + return $response + ->withStatus( + $status_code ?? + $throwable->status ?? + $throwable->statusCode ?? + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR + ) + ->withBody( + new SwooleStream($data) + ); + // 或者不做处理直接屏蔽异常 + } + + /** + * 判断该异常处理器是否要对该异常进行处理. + */ + public function isValid(Throwable $throwable): bool + { + return true; + } +}