M4: 插件框架(钩子系统/ZIP安装/市场客户端)+ blog-seo 插件(JSON-LD/OG/llms.txt/Markdown导出)+ 后台插件/主题管理页
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Blog\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class PluginServiceProvider
|
||||
{
|
||||
/**
|
||||
* 插件入口:由 PluginManagerServiceProvider 在应用启动时调用。
|
||||
*/
|
||||
public static function bootPlugin(PluginManager $manager): void
|
||||
{
|
||||
(new static)->boot($manager);
|
||||
}
|
||||
|
||||
abstract protected function boot(PluginManager $manager): void;
|
||||
|
||||
protected function addAction(PluginManager $manager, string $hook, callable $callback, int $priority = 10): void
|
||||
{
|
||||
$manager->addAction($hook, $callback, $priority);
|
||||
}
|
||||
|
||||
protected function addFilter(PluginManager $manager, string $hook, callable $callback, int $priority = 10): void
|
||||
{
|
||||
$manager->addFilter($hook, $callback, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载插件路由文件。
|
||||
*/
|
||||
protected function loadRoutes(string $file): void
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
Route::middleware('web')->group($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册插件视图命名空间:plugins/{vendor}.{name}/views -> plugin.{vendor}.{name}
|
||||
*/
|
||||
protected function loadViews(string $viewsPath, string $namespace): void
|
||||
{
|
||||
if (is_dir($viewsPath)) {
|
||||
\Illuminate\Support\Facades\View::addNamespace($namespace, $viewsPath);
|
||||
}
|
||||
}
|
||||
|
||||
protected function slug(string $string): string
|
||||
{
|
||||
return Str::slug($string);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user