OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
20
app/Core/Routing/FrontcontrollerServiceProvider.php
Normal file
20
app/Core/Routing/FrontcontrollerServiceProvider.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Routing;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class FrontcontrollerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
$this->app->singleton('frontcontroller', \Leantime\Core\Controller\Frontcontroller::class);
|
||||
|
||||
}
|
||||
}
|
||||
115
app/Core/Routing/RouteLoader.php
Normal file
115
app/Core/Routing/RouteLoader.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Routing;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Leantime\Core\Auth\Permissions\CheckPermissions;
|
||||
use Leantime\Core\Configuration\Environment;
|
||||
use Leantime\Core\Events\EventDispatcher;
|
||||
|
||||
class RouteLoader
|
||||
{
|
||||
/**
|
||||
* Load all routes.php files from domains and plugins
|
||||
*/
|
||||
public static function loadRoutes(): void
|
||||
{
|
||||
static $loaded;
|
||||
$loaded ??= false;
|
||||
|
||||
if ($loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load domain routes
|
||||
self::loadDomainRoutes();
|
||||
|
||||
// Load system plugin routes (defined via config)
|
||||
self::loadSystemPluginRoutes();
|
||||
|
||||
// Load user plugin routes (will be called via event after plugins are loaded)
|
||||
EventDispatcher::add_event_listener('leantime.core.middleware.loadplugins.handle.pluginsEvents', function () {
|
||||
self::loadUserPluginRoutes();
|
||||
}, 50);
|
||||
|
||||
$loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load routes.php files from all domains
|
||||
*/
|
||||
private static function loadDomainRoutes(): void
|
||||
{
|
||||
if ((bool) config('debug') === false) {
|
||||
$domainPaths = Cache::store('installation')->rememberForever('domainRoutes', function () {
|
||||
return self::getDomainPaths();
|
||||
});
|
||||
} else {
|
||||
$domainPaths = self::getDomainPaths();
|
||||
}
|
||||
|
||||
// Routes inherit the permission-enforcement middleware so #[RequiresPermission] on a
|
||||
// native controller action is honored without per-route `can:` declarations.
|
||||
Route::middleware([CheckPermissions::class])->group(function () use ($domainPaths) {
|
||||
foreach ($domainPaths as $domainPath) {
|
||||
if (file_exists($routesPath = "$domainPath/routes.php")) {
|
||||
require_once $routesPath;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load routes.php files from system plugins (defined in config)
|
||||
*/
|
||||
private static function loadSystemPluginRoutes(): void
|
||||
{
|
||||
if (isset(app(Environment::class)->plugins)) {
|
||||
$configPlugins = explode(',', app(Environment::class)->plugins);
|
||||
|
||||
Route::middleware([CheckPermissions::class])->group(function () use ($configPlugins) {
|
||||
foreach ($configPlugins as $plugin) {
|
||||
if (file_exists($pluginRoutesPath = APP_ROOT.'/app/Plugins/'.$plugin.'/routes.php')) {
|
||||
require_once $pluginRoutesPath;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load routes.php files from user-enabled plugins
|
||||
*/
|
||||
private static function loadUserPluginRoutes(): void
|
||||
{
|
||||
if (! session('isInstalled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$pluginService = app()->make(\Leantime\Core\Plugins\Plugins::class);
|
||||
$enabledPluginPaths = $pluginService->getEnabledPluginPaths();
|
||||
|
||||
Route::middleware([CheckPermissions::class])->group(function () use ($enabledPluginPaths) {
|
||||
foreach ($enabledPluginPaths as $pluginInfo) {
|
||||
$routesPath = $pluginInfo['path'].'/routes.php';
|
||||
|
||||
if (file_exists($routesPath)) {
|
||||
require_once $routesPath;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
// Silently continue if plugin service is unavailable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all domain paths (same as EventDispatcher::getDomainPaths but public for reuse)
|
||||
*/
|
||||
public static function getDomainPaths(): array
|
||||
{
|
||||
return collect(glob(APP_ROOT.'/app/Domain'.'/*', GLOB_ONLYDIR))->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user