--- applyTo: "**/*.php" --- # PHP Conventions — XC_VM XC_VM is a PHP 8.1+ modular monolith **migrated to Composer PSR-4** (`XcVm\` → `src/`). The application root is `src/` (composer.json, vendor/, bootstrap.php all live there). `short_open_tag=1` is on — view templates use `query('SELECT * FROM streams WHERE id = ?;', $id)`. Terminate the SQL string with a semicolon. - Legacy superglobals (`$db`, `$rSettings`, `$rUserInfo`, `$rServers`) are still bridged by `LegacyInitializer` for legacy code — preserve them when editing legacy files, but never introduce new global state in new code. ## Naming - **Classes:** PascalCase (`StreamService`, `DatabaseHandler`) - **Methods:** camelCase (`getById`, `processStream`) - **Constants:** UPPER_SNAKE_CASE; for typed sets prefer enums (`BootContext`, `ModuleState`) over new string constants - **DB columns in queries:** snake_case as stored ## Class patterns - New domain code follows **Controller → Service → Repository** (see `docs/en/development/architecture.md`). - Prefer constructor injection for collaborators; use the `DatabaseAware` trait for the shared connection. ## Comments - **New code:** English comments and DocBlocks (keep `@param`, `@return`, `@package` tags in English). - **Legacy files** carry Russian-language DocBlocks in some files. Do NOT mass-translate; translate only a file you are already editing for another reason, or when asked. Don't mix languages within one comment block. ## Error handling - Prefer typed exceptions from the `XcVmException` hierarchy for new code. - For fatal API responses the codebase uses `exit(json_encode(...))` — match the surrounding handler. - Do NOT wrap existing code in try-catch "just in case". ## What NOT to do - Do NOT run `composer install` on a deploy path, and do NOT add Composer dependencies casually. - Do NOT reintroduce `setDb()` static injection or new `global` usage in new code. - Do NOT mass-migrate legacy files to namespaces / `strict_types` / DI without an explicit request — keep changes surgical. - Do NOT add PHPDoc or type annotations to unchanged code.