From 27966a126a627834c4e1d8e8b6006e475aaef198 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 29 Apr 2018 19:41:29 +0800 Subject: [PATCH 1/2] add close function for websocket --- src/Websocket/Websocket.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Websocket/Websocket.php b/src/Websocket/Websocket.php index 45ad2e7a..4208cb76 100644 --- a/src/Websocket/Websocket.php +++ b/src/Websocket/Websocket.php @@ -232,6 +232,16 @@ public function call(string $event, $data = null) ]); } + /** + * Close current connection. + * + * @param integer + */ + public function close(int $fd = null) + { + return app('swoole.server')->close($fd ?: $this->sender); + } + /** * Set sender fd. * From fd17dd37e12b520dc11dbd2c5e9753b0478cf27e Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 29 Apr 2018 20:19:13 +0800 Subject: [PATCH 2/2] reset view's container in sandbox --- src/Server/Sandbox.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Server/Sandbox.php b/src/Server/Sandbox.php index d7926a6b..c63582b5 100644 --- a/src/Server/Sandbox.php +++ b/src/Server/Sandbox.php @@ -66,7 +66,6 @@ public function getApplication() $snapshot = clone $this->application; $this->resetLaravelApp($snapshot->getApplication()); - $this->rebindRouterContainer($snapshot->getApplication()); return $this->snapshot = $snapshot; } @@ -85,6 +84,9 @@ protected function resetLaravelApp($application) $reflector->setAccessible(true); $reflector->invoke($application); } + + $this->rebindRouterContainer($application); + $this->rebindViewContainer($application); } /** @@ -108,6 +110,22 @@ protected function rebindRouterContainer($application) } } + /** + * Rebind laravel/lumen's container in view. + */ + protected function rebindViewContainer($application) + { + $view = $application->make('view'); + + $closure = function () use ($application) { + $this->container = $application; + $this->shared['app'] = $application; + }; + + $resetView = $closure->bindTo($view, $view); + $resetView(); + } + /** * Get application's framework. */