|
| 1 | +# Frankenstyle Naming Compliance Changes |
| 2 | + |
| 3 | +This document summarizes the changes made to comply with Moodle's frankenstyle naming conventions. |
| 4 | + |
| 5 | +## Changes Made |
| 6 | + |
| 7 | +### 1. Exception Class |
| 8 | +- **Old**: `onlinejudge_exception` (in `exceptions.php`) |
| 9 | +- **New**: `\local_onlinejudge\exception` (in `classes/exception.php`) |
| 10 | + |
| 11 | +### 2. Judge Base Class |
| 12 | +- **Old**: `judge_base` (in `judgelib.php`) |
| 13 | +- **New**: `\local_onlinejudge\judge\base` (in `classes/judge/base.php`) |
| 14 | + |
| 15 | +### 3. Judge Sandbox Class |
| 16 | +- **Old**: `judge_sandbox` (in `judge/sandbox/lib.php`) |
| 17 | +- **New**: `\local_onlinejudge\judge\sandbox` (in `classes/judge/sandbox.php`) |
| 18 | + |
| 19 | +### 4. Judge Sphere Engine Class |
| 20 | +- **Old**: `judge_sphere_engine` (in `judge/sphere_engine/lib.php`) |
| 21 | +- **New**: `\local_onlinejudge\judge\sphere_engine` (in `classes/judge/sphere_engine.php`) |
| 22 | + |
| 23 | +### 5. Event Class |
| 24 | +- **Old**: `onlinejudge_task_judged` (in `classes/event/onlinejudge_task_judged.php`) |
| 25 | +- **New**: `task_judged` (in `classes/event/task_judged.php`) |
| 26 | +- **Namespace**: Changed from `mod_onlinejudge\event` to `local_onlinejudge\event` |
| 27 | + |
| 28 | +## Backward Compatibility |
| 29 | + |
| 30 | +To ensure existing code continues to work, backward compatibility aliases have been added in `judgelib.php`: |
| 31 | + |
| 32 | +```php |
| 33 | +// Backward compatibility aliases |
| 34 | +if (!class_exists('onlinejudge_exception')) { |
| 35 | + class_alias('\\local_onlinejudge\\exception', 'onlinejudge_exception'); |
| 36 | +} |
| 37 | +if (!class_exists('judge_base')) { |
| 38 | + class_alias('\\local_onlinejudge\\judge\\base', 'judge_base'); |
| 39 | +} |
| 40 | +if (!class_exists('judge_sandbox')) { |
| 41 | + class_alias('\\local_onlinejudge\\judge\\sandbox', 'judge_sandbox'); |
| 42 | +} |
| 43 | +if (!class_exists('judge_sphere_engine')) { |
| 44 | + class_alias('\\local_onlinejudge\\judge\\sphere_engine', 'judge_sphere_engine'); |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +## Files Structure |
| 49 | + |
| 50 | +The new frankenstyle-compliant structure is: |
| 51 | + |
| 52 | +``` |
| 53 | +classes/ |
| 54 | +├── exception.php # \local_onlinejudge\exception |
| 55 | +├── judge/ |
| 56 | +│ ├── base.php # \local_onlinejudge\judge\base |
| 57 | +│ ├── sandbox.php # \local_onlinejudge\judge\sandbox |
| 58 | +│ └── sphere_engine.php # \local_onlinejudge\judge\sphere_engine |
| 59 | +└── event/ |
| 60 | + └── task_judged.php # \local_onlinejudge\event\task_judged |
| 61 | +``` |
| 62 | + |
| 63 | +## Migration Guide |
| 64 | + |
| 65 | +### For New Code |
| 66 | +Use the new namespaced classes: |
| 67 | +```php |
| 68 | +// Use this |
| 69 | +use local_onlinejudge\exception; |
| 70 | +use local_onlinejudge\judge\base; |
| 71 | +use local_onlinejudge\judge\sandbox; |
| 72 | +use local_onlinejudge\judge\sphere_engine; |
| 73 | +use local_onlinejudge\event\task_judged; |
| 74 | +``` |
| 75 | + |
| 76 | +### For Existing Code |
| 77 | +No changes required - old class names will continue to work due to backward compatibility aliases. |
| 78 | + |
| 79 | +## Language Strings |
| 80 | + |
| 81 | +Added new language strings for the renamed event: |
| 82 | +- `event_task_judged` - "Online Judge Task Judged" |
| 83 | +- `event_task_judged_description` - "The event is fired when an online judge task has been judged." |
| 84 | + |
| 85 | +## Benefits |
| 86 | + |
| 87 | +1. **Compliance**: Meets Moodle's frankenstyle naming requirements for plugin database approval |
| 88 | +2. **Autoloading**: Classes can be autoloaded using Moodle's class loader |
| 89 | +3. **Namespace**: Proper namespace organization prevents naming conflicts |
| 90 | +4. **Maintainability**: Clear class organization in the `classes/` directory |
| 91 | +5. **Compatibility**: Existing code continues to work without modification |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- The old files in `judge/` directory are still present for backward compatibility |
| 96 | +- All functions in `judgelib.php` retain their original names (they follow correct naming) |
| 97 | +- The plugin continues to work exactly as before with no functional changes |
0 commit comments