diff --git a/app/Http/Controllers/Modules/ScriptController.php b/app/Http/Controllers/Modules/ScriptController.php index 86ab6640..4a9354ca 100644 --- a/app/Http/Controllers/Modules/ScriptController.php +++ b/app/Http/Controllers/Modules/ScriptController.php @@ -3,27 +3,27 @@ namespace App\Http\Controllers\Modules; use App\Http\Controllers\Controller; -use App\Services\Module\ModuleFacade; use DateTime; +use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Support\Arr; -use Request; +use InvoiceShelf\Modules\Registry as ModuleRegistry; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class ScriptController extends Controller { /** - * Serve the requested script. + * Serve the requested module-registered script. * - * @return Response + * Modules call \InvoiceShelf\Modules\Registry::registerScript($name, $path) + * from their ServiceProvider::boot() to inject custom JS into the host app. * * @throws NotFoundHttpException */ - public function __invoke(Request $request, string $script) + public function __invoke(Request $request, string $script): Response { - $path = Arr::get(ModuleFacade::allScripts(), $script); + $path = ModuleRegistry::scriptFor($script); - abort_if(is_null($path), 404); + abort_if($path === null, 404); return response( file_get_contents($path), @@ -31,6 +31,6 @@ class ScriptController extends Controller [ 'Content-Type' => 'application/javascript', ] - )->setLastModified(DateTime::createFromFormat('U', filemtime($path))); + )->setLastModified(DateTime::createFromFormat('U', (string) filemtime($path))); } } diff --git a/app/Http/Controllers/Modules/StyleController.php b/app/Http/Controllers/Modules/StyleController.php index 3c2544d1..c09108bc 100644 --- a/app/Http/Controllers/Modules/StyleController.php +++ b/app/Http/Controllers/Modules/StyleController.php @@ -3,27 +3,27 @@ namespace App\Http\Controllers\Modules; use App\Http\Controllers\Controller; -use App\Services\Module\ModuleFacade; use DateTime; +use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Support\Arr; -use Request; +use InvoiceShelf\Modules\Registry as ModuleRegistry; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class StyleController extends Controller { /** - * Serve the requested stylesheet. + * Serve the requested module-registered stylesheet. * - * @return Response + * Modules call \InvoiceShelf\Modules\Registry::registerStyle($name, $path) + * from their ServiceProvider::boot() to inject custom CSS into the host app. * * @throws NotFoundHttpException */ - public function __invoke(Request $request, string $style) + public function __invoke(Request $request, string $style): Response { - $path = Arr::get(ModuleFacade::allStyles(), $style); + $path = ModuleRegistry::styleFor($style); - abort_if(is_null($path), 404); + abort_if($path === null, 404); return response( file_get_contents($path), @@ -31,6 +31,6 @@ class StyleController extends Controller [ 'Content-Type' => 'text/css', ] - )->setLastModified(DateTime::createFromFormat('U', filemtime($path))); + )->setLastModified(DateTime::createFromFormat('U', (string) filemtime($path))); } } diff --git a/app/Services/Module/Module.php b/app/Services/Module/Module.php deleted file mode 100644 index 9555f729..00000000 --- a/app/Services/Module/Module.php +++ /dev/null @@ -1,75 +0,0 @@ - - @foreach(\App\Services\Module\ModuleFacade::allStyles() as $name => $path) + @foreach(\InvoiceShelf\Modules\Registry::allStyles() as $name => $path) @endforeach @@ -38,7 +38,7 @@ @if(isset($current_theme)) theme-{{ $current_theme }} @else theme-{{get_app_setting('admin_portal_theme') ?? 'invoiceshelf'}} @endif "> - @foreach (\App\Services\Module\ModuleFacade::allScripts() as $name => $path) + @foreach (\InvoiceShelf\Modules\Registry::allScripts() as $name => $path) @if (\Illuminate\Support\Str::startsWith($path, ['http://', 'https://'])) @else