diff --git a/composer.json b/composer.json index 81d88c2b..7a214adb 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "ext-mongodb": "^1.5", "cboden/ratchet": "^0.4", "cocur/slugify": "^3.2", + "eaglewu/swoole-ide-helper": "dev-master", "gabordemooij/redbean": "^5.2", "mongodb/mongodb": "^1.4", "monolog/monolog": "^1.24", diff --git a/composer.lock b/composer.lock index 4358651f..8d6f2b2f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "72f743f50d32b133a88b0c1774941475", + "content-hash": "2e4a307367577d8c4ebfa29af0e098b3", "packages": [], "packages-dev": [ { @@ -341,6 +341,46 @@ ], "time": "2014-09-09T13:34:57+00:00" }, + { + "name": "eaglewu/swoole-ide-helper", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wudi/swoole-ide-helper.git", + "reference": "c79def9a776c01f8dd493c3f4862181beb91a682" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wudi/swoole-ide-helper/zipball/c79def9a776c01f8dd493c3f4862181beb91a682", + "reference": "c79def9a776c01f8dd493c3f4862181beb91a682", + "shasum": "" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "eagle", + "email": "eaglewudi@gmail.com", + "role": "lead" + } + ], + "description": "Swoole IDE Helper, to improve auto-completion", + "keywords": [ + "autocomplete", + "codeintel", + "helper", + "ide", + "netbeans", + "phpdoc", + "phpstorm", + "sublime", + "swoole" + ], + "time": "2019-03-22T10:40:58+00:00" + }, { "name": "egulias/email-validator", "version": "2.1.7", @@ -4198,7 +4238,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "eaglewu/swoole-ide-helper": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Swoole/Swoole.php b/src/Swoole/Swoole.php index d211066b..7fc46697 100644 --- a/src/Swoole/Swoole.php +++ b/src/Swoole/Swoole.php @@ -8,7 +8,11 @@ namespace Siler\Swoole; +use Swoole\Http\Request; +use Swoole\Http\Response; +use Swoole\Http\Server; use Siler\Container; +use const Siler\Route\DID_MATCH; const SWOOLE_HTTP_REQUEST = 'swoole_http_request'; const SWOOLE_HTTP_REQUEST_ENDED = 'swoole_http_request_ended'; @@ -24,13 +28,14 @@ * @param int $port The port binding (defaults to 9501). * @param string $host The host binding (defaults to 0.0.0.0). * - * @return \Swoole\Http\Server + * @return Server */ -function http(callable $handler, int $port = 9501, string $host = '0.0.0.0') +function http(callable $handler, int $port = 9501, string $host = '0.0.0.0'): Server { - $server = new \Swoole\Http\Server($host, $port); + $server = new Server($host, $port); $server->on('request', function ($request, $response) use ($handler) { + Container\set(DID_MATCH, false); Container\set(SWOOLE_HTTP_REQUEST_ENDED, false); Container\set(SWOOLE_HTTP_REQUEST, $request); Container\set(SWOOLE_HTTP_RESPONSE, $response); @@ -44,7 +49,7 @@ function http(callable $handler, int $port = 9501, string $host = '0.0.0.0') /** * Gets the current Swoole HTTP request. */ -function request() +function request(): Request { return Container\get(SWOOLE_HTTP_REQUEST); } @@ -52,7 +57,7 @@ function request() /** * Gets the current Swoole HTTP response. */ -function response() +function response(): Response { return Container\get(SWOOLE_HTTP_RESPONSE); } @@ -63,6 +68,8 @@ function response() * @param string $content Content for the output. * @param int $status HTTP response status code. * @param array $headers HTTP response headers. + * + * @return null */ function emit(string $content, int $status = 200, array $headers = []) { @@ -78,15 +85,19 @@ function emit(string $content, int $status = 200, array $headers = []) Container\set(SWOOLE_HTTP_REQUEST_ENDED, true); - return response()->end($content); + response()->end($content); + + return null; } /** * Sugar to emit() JSON encoded data. * * @param mixed $data - * @param int $status + * @param int $status * @param array $headers + * + * @return null */ function json($data, int $status = 200, array $headers = []) { @@ -125,8 +136,10 @@ function websocket_hooks(array $hooks) * Returns a Swoole\WebSocket\Server. * * @param callable $handler The handler to call on each message. - * @param int $port The port binding (defaults to 9502). - * @param string $host The host binding (defaults to 0.0.0.0). + * @param int $port The port binding (defaults to 9502). + * @param string $host The host binding (defaults to 0.0.0.0). + * + * @return \Swoole\WebSocket\Server */ function websocket(callable $handler, int $port = 9502, string $host = '0.0.0.0'): \Swoole\WebSocket\Server {