Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Factory methods for conditional binding #274

Closed
wants to merge 1 commit into from

Conversation

aPalenov
Copy link

In the current implementation of the Factory class, there is no ability to override bindings for dependencies. Please add functionality that allows developers to override these bindings. This would greatly simplify the configuration and testing of the application, as well as increase its flexibility.

@taylorotwell
Copy link
Member

Please provide your specific use case in your own application.

@aPalenov
Copy link
Author

In my current application, I use the beyondcode/laravel-websockets package, which allows me to change the channel_manager in the websockets.php configuration file (for example, here). This gives me the ability to modify and create custom channels.

An example of this is shown in the following code:

<?php

namespace App\Libraries\LaravelWebSockets\Channels\ChannelManagers;

use App\Libraries\LaravelWebSockets\Channels\PresenceSecretChannel;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers\ArrayChannelManager as BaseArrayChannelManager;
use Illuminate\Support\Str;

class ArrayChannelManager extends BaseArrayChannelManager
{
    protected function determineChannelClass(string $channelName): string
    {
        if (Str::startsWith($channelName, 'presence-secret-')) {
            return PresenceSecretChannel::class;
        }

        return parent::determineChannelClass($channelName);
    }
}

In this case, I create a channel where users can subscribe via whisper/listenForWhisper, sending messages that are only accessible to specific users. Each message also includes a user_id.

While it might not be necessary to replace the entire ArrayChannelManager, having the ability to create my own channels would significantly simplify the configuration of the application.

@aPalenov aPalenov deleted the patch-1 branch November 20, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants