This directory contains comprehensive documentation for migrating SMF3 from static/global variables to modern Dependency Injection using League\Container.
-
DI_MIGRATION_SUMMARY.md - Start here!
- Executive summary
- Quick overview of the problem and solution
- High-level overview and benefits
- Best for: Quick overview
-
DEPENDENCY_INJECTION_MIGRATION_PLAN.md - Complete technical plan
- Detailed service interfaces and implementations
- Complete global/static variable inventory
- Phase-by-phase implementation roadmap
- Code examples and patterns
- Testing strategy
- Performance considerations
- Best for: Developers implementing the migration
-
DI_MIGRATION_QUICK_REFERENCE.md - Daily reference guide
- Quick lookup table for common migrations
- Before/after code examples
- Service method reference
- Migration patterns
- Best for: Developers actively migrating code
- Read the Summary to understand the "why"
- Review the Quick Reference for common patterns
- Consult the Full Plan for detailed implementation
Use the Quick Reference to verify migrations follow the correct patterns.
- Total static/global usages: ~8,300+
- Highest priority:
Utils::$context(5,733 usages) - Second priority:
Config::$modSettings(2,270 usages) - Risk level: Low (backward compatible approach)
Static Variables (Current) Services (Target)
├── Config::$modSettings → ModSettingsService
├── Config::$sourcedir → PathService
├── Config::$scripturl → UrlService
└── Utils::$context → AssetService
PageContextService
TemplateContextService
- Foundation: Create service interfaces and core services
- Context Breakdown: Split Utils::$context into focused services
- Supporting Services: Path and URL services
- Gradual Migration: Migrate Actions and components
- Testing & Refinement: Comprehensive testing
Before:
class ProfileAction {
public function execute() {
$username = Config::$modSettings['default_username'];
Utils::$context['page_title'] = 'Profile';
}
}After:
class ProfileAction {
public function __construct(
private ModSettingsServiceInterface $modSettings,
private PageContextServiceInterface $pageContext
) {}
public function execute() {
$username = $this->modSettings->getString('default_username');
$this->pageContext->setPageTitle('Profile');
}
}- Testability: Easy to mock dependencies in unit tests
- Type Safety: IDE autocomplete and type checking
- Clear Dependencies: Constructor shows what a class needs
- Maintainability: Changes isolated to service implementations
- Modern Architecture: Industry-standard dependency injection
- DI Container: League\Container (already included)
- Pattern: Service Provider pattern
- Injection: Constructor injection (preferred)
- Backward Compatibility: Helper functions during transition
When migrating code:
- Follow patterns in the Quick Reference
- Write tests for migrated code
- Update documentation if you discover new patterns
- Submit PRs with clear before/after examples
- Review the Full Plan for detailed answers
- Check the Quick Reference for common scenarios
- Consult the team lead for architectural decisions
- Document current state and usage statistics
- Design service architecture
- Create comprehensive migration plan
- Implement proof of concept (ModSettingsService)
- Migrate first Action as example
- Execute gradual migration
Last Updated: 2026-01-27 Status: Planning Phase