Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

[2.x] Laravel Octane support #733

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/Console/Commands/StartServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ protected function configureLoggers()
*/
protected function configureManagers()
{
$this->laravel->singleton(ChannelManager::class, function () {
$mode = config('websockets.replication.mode', 'local');
$this->laravel->singleton(ChannelManager::class, function ($app) {
$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);
});
Expand Down Expand Up @@ -211,9 +212,9 @@ protected function configurePongTracker()
*/
protected function configureHttpLogger()
{
$this->laravel->singleton(HttpLogger::class, function () {
$this->laravel->singleton(HttpLogger::class, function ($app) {
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());
});
}
Expand All @@ -225,9 +226,9 @@ protected function configureHttpLogger()
*/
protected function configureMessageLogger()
{
$this->laravel->singleton(WebSocketsLogger::class, function () {
$this->laravel->singleton(WebSocketsLogger::class, function ($app) {
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());
});
}
Expand All @@ -239,9 +240,9 @@ protected function configureMessageLogger()
*/
protected function configureConnectionLogger()
{
$this->laravel->bind(ConnectionLogger::class, function () {
$this->laravel->bind(ConnectionLogger::class, function ($app) {
return (new ConnectionLogger($this->output))
->enable(config('app.debug'))
->enable($app['config']['app']['debug'] ?? false)
->verbose($this->output->isVerbose());
});
}
Expand Down
18 changes: 11 additions & 7 deletions src/WebSocketsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,18 @@ protected function registerAsyncRedisQueueDriver()
*/
protected function registerStatistics()
{
$this->app->singleton(StatisticsStore::class, function () {
$class = config('websockets.statistics.store');
$this->app->singleton(StatisticsStore::class, function ($app) {
$config = $app['config']['websockets'];
$class = $config['statistics']['store'];

return new $class;
});

$this->app->singleton(StatisticsCollector::class, function () {
$replicationMode = config('websockets.replication.mode', 'local');
$this->app->singleton(StatisticsCollector::class, function ($app) {
$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;
});
Expand Down Expand Up @@ -142,8 +144,10 @@ protected function registerRouter()
*/
protected function registerManagers()
{
$this->app->singleton(Contracts\AppManager::class, function () {
return $this->app->make(config('websockets.managers.app'));
$this->app->singleton(Contracts\AppManager::class, function ($app) {
$config = $app['config']['websockets'];

return $this->app->make($config['managers']['app']);
});
}

Expand Down