Initial baseline: LaraBlog core with plugin commerce surface.

Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
This commit is contained in:
ak
2026-08-12 01:15:38 +08:00
commit 263b98b218
337 changed files with 31393 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace App\Providers;
use App\Auth\LaraBlogUserProvider;
use App\Contracts\LlmProvider;
use App\Domain\Ai\OpenAiCompatibleLlmProvider;
use App\Domain\Ai\StubLlmProvider;
use App\Domain\Media\AttachmentStorageService;
use App\Domain\Plugin\PluginManager;
use App\Domain\Seo\SeoPresenter;
use App\Domain\Theme\RegistersSnippetSlots;
use App\Domain\Theme\ThemeManager;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(ThemeManager::class);
$this->app->singleton(PluginManager::class);
$this->app->singleton(AttachmentStorageService::class);
$this->app->singleton(SeoPresenter::class);
$this->app->bind(LlmProvider::class, function (): LlmProvider {
$provider = env('AI_PROVIDER', 'stub');
try {
$provider = app(\App\Settings\AiSettings::class)->provider ?: $provider;
} catch (\Throwable) {
// settings table may be unavailable during early boot
}
return match ($provider) {
'openai_compatible', 'openai' => $this->app->make(OpenAiCompatibleLlmProvider::class),
default => $this->app->make(StubLlmProvider::class),
};
});
}
public function boot(): void
{
Auth::provider('larablog', function ($app, array $config) {
return new LaraBlogUserProvider($app['hash'], $config['model'] ?? User::class);
});
// Always register default theme views; active theme may resolve later.
$this->app->make(ThemeManager::class)->registerViewNamespaces();
Blade::directive('themeslot', function (string $expression): string {
return "<?php echo \\App\\Domain\\Theme\\ThemeSlot::render({$expression}); ?>";
});
// Always load discovered plugin migrations so `artisan migrate` works
// before a plugin is enabled (enable → migrate chicken-and-egg).
foreach ($this->app->make(PluginManager::class)->discover() as $manifest) {
$migrations = rtrim((string) ($manifest['path'] ?? ''), '/').'/database/migrations';
if (is_dir($migrations)) {
$this->loadMigrationsFrom($migrations);
}
}
// Filament AdminPanelProvider also registers plugins before panel id();
// keep this for HTTP routes / hooks when the admin panel is unused.
if (Schema::hasTable('plugins')) {
$this->app->make(PluginManager::class)->registerEnabledProviders();
}
if (Schema::hasTable('settings')) {
RegistersSnippetSlots::boot();
}
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace App\Providers\Filament;
use App\Domain\Plugin\PluginManager;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages\Dashboard;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Support\Enums\Width;
use Filament\View\PanelsRenderHook;
use Filament\Widgets\AccountWidget;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Schema;
use Illuminate\View\Middleware\ShareErrorsFromSession;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
// Plugin providers' register() may call Panel::configureUsing; that must
// run before id(), which triggers configure().
$this->registerEnabledPluginProviders();
return $panel
->default()
->id('admin')
->path('admin')
->login()
->brandName(fn (): string => __('admin.brand'))
->colors([
'primary' => Color::Teal,
])
->maxContentWidth(Width::Full)
->sidebarWidth('13.5rem')
->collapsedSidebarWidth('3.75rem')
->sidebarFullyCollapsibleOnDesktop()
->collapsibleNavigationGroups(false)
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
AccountWidget::class,
])
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
fn (): string => Blade::render('@livewire(\'admin.clear-cache-button\')'),
)
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
protected function registerEnabledPluginProviders(): void
{
try {
if (! Schema::hasTable('plugins')) {
return;
}
app(PluginManager::class)->registerEnabledProviders();
} catch (\Throwable) {
// Ignore during installs / early package discovery without DB.
}
}
}