You've already forked Php-Template
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m42s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m38s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m5s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m28s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m27s
Reviewed-on: #16 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Services\ServiceProviders;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Siteworxpro\App\Async\Brokers\Broker;
|
|
use Siteworxpro\App\Services\Facades\Config;
|
|
|
|
/**
|
|
* Class BrokerServiceProvider
|
|
*
|
|
* This service provider is responsible for binding the Broker implementation
|
|
* to the Laravel service container based on configuration settings.
|
|
*
|
|
* @package Siteworxpro\App\Services\ServiceProviders
|
|
*/
|
|
class BrokerServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register services.
|
|
*
|
|
* This method binds the Broker interface to a specific implementation
|
|
* based on the configuration defined in 'queue.broker' and 'queue.broker_config'.
|
|
*
|
|
* @return void
|
|
* @throws \RuntimeException if the specified broker class does not exist.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(Broker::class, function (): Broker {
|
|
$configName = Config::get('queue.broker');
|
|
$brokerConfig = Config::get('queue.broker_config.' . $configName) ?? [];
|
|
|
|
$brokerClass = Broker::BROKER_TYPES[$configName] ?? null;
|
|
|
|
if ($brokerClass && class_exists($brokerClass)) {
|
|
return new $brokerClass($brokerConfig);
|
|
}
|
|
|
|
throw new \RuntimeException("Broker class $brokerClass does not exist.");
|
|
});
|
|
}
|
|
}
|