email plugin

This commit is contained in:
th committed 2026-04-10 10:42:18 +02:00
1 parent 3f4ba3c0f4
commit cc97754ae6
16 files changed
+2979 -5

No files matched your search

+27
View File
@@ -22,6 +22,7 @@ class PluginManager {
private array $plugins = [];
private array $slots = [];
private array $disabled = []; // names of plugins the user has disabled
private array $routeHandlers = []; // callbacks: fn(string $route, string $method): bool
private ?string $stateFile = null; // path to plugins.json
private static ?PluginManager $instance = null;
@@ -99,6 +100,32 @@ class PluginManager {
return $this->disabled;
}
/**
* Register a route handler from a plugin's backend.php.
* The callback receives ($route, $method) and should call exit() on a match.
* If it doesn't exit, the next handler / core route handling continues.
*/
public function onApiRoute(callable $handler): void {
$this->routeHandlers[] = $handler;
}
/**
* Dispatch a request to all registered plugin route handlers in order.
* Each handler that wants to claim the route must call exit() itself.
* Called from index.php BEFORE core route handling.
*/
public function dispatchRoute(string $route, string $method): void {
foreach ($this->routeHandlers as $handler) {
try { $handler($route, $method); }
catch (\Throwable $e) {
error_log('[plugin route] ' . $e->getMessage());
http_response_code(500);
echo json_encode(['error' => 'plugin route handler failed']);
exit;
}
}
}
/** Public-friendly plugin list for the API: [{name, version, description, enabled}]. */
public function pluginsForApi(): array {
$out = [];