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

Commit b7f4d36

Browse files
committed
fix potential package configuration mismatched in lumen
1 parent d27e2c4 commit b7f4d36

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

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)