Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/app/Providers/ |
<?php
namespace App\Providers;
use App\Services\ModuleService;
use Illuminate\Support\ServiceProvider;
/**
* Replaces Caffeinated\Modules - registers module service providers
* and the Module facade for isEnabled() checks.
*/
class ModulesServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('module', function ($app) {
return new ModuleService();
});
}
public function boot()
{
$this->registerModuleProviders();
}
/**
* Register each module's main ServiceProvider (for Lang, View namespaces).
* Discovers any *ServiceProvider in each module's Providers dir (except RouteServiceProvider).
*/
protected function registerModuleProviders()
{
$path = config('modules.path', app_path('Modules'));
if (!is_dir($path)) {
return;
}
$dirs = glob($path . '/*', GLOB_ONLYDIR);
foreach ($dirs as $dir) {
$moduleName = basename($dir);
$providersPath = $dir . '/Providers';
if (!is_dir($providersPath)) {
continue;
}
$files = glob($providersPath . '/*ServiceProvider.php');
foreach ($files as $file) {
$base = basename($file, '.php');
if ($base === 'RouteServiceProvider') {
continue;
}
$providerClass = 'App\\Modules\\' . $moduleName . '\\Providers\\' . $base;
if (class_exists($providerClass)) {
$this->app->register($providerClass);
}
}
}
}
}