46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ModuleServiceProvider extends ServiceProvider
|
|
{
|
|
private string $strProjectName = 'LaraBB';
|
|
|
|
public function boot()
|
|
{
|
|
|
|
}
|
|
|
|
public function register($strPath = '')
|
|
{
|
|
// Durchsuche diesen Pfad nach (Unter)Modulen
|
|
$strScanPath = empty($strPath) ? app_path('Modules/' . $strPath) : $strPath . '/';
|
|
|
|
foreach (scandir($strScanPath) as $strModule) {
|
|
if ($strModule != '.' && $strModule != '..') {
|
|
|
|
// Pfad zur ServiceProvider.php (je nach gefundenem Modul)
|
|
$strServiceProviderPath = $strScanPath . $strModule . '/ServiceProvider.php';
|
|
|
|
// Wenn keine ServiceProvider.php für Modul existiert, überspringe das gefundene Modul
|
|
if(!file_exists($strServiceProviderPath)) continue;
|
|
|
|
// Extrahiere ServiceProvider-Namespace aus Pfad zur ServiceProvider.php
|
|
preg_match('/Modules\/(.*?)\.php/', $strServiceProviderPath, $matches);
|
|
$strServiceProviderNamespace = str_replace('/', '\\', $matches[1]);
|
|
|
|
// Registriere ServiceProvider (Modul) im Framework
|
|
$this->app->register($this->strProjectName . '\\' . $strServiceProviderNamespace);
|
|
|
|
// Wenn "Modules"-Ordner in (Unter)Modul vorhanden, dann rekursiver Aufruf
|
|
$strSubModulePath = $strScanPath . $strModule . '/Modules';
|
|
if(is_dir($strSubModulePath)) {
|
|
$this->register($strSubModulePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|