[2.x] Laravel Octane support (#733)

* Octane support

Co-authored-by: Alex Renoki <rennokki@gmail.com>
This commit is contained in:
Dries Vints 2021-04-06 15:47:54 +02:00 committed by GitHub
parent 1bb727f322
commit ba3a2ad164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 16 deletions

View File

@ -106,10 +106,11 @@ class StartServer extends Command
*/ */
protected function configureManagers() protected function configureManagers()
{ {
$this->laravel->singleton(ChannelManager::class, function () { $this->laravel->singleton(ChannelManager::class, function ($app) {
$mode = config('websockets.replication.mode', 'local'); $config = $app['config']['websockets'];
$mode = $config['replication']['mode'] ?? 'local';
$class = config("websockets.replication.modes.{$mode}.channel_manager"); $class = $config['replication']['modes'][$mode]['channel_manager'];
return new $class($this->loop); return new $class($this->loop);
}); });
@ -211,9 +212,9 @@ class StartServer extends Command
*/ */
protected function configureHttpLogger() protected function configureHttpLogger()
{ {
$this->laravel->singleton(HttpLogger::class, function () { $this->laravel->singleton(HttpLogger::class, function ($app) {
return (new HttpLogger($this->output)) return (new HttpLogger($this->output))
->enable($this->option('debug') ?: config('app.debug')) ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false))
->verbose($this->output->isVerbose()); ->verbose($this->output->isVerbose());
}); });
} }
@ -225,9 +226,9 @@ class StartServer extends Command
*/ */
protected function configureMessageLogger() protected function configureMessageLogger()
{ {
$this->laravel->singleton(WebSocketsLogger::class, function () { $this->laravel->singleton(WebSocketsLogger::class, function ($app) {
return (new WebSocketsLogger($this->output)) return (new WebSocketsLogger($this->output))
->enable($this->option('debug') ?: config('app.debug')) ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false))
->verbose($this->output->isVerbose()); ->verbose($this->output->isVerbose());
}); });
} }
@ -239,9 +240,9 @@ class StartServer extends Command
*/ */
protected function configureConnectionLogger() protected function configureConnectionLogger()
{ {
$this->laravel->bind(ConnectionLogger::class, function () { $this->laravel->bind(ConnectionLogger::class, function ($app) {
return (new ConnectionLogger($this->output)) return (new ConnectionLogger($this->output))
->enable(config('app.debug')) ->enable($app['config']['app']['debug'] ?? false)
->verbose($this->output->isVerbose()); ->verbose($this->output->isVerbose());
}); });
} }

View File

@ -80,16 +80,18 @@ class WebSocketsServiceProvider extends ServiceProvider
*/ */
protected function registerStatistics() protected function registerStatistics()
{ {
$this->app->singleton(StatisticsStore::class, function () { $this->app->singleton(StatisticsStore::class, function ($app) {
$class = config('websockets.statistics.store'); $config = $app['config']['websockets'];
$class = $config['statistics']['store'];
return new $class; return new $class;
}); });
$this->app->singleton(StatisticsCollector::class, function () { $this->app->singleton(StatisticsCollector::class, function ($app) {
$replicationMode = config('websockets.replication.mode', 'local'); $config = $app['config']['websockets'];
$replicationMode = $config['replication']['mode'] ?? 'local';
$class = config("websockets.replication.modes.{$replicationMode}.collector"); $class = $config['replication']['modes'][$replicationMode]['collector'];
return new $class; return new $class;
}); });
@ -142,8 +144,10 @@ class WebSocketsServiceProvider extends ServiceProvider
*/ */
protected function registerManagers() protected function registerManagers()
{ {
$this->app->singleton(Contracts\AppManager::class, function () { $this->app->singleton(Contracts\AppManager::class, function ($app) {
return $this->app->make(config('websockets.managers.app')); $config = $app['config']['websockets'];
return $this->app->make($config['managers']['app']);
}); });
} }