|
| 1 | +# Version 3.0 Architecture Changes |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Version 3.0 introduces a **plugin-based architecture** for module auto-discovery. The monolithic `ModularServiceProvider` has been refactored into a collection of focused, composable `Plugin` classes. |
| 6 | +This improves extensibility, testability, and separation of concerns. |
| 7 | + |
| 8 | +## Breaking Changes |
| 9 | + |
| 10 | +### Requirements |
| 11 | + |
| 12 | +- **PHP 8.3+** (was 8.0+) |
| 13 | +- **Laravel 11+** (dropped Laravel 9/10 support) |
| 14 | + |
| 15 | +### Removed Features |
| 16 | + |
| 17 | +| Removed | Replacement | |
| 18 | +|----------------------------------|---------------------------------------| |
| 19 | +| `ModularEventServiceProvider` | `EventsPlugin` (auto-registered) | |
| 20 | +| `AutoDiscoveryHelper` | `FinderFactory` | |
| 21 | +| `ModuleRegistry::getCachePath()` | `Cache::path()` | |
| 22 | +| `make:livewire --module` | Install `internachi/modular-livewire` | |
| 23 | +| Breadcrumbs integration | Load manually in service provider | |
| 24 | + |
| 25 | +### Cache Changes |
| 26 | + |
| 27 | +| Before | After | |
| 28 | +|-------------------------------|-----------------------------------| |
| 29 | +| `bootstrap/cache/modules.php` | `bootstrap/cache/app-modules.php` | |
| 30 | +| Module paths only | All plugin discovery data | |
| 31 | + |
| 32 | +## Plugin Architecture |
| 33 | + |
| 34 | +### Core Classes |
| 35 | + |
| 36 | +``` |
| 37 | +PluginRegistry → Registration point for plugins |
| 38 | +PluginHandler → Orchestrates plugin lifecycle |
| 39 | +PluginDataRepository → Manages discovery data (cached or fresh) |
| 40 | +Cache → File I/O for unified cache |
| 41 | +FinderFactory → Creates FinderCollection instances |
| 42 | +ModuleFileInfo → Decorator with module() and fullyQualifiedClassName() |
| 43 | +``` |
| 44 | + |
| 45 | +### Plugin Base Class |
| 46 | + |
| 47 | +```php |
| 48 | +abstract class Plugin |
| 49 | +{ |
| 50 | + abstract public function discover(FinderFactory $finders): iterable; |
| 51 | + abstract public function handle(Collection $data); |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### PHP 8 Attributes |
| 56 | + |
| 57 | +| Attribute | Behavior | |
| 58 | +|-------------------------------------|---------------------------------------------| |
| 59 | +| `#[AfterResolving(Service::class)]` | Defer until service resolved | |
| 60 | +| `#[OnBoot]` | Execute during `booting()` hook | |
| 61 | +| *(none)* | Explicit call via `PluginHandler::handle()` | |
| 62 | + |
| 63 | +### Built-in Plugins |
| 64 | + |
| 65 | +| Plugin | Trigger | Responsibility | |
| 66 | +|--------------------|---------------------------------|-------------------------------------------------| |
| 67 | +| `ModulesPlugin` | Eager | Discover `composer.json`, create `ModuleConfig` | |
| 68 | +| `RoutesPlugin` | `!routesAreCached()` | Load route files | |
| 69 | +| `ViewPlugin` | `AfterResolving(ViewFactory)` | Register view namespaces | |
| 70 | +| `BladePlugin` | `AfterResolving(BladeCompiler)` | Register Blade components | |
| 71 | +| `TranslatorPlugin` | `AfterResolving(Translator)` | Register translations | |
| 72 | +| `EventsPlugin` | `AfterResolving(Dispatcher)` | Discover event listeners | |
| 73 | +| `MigratorPlugin` | `AfterResolving(Migrator)` | Register migration paths | |
| 74 | +| `GatePlugin` | `AfterResolving(Gate)` | Register model policies | |
| 75 | +| `ArtisanPlugin` | `Artisan::starting()` | Register commands | |
| 76 | + |
| 77 | +## Boot Flow |
| 78 | + |
| 79 | +``` |
| 80 | +ModularServiceProvider::register() |
| 81 | + ├─ Register singletons |
| 82 | + ├─ PluginRegistry::add(built-in plugins) |
| 83 | + └─ $app->booting(PluginHandler::boot) |
| 84 | + └─ For each plugin: |
| 85 | + └─ Plugin::boot(handler, app) |
| 86 | + └─ Read attributes, schedule execution |
| 87 | +``` |
| 88 | + |
| 89 | +## Extensibility |
| 90 | + |
| 91 | +Register custom plugins in a service provider: |
| 92 | + |
| 93 | +```php |
| 94 | +public function register(): void |
| 95 | +{ |
| 96 | + PluginRegistry::register(MyPlugin::class); |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Custom plugins: |
| 101 | + |
| 102 | +- Must extend `InterNACHI\Modular\Plugins\Plugin` |
| 103 | +- Are automatically integrated into caching |
| 104 | +- Can use lifecycle attributes |
| 105 | + |
| 106 | +## Laravel Integration |
| 107 | + |
| 108 | +Modular 3.0 integrates with Laravel's optimize commands via the `optimizes()` method: |
| 109 | + |
| 110 | +- `php artisan optimize` → runs `modules:cache` |
| 111 | +- `php artisan optimize:clear` → runs `modules:clear` |
| 112 | + |
| 113 | +## Migration Checklist |
| 114 | + |
| 115 | +1. Upgrade PHP to 8.3+ and Laravel to 11+ |
| 116 | +2. Run `php artisan modules:clear` |
| 117 | +3. Run `composer update internachi/modular` |
| 118 | +4. If using Livewire: `composer require internachi/modular-livewire` |
| 119 | +5. Update any `AutoDiscoveryHelper` references to `FinderFactory` |
| 120 | +6. Remove any `ModularEventServiceProvider` references |
0 commit comments