docs: Add Select class migration guide

This commit is contained in:
Roman Kelesidis 2025-06-18 09:43:10 +03:00
commit 5796dcfbc4
No known key found for this signature in database
GPG key ID: D8157C4D4C4C6DB4

View file

@ -6,6 +6,7 @@ This guide helps you upgrade your TorrentPier installation to the latest version
- [Configuration System Migration](#configuration-system-migration) - [Configuration System Migration](#configuration-system-migration)
- [Censor System Migration](#censor-system-migration) - [Censor System Migration](#censor-system-migration)
- [Select System Migration](#select-system-migration)
- [Development System Migration](#development-system-migration) - [Development System Migration](#development-system-migration)
- [Breaking Changes](#breaking-changes) - [Breaking Changes](#breaking-changes)
- [Best Practices](#best-practices) - [Best Practices](#best-practices)
@ -161,6 +162,74 @@ When you update censored words in the admin panel, the system now automatically:
2. Reloads the singleton instance with fresh words 2. Reloads the singleton instance with fresh words
3. Applies changes immediately without requiring page refresh 3. Applies changes immediately without requiring page refresh
## 📋 Select System Migration
The Select class has been moved and reorganized for better structure and consistency within the legacy system organization.
### Quick Migration Overview
```php
// ❌ Old way (deprecated)
\TorrentPier\Legacy\Select::language($new['default_lang'], 'default_lang');
\TorrentPier\Legacy\Select::timezone('', 'timezone_type');
\TorrentPier\Legacy\Select::template($pr_data['tpl_name'], 'tpl_name');
// ✅ New way (recommended)
\TorrentPier\Legacy\Common\Select::language($new['default_lang'], 'default_lang');
\TorrentPier\Legacy\Common\Select::timezone('', 'timezone_type');
\TorrentPier\Legacy\Common\Select::template($pr_data['tpl_name'], 'tpl_name');
```
#### Namespace Update
The Select class has been moved from `\TorrentPier\Legacy\Select` to `\TorrentPier\Legacy\Common\Select` to better organize legacy components.
#### Method Usage Remains Unchanged
```php
// Language selection dropdown
$languageSelect = \TorrentPier\Legacy\Common\Select::language($currentLang, 'language_field');
// Timezone selection dropdown
$timezoneSelect = \TorrentPier\Legacy\Common\Select::timezone($currentTimezone, 'timezone_field');
// Template selection dropdown
$templateSelect = \TorrentPier\Legacy\Common\Select::template($currentTemplate, 'template_field');
```
#### Available Select Methods
```php
// All existing methods remain available:
\TorrentPier\Legacy\Common\Select::language($selected, $name);
\TorrentPier\Legacy\Common\Select::timezone($selected, $name);
\TorrentPier\Legacy\Common\Select::template($selected, $name);
```
### Backward Compatibility
The old class path is deprecated but still works through class aliasing:
```php
// This still works but is deprecated
\TorrentPier\Legacy\Select::language($lang, 'default_lang');
// This is the new recommended way
\TorrentPier\Legacy\Common\Select::language($lang, 'default_lang');
```
### Migration Strategy
1. **Search and Replace**: Update all references to the old namespace
2. **Import Statements**: Update use statements if you're using them
3. **Configuration Files**: Update any configuration that references the old class path
```php
// Update use statements
// Old
use TorrentPier\Legacy\Select;
// New
use TorrentPier\Legacy\Common\Select;
```
## 🛠️ Development System Migration ## 🛠️ Development System Migration
The development and debugging system has been refactored to use a singleton pattern, providing better resource management and consistency across the application. The development and debugging system has been refactored to use a singleton pattern, providing better resource management and consistency across the application.
@ -264,6 +333,7 @@ $environment = [
- Direct `$wordCensor` access → Use `censor()` methods - Direct `$wordCensor` access → Use `censor()` methods
- `new TorrentPier\Dev()` → Use `dev()` global function - `new TorrentPier\Dev()` → Use `dev()` global function
- Static `Dev::` methods → Use `dev()` instance methods - Static `Dev::` methods → Use `dev()` instance methods
- `\TorrentPier\Legacy\Select::` → Use `\TorrentPier\Legacy\Common\Select::`
### File Structure Changes ### File Structure Changes
- New `/src/` directory for modern PHP classes - New `/src/` directory for modern PHP classes
@ -310,6 +380,23 @@ function processUserInput(string $text): string {
$censoredText = censor()->censorString($input); $censoredText = censor()->censorString($input);
``` ```
### Select Usage
```php
// ✅ Use the new namespace consistently
$languageSelect = \TorrentPier\Legacy\Common\Select::language($currentLang, 'language_field');
// ✅ Store frequently used selects
class AdminPanel {
private string $languageSelect;
private string $timezoneSelect;
public function __construct() {
$this->languageSelect = \TorrentPier\Legacy\Common\Select::language('', 'default_lang');
$this->timezoneSelect = \TorrentPier\Legacy\Common\Select::timezone('', 'timezone');
}
}
```
### Development and Debugging ### Development and Debugging
```php ```php
// ✅ Use instance methods for debugging // ✅ Use instance methods for debugging