Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit b3b9d5e

Browse files
authored
Merge pull request #290 from swooletw/develop
Develop
2 parents 0f36ee3 + f83b952 commit b3b9d5e

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

src/Concerns/InteractsWithWebsocket.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ protected function prepareWebsocket()
280280
*/
281281
protected function isServerWebsocket(int $fd): bool
282282
{
283-
return (bool) $this->container->make(Server::class)
284-
->connection_info($fd)['websocket_status'] ?? false;
283+
return array_key_exists(
284+
'websocket_status',
285+
$this->container->make(Server::class)
286+
->connection_info($fd)
287+
);
285288
}
286289

287290
/**
@@ -354,7 +357,7 @@ protected function createRoom(string $class, array $settings): RoomContract
354357
*/
355358
protected function bindRoom(): void
356359
{
357-
$this->app->singleton(RoomContract::class, function (Container $app) {
360+
$this->app->singleton(RoomContract::class, function () {
358361
return $this->websocketRoom;
359362
});
360363

src/HttpServiceProvider.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,35 @@ abstract class HttpServiceProvider extends ServiceProvider
3838
protected static $server;
3939

4040
/**
41-
* Register the service provider.
41+
* Boot the service provider.
4242
*
4343
* @return void
4444
*/
45-
public function register()
45+
public function boot()
4646
{
47+
$this->publishFiles();
48+
$this->loadConfigs();
4749
$this->mergeConfigs();
4850
$this->setIsWebsocket();
51+
52+
$config = $this->app->make('config');
53+
54+
if ($config->get('swoole_http.websocket.enabled')) {
55+
$this->bootWebsocketRoutes();
56+
}
57+
58+
if ($config->get('swoole_http.server.access_log')) {
59+
$this->pushAccessLogMiddleware();
60+
}
61+
}
62+
63+
/**
64+
* Register the service provider.
65+
*
66+
* @return void
67+
*/
68+
public function register()
69+
{
4970
$this->registerServer();
5071
$this->registerManager();
5172
$this->registerCommands();
@@ -76,27 +97,23 @@ abstract protected function bootWebsocketRoutes();
7697
abstract protected function pushAccessLogMiddleware();
7798

7899
/**
79-
* Boot the service provider.
80-
*
81-
* @return void
100+
* Publish files of this package.
82101
*/
83-
public function boot()
102+
protected function publishFiles()
84103
{
85104
$this->publishes([
86105
__DIR__ . '/../config/swoole_http.php' => base_path('config/swoole_http.php'),
87106
__DIR__ . '/../config/swoole_websocket.php' => base_path('config/swoole_websocket.php'),
88107
__DIR__ . '/../routes/websocket.php' => base_path('routes/websocket.php'),
89108
], 'laravel-swoole');
109+
}
90110

91-
$config = $this->app->make('config');
92-
93-
if ($config->get('swoole_http.websocket.enabled')) {
94-
$this->bootWebsocketRoutes();
95-
}
96-
97-
if ($config->get('swoole_http.server.access_log')) {
98-
$this->pushAccessLogMiddleware();
99-
}
111+
/**
112+
* Load configurations.
113+
*/
114+
protected function loadConfigs()
115+
{
116+
// do nothing
100117
}
101118

102119
/**

src/LumenServiceProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
*/
1111
class LumenServiceProvider extends HttpServiceProvider
1212
{
13+
/**
14+
* Load configurations.
15+
*/
16+
protected function loadConfigs()
17+
{
18+
$this->app->configure('swoole_http');
19+
$this->app->configure('swoole_websocket');
20+
}
21+
1322
/**
1423
* Register manager.
1524
*

0 commit comments

Comments
 (0)