mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 01:04:03 +00:00
refactor(modules): migrate asset registry from app/Services to invoiceshelf/modules package
The vestigial App\Services\Module\Module static class — with its unused
\$scripts / \$styles / \$settings registries — never had any of its helpers
wired up. The new InvoiceShelf\Modules\Registry shipped from the
invoiceshelf/modules package supersedes it cleanly: same static-array surface
(\$menu, \$settings, \$scripts, \$styles), but lives outside the host app so
third-party modules can depend on it without importing v3-app internals.
Three consumers in the host app are migrated to the new namespace:
- ScriptController and StyleController (the HTTP endpoints that serve
module-registered JS/CSS assets at /modules/scripts/{name} and
/modules/styles/{name}) now look up paths via Registry::scriptFor() and
Registry::styleFor() instead of Arr::get(ModuleFacade::all*(), \$name).
Also tightens type hints — Request import + Response return type.
- resources/views/app.blade.php iterates Registry::allStyles() /
Registry::allScripts() to inject module-supplied <link>/<script> tags into
the main layout. Same Akaunting-style asset injection mechanism, just
reading from the new namespace.
Both Module and ModuleFacade are deleted — they had no remaining callers
after this migration.
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Module;
|
||||
|
||||
class Module
|
||||
{
|
||||
/**
|
||||
* All of the registered Modules scripts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $scripts = [];
|
||||
|
||||
/**
|
||||
* All of the registered company settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $settings = [];
|
||||
|
||||
/**
|
||||
* All of the registered Modules CSS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $styles = [];
|
||||
|
||||
/**
|
||||
* Register the given script file with Module.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @return static
|
||||
*/
|
||||
public static function script($name, $path)
|
||||
{
|
||||
static::$scripts[$name] = $path;
|
||||
|
||||
return new static;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the given CSS file with Module.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @return static
|
||||
*/
|
||||
public static function style($name, $path)
|
||||
{
|
||||
static::$styles[$name] = $path;
|
||||
|
||||
return new static;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the additional scripts that should be registered.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function allScripts()
|
||||
{
|
||||
return static::$scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the additional stylesheets that should be registered.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function allStyles()
|
||||
{
|
||||
return static::$styles;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Module;
|
||||
|
||||
use Illuminate\Support\Facades\Facade as BaseFacade;
|
||||
|
||||
class ModuleFacade extends BaseFacade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return Module::class;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
|
||||
<!-- Module Styles -->
|
||||
@foreach(\App\Services\Module\ModuleFacade::allStyles() as $name => $path)
|
||||
@foreach(\InvoiceShelf\Modules\Registry::allStyles() as $name => $path)
|
||||
<link rel="stylesheet" href="/modules/styles/{{ $name }}">
|
||||
@endforeach
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
@if(isset($current_theme)) theme-{{ $current_theme }} @else theme-{{get_app_setting('admin_portal_theme') ?? 'invoiceshelf'}} @endif ">
|
||||
|
||||
<!-- Module Scripts -->
|
||||
@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://']))
|
||||
<script type="module" src="{!! $path !!}"></script>
|
||||
@else
|
||||
|
||||
Reference in New Issue
Block a user