From 2341f068d34a7b4a7438d9d4bf55f4ea6a0b9095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Wed, 3 Jul 2019 13:55:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=80=E4=BA=9B=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=87=8F=E5=B0=91=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=AF=B9lumen=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.lock | 783 +++++++++++++------ src/Client.php | 30 +- src/Providers/BaseServiceProvider.php | 21 +- src/Providers/ClientServiceProvider.php | 6 +- src/Providers/LumenServerServiceProvider.php | 1 + src/Server/JsonRpcServer.php | 65 +- tests/publish.php | 25 + tests/sub.php | 19 +- 8 files changed, 671 insertions(+), 279 deletions(-) create mode 100644 tests/publish.php diff --git a/composer.lock b/composer.lock index b9f492b..2d3d847 100644 --- a/composer.lock +++ b/composer.lock @@ -1,7 +1,7 @@ { "_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#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "fb453b0071e663c4a9de3793bf7aad24", @@ -209,16 +209,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.5.2", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "9f83dded91781a01c63574e387eaa769be769115" + "reference": "dc784032a3f6f4e7a4b882e272b771f6fe4c37cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", - "reference": "9f83dded91781a01c63574e387eaa769be769115", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/dc784032a3f6f4e7a4b882e272b771f6fe4c37cf", + "reference": "dc784032a3f6f4e7a4b882e272b771f6fe4c37cf", "shasum": "", "mirrors": [ { @@ -230,18 +230,22 @@ "require": { "php": ">=5.4.0", "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5" + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { + "ext-zlib": "*", "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -278,20 +282,20 @@ "uri", "url" ], - "time": "2018-12-04T20:46:45+00:00" + "time": "2019-06-30T00:37:05+00:00" }, { "name": "illuminate/contracts", - "version": "v5.7.26", + "version": "v5.8.24", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", - "reference": "b63324d349a8ae2156fbc2697c1ccc85879b3803" + "reference": "33b4e0ffb89eb2216c764235c9e95fed1f3fab82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/b63324d349a8ae2156fbc2697c1ccc85879b3803", - "reference": "b63324d349a8ae2156fbc2697c1ccc85879b3803", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/33b4e0ffb89eb2216c764235c9e95fed1f3fab82", + "reference": "33b4e0ffb89eb2216c764235c9e95fed1f3fab82", "shasum": "", "mirrors": [ { @@ -308,7 +312,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7-dev" + "dev-master": "5.8-dev" } }, "autoload": { @@ -328,20 +332,20 @@ ], "description": "The Illuminate Contracts package.", "homepage": "https://laravel.com", - "time": "2019-02-12T07:46:48+00:00" + "time": "2019-06-11T14:00:26+00:00" }, { "name": "illuminate/filesystem", - "version": "v5.7.26", + "version": "v5.8.24", "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", - "reference": "ff853e678a93996b1d0a3ddc6fc56c10bae0de30" + "reference": "3934079a1a68d81084c12b82e962cb23555f4b2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/filesystem/zipball/ff853e678a93996b1d0a3ddc6fc56c10bae0de30", - "reference": "ff853e678a93996b1d0a3ddc6fc56c10bae0de30", + "url": "https://api.github.com/repos/illuminate/filesystem/zipball/3934079a1a68d81084c12b82e962cb23555f4b2e", + "reference": "3934079a1a68d81084c12b82e962cb23555f4b2e", "shasum": "", "mirrors": [ { @@ -351,10 +355,10 @@ ] }, "require": { - "illuminate/contracts": "5.7.*", - "illuminate/support": "5.7.*", + "illuminate/contracts": "5.8.*", + "illuminate/support": "5.8.*", "php": "^7.1.3", - "symfony/finder": "^4.1" + "symfony/finder": "^4.2" }, "suggest": { "league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).", @@ -366,7 +370,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7-dev" + "dev-master": "5.8-dev" } }, "autoload": { @@ -386,20 +390,20 @@ ], "description": "The Illuminate Filesystem package.", "homepage": "https://laravel.com", - "time": "2019-02-11T13:48:57+00:00" + "time": "2019-06-04T14:33:55+00:00" }, { "name": "illuminate/http", - "version": "v5.7.26", + "version": "v5.8.24", "source": { "type": "git", "url": "https://github.com/illuminate/http.git", - "reference": "279984eed495fc19a5649e4e8f57c5076e406f0a" + "reference": "597fd8923080117cda4af2aa878e88cef5624840" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/http/zipball/279984eed495fc19a5649e4e8f57c5076e406f0a", - "reference": "279984eed495fc19a5649e4e8f57c5076e406f0a", + "url": "https://api.github.com/repos/illuminate/http/zipball/597fd8923080117cda4af2aa878e88cef5624840", + "reference": "597fd8923080117cda4af2aa878e88cef5624840", "shasum": "", "mirrors": [ { @@ -409,16 +413,17 @@ ] }, "require": { - "illuminate/session": "5.7.*", - "illuminate/support": "5.7.*", + "ext-json": "*", + "illuminate/session": "5.8.*", + "illuminate/support": "5.8.*", "php": "^7.1.3", - "symfony/http-foundation": "^4.1", - "symfony/http-kernel": "^4.1" + "symfony/http-foundation": "^4.2", + "symfony/http-kernel": "^4.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7-dev" + "dev-master": "5.8-dev" } }, "autoload": { @@ -438,20 +443,20 @@ ], "description": "The Illuminate Http package.", "homepage": "https://laravel.com", - "time": "2019-02-11T13:48:57+00:00" + "time": "2019-06-11T19:01:45+00:00" }, { "name": "illuminate/session", - "version": "v5.7.26", + "version": "v5.8.24", "source": { "type": "git", "url": "https://github.com/illuminate/session.git", - "reference": "0d1233ea455b9ad50112212022ca3bcff874fa86" + "reference": "762eadf940439344a34acdcf2c31efd0deb9b9ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/session/zipball/0d1233ea455b9ad50112212022ca3bcff874fa86", - "reference": "0d1233ea455b9ad50112212022ca3bcff874fa86", + "url": "https://api.github.com/repos/illuminate/session/zipball/762eadf940439344a34acdcf2c31efd0deb9b9ac", + "reference": "762eadf940439344a34acdcf2c31efd0deb9b9ac", "shasum": "", "mirrors": [ { @@ -461,20 +466,21 @@ ] }, "require": { - "illuminate/contracts": "5.7.*", - "illuminate/filesystem": "5.7.*", - "illuminate/support": "5.7.*", + "ext-json": "*", + "illuminate/contracts": "5.8.*", + "illuminate/filesystem": "5.8.*", + "illuminate/support": "5.8.*", "php": "^7.1.3", - "symfony/finder": "^4.1", - "symfony/http-foundation": "^4.1" + "symfony/finder": "^4.2", + "symfony/http-foundation": "^4.2" }, "suggest": { - "illuminate/console": "Required to use the session:table command (5.7.*)." + "illuminate/console": "Required to use the session:table command (5.8.*)." }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7-dev" + "dev-master": "5.8-dev" } }, "autoload": { @@ -494,20 +500,20 @@ ], "description": "The Illuminate Session package.", "homepage": "https://laravel.com", - "time": "2019-02-11T13:48:57+00:00" + "time": "2019-06-05T13:03:53+00:00" }, { "name": "illuminate/support", - "version": "v5.7.26", + "version": "v5.8.24", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "3e2810145f37eb89fa11759781ee88ee1c1a5262" + "reference": "b05653f5ecce996734d3facd06a81aff504b6a2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/3e2810145f37eb89fa11759781ee88ee1c1a5262", - "reference": "3e2810145f37eb89fa11759781ee88ee1c1a5262", + "url": "https://api.github.com/repos/illuminate/support/zipball/b05653f5ecce996734d3facd06a81aff504b6a2f", + "reference": "b05653f5ecce996734d3facd06a81aff504b6a2f", "shasum": "", "mirrors": [ { @@ -518,25 +524,27 @@ }, "require": { "doctrine/inflector": "^1.1", + "ext-json": "*", "ext-mbstring": "*", - "illuminate/contracts": "5.7.*", - "nesbot/carbon": "^1.26.3", + "illuminate/contracts": "5.8.*", + "nesbot/carbon": "^1.26.3 || ^2.0", "php": "^7.1.3" }, "conflict": { "tightenco/collect": "<5.5.33" }, "suggest": { - "illuminate/filesystem": "Required to use the composer class (5.7.*).", + "illuminate/filesystem": "Required to use the composer class (5.8.*).", "moontoast/math": "Required to use ordered UUIDs (^1.1).", "ramsey/uuid": "Required to use Str::uuid() (^3.7).", - "symfony/process": "Required to use the composer class (^4.1).", - "symfony/var-dumper": "Required to use the dd function (^4.1)." + "symfony/process": "Required to use the composer class (^4.2).", + "symfony/var-dumper": "Required to use the dd function (^4.2).", + "vlucas/phpdotenv": "Required to use the env helper (^3.3)." }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7-dev" + "dev-master": "5.8-dev" } }, "autoload": { @@ -559,20 +567,20 @@ ], "description": "The Illuminate Support package.", "homepage": "https://laravel.com", - "time": "2019-02-12T07:57:07+00:00" + "time": "2019-06-19T14:12:17+00:00" }, { "name": "influxdb/influxdb-php", - "version": "1.14.7", + "version": "1.15.0", "source": { "type": "git", "url": "https://github.com/influxdata/influxdb-php.git", - "reference": "570bd5cdedb9b1c1628dceea5785bc40e08f7e48" + "reference": "bf3415f81962e1ab8c939bc1a08a85f500bead35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/570bd5cdedb9b1c1628dceea5785bc40e08f7e48", - "reference": "570bd5cdedb9b1c1628dceea5785bc40e08f7e48", + "url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/bf3415f81962e1ab8c939bc1a08a85f500bead35", + "reference": "bf3415f81962e1ab8c939bc1a08a85f500bead35", "shasum": "", "mirrors": [ { @@ -589,6 +597,7 @@ "phpunit/phpunit": "^5.7" }, "suggest": { + "ext-curl": "Curl extension, needed for Curl driver", "stefanotorresi/influxdb-php-async": "An asyncronous client for InfluxDB, implemented via ReactPHP." }, "type": "library", @@ -625,7 +634,7 @@ "influxdb library", "time series" ], - "time": "2018-07-06T10:13:39+00:00" + "time": "2019-05-30T00:15:14+00:00" }, { "name": "itxq/api-doc-php", @@ -742,16 +751,16 @@ }, { "name": "nesbot/carbon", - "version": "1.36.2", + "version": "2.20.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9" + "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", - "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bc671b896c276795fad8426b0aa24e8ade0f2498", + "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498", "shasum": "", "mirrors": [ { @@ -761,15 +770,17 @@ ] }, "require": { - "php": ">=5.3.9", - "symfony/translation": "~2.6 || ~3.0 || ~4.0" + "ext-json": "*", + "php": "^7.1.8 || ^8.0", + "symfony/translation": "^3.4 || ^4.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7" - }, - "suggest": { - "friendsofphp/php-cs-fixer": "Needed for the `composer phpcs` command. Allow to automatically fix code style.", - "phpstan/phpstan": "Needed for the `composer phpstan` command. Allow to detect potential errors." + "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "kylekatarnls/multi-tester": "^1.1", + "phpmd/phpmd": "^2.6", + "phpstan/phpstan": "^0.11", + "phpunit/phpunit": "^7.5 || ^8.0", + "squizlabs/php_codesniffer": "^3.4" }, "type": "library", "extra": { @@ -781,7 +792,7 @@ }, "autoload": { "psr-4": { - "": "src/" + "Carbon\\": "src/Carbon/" } }, "notification-url": "https://packagist.org/downloads/", @@ -802,7 +813,7 @@ "datetime", "time" ], - "time": "2018-12-28T10:07:33+00:00" + "time": "2019-06-25T10:00:57+00:00" }, { "name": "psr/container", @@ -1024,16 +1035,16 @@ }, { "name": "ralouphie/getallheaders", - "version": "2.0.5", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + "reference": "120b605dfeb996808c31b6477290a714d356e822" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", "shasum": "", "mirrors": [ { @@ -1043,11 +1054,11 @@ ] }, "require": { - "php": ">=5.3" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "~3.7.0", - "satooshi/php-coveralls": ">=1.0" + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" }, "type": "library", "autoload": { @@ -1066,94 +1077,20 @@ } ], "description": "A polyfill for getallheaders.", - "time": "2016-02-11T07:05:27+00:00" - }, - { - "name": "symfony/contracts", - "version": "v1.0.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/contracts.git", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "shasum": "", - "mirrors": [ - { - "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", - "preferred": true - } - ] - }, - "require": { - "php": "^7.1.3" - }, - "require-dev": { - "psr/cache": "^1.0", - "psr/container": "^1.0" - }, - "suggest": { - "psr/cache": "When using the Cache contracts", - "psr/container": "When using the Service contracts", - "symfony/cache-contracts-implementation": "", - "symfony/service-contracts-implementation": "", - "symfony/translation-contracts-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\": "" - }, - "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": "A set of abstractions extracted out of the Symfony components", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2018-12-05T08:06:11+00:00" + "time": "2019-03-08T08:55:37+00:00" }, { "name": "symfony/debug", - "version": "v4.2.3", + "version": "v4.3.2", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "cf9b2e33f757deb884ce474e06d2647c1c769b65" + "reference": "d8f4fb38152e0eb6a433705e5f661d25b32c5fcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/cf9b2e33f757deb884ce474e06d2647c1c769b65", - "reference": "cf9b2e33f757deb884ce474e06d2647c1c769b65", + "url": "https://api.github.com/repos/symfony/debug/zipball/d8f4fb38152e0eb6a433705e5f661d25b32c5fcd", + "reference": "d8f4fb38152e0eb6a433705e5f661d25b32c5fcd", "shasum": "", "mirrors": [ { @@ -1175,7 +1112,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1202,20 +1139,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2019-01-25T14:35:16+00:00" + "time": "2019-06-19T15:27:09+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v4.2.3", + "version": "v4.3.2", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "bd09ad265cd50b2b9d09d65ce6aba2d29bc81fe1" + "reference": "d257021c1ab28d48d24a16de79dfab445ce93398" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/bd09ad265cd50b2b9d09d65ce6aba2d29bc81fe1", - "reference": "bd09ad265cd50b2b9d09d65ce6aba2d29bc81fe1", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d257021c1ab28d48d24a16de79dfab445ce93398", + "reference": "d257021c1ab28d48d24a16de79dfab445ce93398", "shasum": "", "mirrors": [ { @@ -1226,16 +1163,22 @@ }, "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0" + "symfony/event-dispatcher-contracts": "^1.1" }, "conflict": { "symfony/dependency-injection": "<3.4" }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "1.1" + }, "require-dev": { "psr/log": "~1.0", "symfony/config": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/expression-language": "~3.4|~4.0", + "symfony/http-foundation": "^3.4|^4.0", + "symfony/service-contracts": "^1.1", "symfony/stopwatch": "~3.4|~4.0" }, "suggest": { @@ -1245,7 +1188,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1272,20 +1215,84 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2019-01-16T20:35:37+00:00" + "time": "2019-06-13T11:03:18+00:00" }, { - "name": "symfony/finder", - "version": "v4.2.3", + "name": "symfony/event-dispatcher-contracts", + "version": "v1.1.5", "source": { "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "ef71816cbb264988bb57fe6a73f610888b9aa70c" + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "c61766f4440ca687de1084a5c00b08e167a2575c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/ef71816cbb264988bb57fe6a73f610888b9aa70c", - "reference": "ef71816cbb264988bb57fe6a73f610888b9aa70c", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/c61766f4440ca687de1084a5c00b08e167a2575c", + "reference": "c61766f4440ca687de1084a5c00b08e167a2575c", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1.3" + }, + "suggest": { + "psr/event-dispatcher": "", + "symfony/event-dispatcher-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "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" + ], + "time": "2019-06-20T06:46:26+00:00" + }, + { + "name": "symfony/finder", + "version": "v4.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "33c21f7d5d3dc8a140c282854a7e13aeb5d0f91a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/33c21f7d5d3dc8a140c282854a7e13aeb5d0f91a", + "reference": "33c21f7d5d3dc8a140c282854a7e13aeb5d0f91a", "shasum": "", "mirrors": [ { @@ -1300,7 +1307,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1327,20 +1334,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-01-16T20:35:37+00:00" + "time": "2019-06-13T11:03:18+00:00" }, { "name": "symfony/http-foundation", - "version": "v4.2.3", + "version": "v4.3.2", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39" + "reference": "e1b507fcfa4e87d192281774b5ecd4265370180d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/8d2318b73e0a1bc75baa699d00ebe2ae8b595a39", - "reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/e1b507fcfa4e87d192281774b5ecd4265370180d", + "reference": "e1b507fcfa4e87d192281774b5ecd4265370180d", "shasum": "", "mirrors": [ { @@ -1351,6 +1358,7 @@ }, "require": { "php": "^7.1.3", + "symfony/mime": "^4.3", "symfony/polyfill-mbstring": "~1.1" }, "require-dev": { @@ -1360,7 +1368,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1387,20 +1395,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2019-01-29T09:49:29+00:00" + "time": "2019-06-26T09:25:00+00:00" }, { "name": "symfony/http-kernel", - "version": "v4.2.3", + "version": "v4.3.2", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "d56b1706abaa771eb6acd894c6787cb88f1dc97d" + "reference": "4150f71e27ed37a74700561b77e3dbd754cbb44d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/d56b1706abaa771eb6acd894c6787cb88f1dc97d", - "reference": "d56b1706abaa771eb6acd894c6787cb88f1dc97d", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/4150f71e27ed37a74700561b77e3dbd754cbb44d", + "reference": "4150f71e27ed37a74700561b77e3dbd754cbb44d", "shasum": "", "mirrors": [ { @@ -1412,15 +1420,16 @@ "require": { "php": "^7.1.3", "psr/log": "~1.0", - "symfony/contracts": "^1.0.2", "symfony/debug": "~3.4|~4.0", - "symfony/event-dispatcher": "~4.1", + "symfony/event-dispatcher": "^4.3", "symfony/http-foundation": "^4.1.1", - "symfony/polyfill-ctype": "~1.8" + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php73": "^1.9" }, "conflict": { + "symfony/browser-kit": "<4.3", "symfony/config": "<3.4", - "symfony/dependency-injection": "<4.2", + "symfony/dependency-injection": "<4.3", "symfony/translation": "<4.2", "symfony/var-dumper": "<4.1.1", "twig/twig": "<1.34|<2.4,>=2" @@ -1430,11 +1439,11 @@ }, "require-dev": { "psr/cache": "~1.0", - "symfony/browser-kit": "~3.4|~4.0", + "symfony/browser-kit": "^4.3", "symfony/config": "~3.4|~4.0", "symfony/console": "~3.4|~4.0", "symfony/css-selector": "~3.4|~4.0", - "symfony/dependency-injection": "^4.2", + "symfony/dependency-injection": "^4.3", "symfony/dom-crawler": "~3.4|~4.0", "symfony/expression-language": "~3.4|~4.0", "symfony/finder": "~3.4|~4.0", @@ -1443,7 +1452,9 @@ "symfony/stopwatch": "~3.4|~4.0", "symfony/templating": "~3.4|~4.0", "symfony/translation": "~4.2", - "symfony/var-dumper": "^4.1.1" + "symfony/translation-contracts": "^1.1", + "symfony/var-dumper": "^4.1.1", + "twig/twig": "^1.34|^2.4" }, "suggest": { "symfony/browser-kit": "", @@ -1455,7 +1466,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1482,20 +1493,85 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2019-02-03T12:47:33+00:00" + "time": "2019-06-26T14:26:16+00:00" }, { - "name": "symfony/polyfill-ctype", - "version": "v1.10.0", + "name": "symfony/mime", + "version": "v4.3.2", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "url": "https://github.com/symfony/mime.git", + "reference": "ec2c5565de60e03f33d4296a655e3273f0ad1f8b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/symfony/mime/zipball/ec2c5565de60e03f33d4296a655e3273f0ad1f8b", + "reference": "ec2c5565de60e03f33d4296a655e3273f0ad1f8b", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-intl-idn": "^1.10", + "symfony/polyfill-mbstring": "^1.0" + }, + "require-dev": { + "egulias/email-validator": "^2.0", + "symfony/dependency-injection": "~3.4|^4.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "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": "A library to manipulate MIME messages", + "homepage": "https://symfony.com", + "keywords": [ + "mime", + "mime-type" + ], + "time": "2019-06-04T09:22:54+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.11.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "82ebae02209c21113908c229e9883c419720738a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", "shasum": "", "mirrors": [ { @@ -1513,7 +1589,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.11-dev" } }, "autoload": { @@ -1535,7 +1611,7 @@ }, { "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "email": "BackEndTea@gmail.com" } ], "description": "Symfony polyfill for ctype functions", @@ -1546,20 +1622,88 @@ "polyfill", "portable" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2019-02-06T07:57:58+00:00" }, { - "name": "symfony/polyfill-mbstring", - "version": "v1.10.0", + "name": "symfony/polyfill-intl-idn", + "version": "v1.11.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "c766e95bec706cdd89903b1eda8afab7d7a6b7af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/c766e95bec706cdd89903b1eda8afab7d7a6b7af", + "reference": "c766e95bec706cdd89903b1eda8afab7d7a6b7af", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php72": "^1.9" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + } + ], + "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" + ], + "time": "2019-03-04T13:44:35+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.11.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", + "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", "shasum": "", "mirrors": [ { @@ -1577,7 +1721,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.11-dev" } }, "autoload": { @@ -1611,20 +1755,145 @@ "portable", "shim" ], - "time": "2018-09-21T13:07:52+00:00" + "time": "2019-02-06T07:57:58+00:00" }, { - "name": "symfony/translation", - "version": "v4.2.3", + "name": "symfony/polyfill-php72", + "version": "v1.11.0", "source": { "type": "git", - "url": "https://github.com/symfony/translation.git", - "reference": "23fd7aac70d99a17a8e6473a41fec8fab3331050" + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "ab50dcf166d5f577978419edd37aa2bb8eabce0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/23fd7aac70d99a17a8e6473a41fec8fab3331050", - "reference": "23fd7aac70d99a17a8e6473a41fec8fab3331050", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/ab50dcf166d5f577978419edd37aa2bb8eabce0c", + "reference": "ab50dcf166d5f577978419edd37aa2bb8eabce0c", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.11-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": "2019-02-06T07:57:58+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.11.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "d1fb4abcc0c47be136208ad9d68bf59f1ee17abd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/d1fb4abcc0c47be136208ad9d68bf59f1ee17abd", + "reference": "d1fb4abcc0c47be136208ad9d68bf59f1ee17abd", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.11-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "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.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-02-06T07:57:58+00:00" + }, + { + "name": "symfony/translation", + "version": "v4.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "934ab1d18545149e012aa898cf02e9f23790f7a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/934ab1d18545149e012aa898cf02e9f23790f7a0", + "reference": "934ab1d18545149e012aa898cf02e9f23790f7a0", "shasum": "", "mirrors": [ { @@ -1635,8 +1904,8 @@ }, "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0.2", - "symfony/polyfill-mbstring": "~1.0" + "symfony/polyfill-mbstring": "~1.0", + "symfony/translation-contracts": "^1.1.2" }, "conflict": { "symfony/config": "<3.4", @@ -1644,7 +1913,7 @@ "symfony/yaml": "<3.4" }, "provide": { - "symfony/translation-contracts-implementation": "1.0" + "symfony/translation-implementation": "1.0" }, "require-dev": { "psr/log": "~1.0", @@ -1652,7 +1921,10 @@ "symfony/console": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", + "symfony/http-kernel": "~3.4|~4.0", "symfony/intl": "~3.4|~4.0", + "symfony/service-contracts": "^1.1.2", + "symfony/var-dumper": "~3.4|~4.0", "symfony/yaml": "~3.4|~4.0" }, "suggest": { @@ -1663,7 +1935,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1690,7 +1962,70 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2019-01-27T23:11:39+00:00" + "time": "2019-06-13T11:03:18+00:00" + }, + { + "name": "symfony/translation-contracts", + "version": "v1.1.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation-contracts.git", + "reference": "cb4b18ad7b92a26e83b65dde940fab78339e6f3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/cb4b18ad7b92a26e83b65dde940fab78339e6f3c", + "reference": "cb4b18ad7b92a26e83b65dde940fab78339e6f3c", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1.3" + }, + "suggest": { + "symfony/translation-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Translation\\": "" + } + }, + "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 translation", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-06-13T11:15:36+00:00" } ], "packages-dev": [], diff --git a/src/Client.php b/src/Client.php index 304b9a1..165995b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,6 +7,7 @@ use JsonRpc\Exception\RpcServerException; use JsonRpc\Server\JsonRpcBase; use Monolog\Handler\StreamHandler; use Monolog\Logger; +use Psr\Log\LoggerInterface; class Client extends JsonRpc { @@ -27,6 +28,11 @@ class Client extends JsonRpc */ protected $http; + /** + * @var LoggerInterface + */ + protected $logger; + /** * which server rpc call choose * @var array @@ -39,6 +45,11 @@ class Client extends JsonRpc $this->id = 1; } + public function setLogger($logger) + { + $this->logger = $logger; + } + /** * * @param $k @@ -60,6 +71,7 @@ class Client extends JsonRpc /** * @param $name * @param $arguments + * @param $options [] * @throws RpcServerException * @return array */ @@ -92,21 +104,23 @@ class Client extends JsonRpc */ protected function post($payload, $options = []) { - $uri = 'rpc/json-rpc-v2.json?app='.$this->config['app']; + $uri = 'rpc/json-rpc-v2.json?app=' . $this->config['app']; + + $requestId = isset($_SERVER['HTTP_X_REQUEST_ID']) ? $_SERVER['HTTP_X_REQUEST_ID'] : 'nginx-config-err'; + try { $headers = [ 'X-Client-App' => $this->config['app'], - 'X-Request-Id' => app('request')->header('X-Request-Id') + 'X-Request-Id' => $requestId, ]; - app('rpc.logger')->info("client_request", array_merge($this->server_config, $payload)); + $this->logger && $this->logger->info("client_request", array_merge($this->server_config, $payload)); $resp = $this->http->request('POST', $uri, array_merge([ 'headers' => $headers, 'json' => $payload, ], $options)); } catch (ServerException $e) { $ex = new RpcServerException(self::ErrorMsg[JsonRpc::Rpc_Error_Internal_Error], JsonRpc::Rpc_Error_Internal_Error); - if (env("APP_DEBUG") == true) { - $resp = $e->getResponse(); + if (function_exists('env') && env("APP_DEBUG") == true) { $ex->setResponse($e->getResponse()); } throw $ex; @@ -114,7 +128,7 @@ class Client extends JsonRpc try { $body = \GuzzleHttp\json_decode($resp->getBody(), true); - app('rpc.logger')->info("client_response", $body); + $this->logger && $this->logger->info("client_response", $body); if (empty($body)) { throw new RpcServerException('http response empty', JsonRpc::Rpc_Error_System_Error); } @@ -127,9 +141,9 @@ class Client extends JsonRpc return $body['result']; } catch (\InvalidArgumentException $e) { - app('rpc.logger')->error('client_decode_error', array_merge($this->server_config, $payload)); + $this->logger && $this->logger->error('client_decode_error', array_merge($this->server_config, $payload)); $ex = new RpcServerException($e->getMessage(), JsonRpc::Rpc_Error_Parse_Error); - if (env("APP_DEBUG") == true) { + if (function_exists('env') && env("APP_DEBUG") == true) { $ex->setResponse($resp); } throw $ex; diff --git a/src/Providers/BaseServiceProvider.php b/src/Providers/BaseServiceProvider.php index 38f9db5..dad526f 100644 --- a/src/Providers/BaseServiceProvider.php +++ b/src/Providers/BaseServiceProvider.php @@ -11,7 +11,10 @@ use Monolog\Logger; class BaseServiceProvider extends ServiceProvider { - public function boot(){ + protected $logger; + + public function boot() + { Request::setTrustedProxies([ //pod network '172.20.0.0/16', @@ -29,7 +32,7 @@ class BaseServiceProvider extends ServiceProvider protected function setupConfig() { $source = realpath(__DIR__ . '/../../config/rpc.php'); - $this->app->configure('rpc'); + $this->app->configure('rpc'); // if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { // $this->publishes([$source => config_path('rpc.php')], 'rpc'); // } elseif ($this->app instanceof LumenApplication) { @@ -38,19 +41,17 @@ class BaseServiceProvider extends ServiceProvider // var_dump($this->app instanceof LumenApplication); // false // exit(); $this->mergeConfigFrom($source, 'rpc'); - + } public function register() { $this->setupConfig(); - $this->app->singleton("rpc.logger", function () { - $config = config('rpc'); - $stream = new StreamHandler($config['log_path']); - $stream->setFormatter(new $config['log_formatter']()); - $logger = new Logger('RPC.LOGGER'); - return $logger->pushHandler($stream); - }); + $this->logger = new Logger('RPC.LOGGER'); + $config = config('rpc'); + $stream = new StreamHandler($config['log_path']); + $stream->setFormatter(new $config['log_formatter']()); + $this->logger->pushHandler($stream); } } \ No newline at end of file diff --git a/src/Providers/ClientServiceProvider.php b/src/Providers/ClientServiceProvider.php index c749145..f6dff5f 100644 --- a/src/Providers/ClientServiceProvider.php +++ b/src/Providers/ClientServiceProvider.php @@ -20,8 +20,10 @@ class ClientServiceProvider extends BaseServiceProvider if (!is_array($config)) { throw new RpcServerException("Application's Rpc Client Config Undefind", 500); } - $this->app->singleton('rpc', function () use ($config) { - return new Client($config); + $this->app->singleton('rpc', function () use ($config) { + $client = new Client($config); + $client->setLogger($this->logger); + return $client; }); foreach ($config['client'] as $k => $item) { diff --git a/src/Providers/LumenServerServiceProvider.php b/src/Providers/LumenServerServiceProvider.php index a6625a5..73b1254 100644 --- a/src/Providers/LumenServerServiceProvider.php +++ b/src/Providers/LumenServerServiceProvider.php @@ -40,6 +40,7 @@ class LumenServerServiceProvider extends BaseServiceProvider } $callback = function () use ($config) { $server = new JsonRpcServer($config); + $server->setLogger($this->logger); return $server->handler(); }; diff --git a/src/Server/JsonRpcServer.php b/src/Server/JsonRpcServer.php index f9b2a9a..d823a29 100644 --- a/src/Server/JsonRpcServer.php +++ b/src/Server/JsonRpcServer.php @@ -6,6 +6,7 @@ namespace JsonRpc\Server; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use JsonRpc\JsonRpc; +use Psr\Log\LoggerInterface; class JsonRpcServer extends JsonRpc { @@ -13,13 +14,19 @@ class JsonRpcServer extends JsonRpc * @var Request */ public $request; + /** - * @var config 配置 + * @var LoggerInterface + */ + protected $logger; + + /** + * @var array 配置 */ protected $config; /** - * @var rpc.server.map rpc方法 + * @var array rpc.server.map rpc方法 */ protected $map; @@ -30,18 +37,22 @@ class JsonRpcServer extends JsonRpc $this->map = $config['map']; } + public function setLogger($logger){ + $this->logger = $logger; + } + public function handler() { -// if ($this->request->getContentType() != 'json') { -// return $this->error(self::Rpc_Error_Invalid_Request); -// } + if ($this->request->getContentType() != 'json') { + return $this->error(self::Rpc_Error_Invalid_Request); + } try { if ($this->request->method() == Request::METHOD_GET) { $method = $this->request->input('method'); $id = $this->request->input('id'); - $params = \GuzzleHttp\json_decode($this->request->input('params'),true); + $params = \GuzzleHttp\json_decode($this->request->input('params'), true); } else { list($method, $params, $id) = $this->parseJson($this->request->getContent()); } @@ -56,9 +67,9 @@ class JsonRpcServer extends JsonRpc return $this->error(self::Rpc_Error_Invalid_Params); } $this->request->attributes->add(['tunnel_method' => $method, 'tunnel_params' => $params]); - app('rpc.logger')->info('server', [$id, $class,$method, $params]); + $this->logger && $this->logger->info('server', [$id, $class, $method, $params]); $ret = call_user_func_array([(new $class($id, $this->request)), $function], $params); - app('rpc.logger')->info('server_result', [$id, $ret]); + $this->logger && $this->logger->info('server_result', [$id, $ret]); return JsonResponse::create($ret); @@ -67,6 +78,11 @@ class JsonRpcServer extends JsonRpc } } + /** + * 处理json rpc post body + * @param $data + * @return array + */ protected function parseJson($data) { $data = \GuzzleHttp\json_decode($data, true); @@ -76,36 +92,23 @@ class JsonRpcServer extends JsonRpc return [$method, $params, $id]; } + /** + * 根据method解析出对应的class + * @param $method + * @return array|mixed + */ protected function parseMethodWithMap($method) { return isset($this->map[$method]) ? $this->map[$method] : ['', '']; } /** - * thisis - * @param string $method 参数名称 - * @return array 返回结果 + * 检查调用方式是否足够 + * @param $class + * @param $method + * @param $parameters + * @return bool */ -// protected function parseMethod($method) -// { -// $method = explode('.', $method); -// -// if (count($method) < 2) { -// return ['', '']; -// } -// -// $function = array_pop($method); -// $class = 'Rpc' . ucwords(array_pop($method)); -// -// foreach ($method as $one) { -// $class = ucwords($one) . '\\' . $class; -// } -// -// $class = "App\Rpc\\$class"; -// return [$class, $function]; -// } - - protected function isEnoughParameter($class, $method, $parameters) { $r = new \ReflectionMethod($class, $method); diff --git a/tests/publish.php b/tests/publish.php new file mode 100644 index 0000000..893e0bf --- /dev/null +++ b/tests/publish.php @@ -0,0 +1,25 @@ + 'abc', + 'client' => [ + 'default' => [ + 'base_uri' => 'http://localhost:8080', + ] + ], +]); + +$client->endpoint('default'); + +$json = json_encode([ + 'order_id' => '123', + 'user_id' => '456', +]); + +try { + $res = $client->call('topic.produce', ['abc', $json]); + var_dump($res); +} catch (Exception $e) { + var_dump($e->getCode(),$e->getMessage()); +} diff --git a/tests/sub.php b/tests/sub.php index 6b46bc9..4260ff9 100644 --- a/tests/sub.php +++ b/tests/sub.php @@ -1,8 +1,19 @@ 'abc', + 'client' => [ + 'default' => [ + 'base_uri' => 'http://localhost:8080', + ] + ], +]); -$res = $client->call('math.subtract',['12','23',500]); +$client->endpoint('default'); -var_dump($res); \ No newline at end of file +try { + $res = $client->call('math.subtract', ['12', '23', 500]); +} catch (Exception $e) { + var_dump($e->getMessage()); +}