move into sonardesk
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Core',
|
||||
'enabled' => true,
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Contracts;
|
||||
|
||||
interface ModuleRegistry
|
||||
{
|
||||
/** @return array<int, array{name:string, alias:string, version:string, enabled:bool}> */
|
||||
public function all(): array;
|
||||
|
||||
public function enabled(string $name): bool;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Core\Contracts\ModuleRegistry;
|
||||
use Modules\Core\Services\LaravelModuleRegistry;
|
||||
use Modules\Core\Support\ModuleInfo;
|
||||
|
||||
final class CoreServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->singleton(ModuleRegistry::class, LaravelModuleRegistry::class);
|
||||
$this->mergeConfigFrom(module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower());
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path(ModuleInfo::name(), 'Database/Migrations'));
|
||||
$this->loadViewsFrom(module_path(ModuleInfo::name(), 'Resources/views'), ModuleInfo::nameLower());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
final class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
$this->routes(function (): void {
|
||||
Route::middleware('web')->group(module_path('Core', 'Routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
// Module routes are intentionally registered by each feature as it is enabled.
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Services;
|
||||
|
||||
use Modules\Core\Contracts\ModuleRegistry;
|
||||
|
||||
final class LaravelModuleRegistry implements ModuleRegistry
|
||||
{
|
||||
public function all(): array
|
||||
{
|
||||
$statuses = json_decode((string) @file_get_contents(base_path('modules_statuses.json')), true) ?: [];
|
||||
$modules = [];
|
||||
foreach (glob(base_path('Modules/*/module.json')) ?: [] as $manifest) {
|
||||
$data = json_decode((string) file_get_contents($manifest), true) ?: [];
|
||||
$name = (string) ($data['name'] ?? basename(dirname($manifest)));
|
||||
$modules[] = [
|
||||
'name' => $name,
|
||||
'alias' => (string) ($data['alias'] ?? strtolower($name)),
|
||||
'version' => (string) ($data['version'] ?? '0.0.0'),
|
||||
'enabled' => (bool) ($statuses[$name] ?? false),
|
||||
];
|
||||
}
|
||||
usort($modules, fn (array $a, array $b): int => $a['name'] <=> $b['name']);
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
public function enabled(string $name): bool
|
||||
{
|
||||
foreach ($this->all() as $module) {
|
||||
if (strcasecmp($module['name'], $name) === 0) {
|
||||
return $module['enabled'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Support;
|
||||
|
||||
final class ModuleInfo
|
||||
{
|
||||
public static function name(): string
|
||||
{
|
||||
return 'Core';
|
||||
}
|
||||
|
||||
public static function nameLower(): string
|
||||
{
|
||||
return 'core';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
it('boots the Core module', function (): void {
|
||||
expect(config('core.name'))->toBe('Core');
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "absdev/core-module",
|
||||
"description": "Core foundation module for the ABSDEV Laravel application platform.",
|
||||
"type": "laravel-module",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Core\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Core",
|
||||
"alias": "core",
|
||||
"version": "1.0.0",
|
||||
"description": "Core foundation module for the ABSDEV Laravel application platform.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"modules",
|
||||
"core"
|
||||
],
|
||||
"priority": 100,
|
||||
"providers": [
|
||||
"Modules\\Core\\Providers\\CoreServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
||||
Reference in New Issue
Block a user