2026-04-17 19:56:58 +03:00
|
|
|
# Bootstrap Contexts
|
|
|
|
|
|
|
|
|
|
`XC_Bootstrap` is the single entry point for system initialization.
|
|
|
|
|
Each context loads only the subsystems required for its execution path.
|
2026-06-15 18:27:23 +03:00
|
|
|
The context is expressed as a `BootContext` enum value.
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Quick Reference
|
|
|
|
|
|
2026-06-15 18:27:23 +03:00
|
|
|
| Enum case | Typical usage |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
| `BootContext::MINIMAL` | Scripts that need only paths/config |
|
|
|
|
|
| `BootContext::CLI` | Cron jobs and CLI commands |
|
|
|
|
|
| `BootContext::STREAM` | Streaming endpoints (`live`, `vod`, `timeshift`) |
|
|
|
|
|
| `BootContext::ADMIN` | Admin/reseller panel |
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Context Details
|
|
|
|
|
|
2026-06-15 18:27:23 +03:00
|
|
|
### BootContext::MINIMAL
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
Loads constants, paths, config, logger, and error handlers.
|
|
|
|
|
No database connection.
|
|
|
|
|
|
|
|
|
|
Includes:
|
|
|
|
|
|
2026-06-26 15:56:15 +03:00
|
|
|
- Composer PSR-4 autoloader (`vendor/autoload.php`)
|
2026-04-17 19:56:58 +03:00
|
|
|
- path constants (`MAIN_HOME`, `INCLUDES_PATH`, ...)
|
|
|
|
|
- logger (`Logger::init()`)
|
|
|
|
|
- error helpers (`generateError()`, `generate404()`)
|
|
|
|
|
|
|
|
|
|
Excludes: DB, Redis, sessions, translator, admin APIs.
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
require_once '/home/xc_vm/bootstrap.php';
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext::MINIMAL);
|
2026-04-17 19:56:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-06-15 18:27:23 +03:00
|
|
|
### BootContext::CLI
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
Used for cron and CLI tasks.
|
2026-06-15 18:27:23 +03:00
|
|
|
Adds database and legacy core initialization over `MINIMAL`.
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
Includes:
|
|
|
|
|
|
|
|
|
|
- DB connection
|
|
|
|
|
- `LegacyInitializer`
|
|
|
|
|
- optional Redis (`'redis' => true`)
|
|
|
|
|
- optional process title (`'process' => '...'`)
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
require_once '/home/xc_vm/bootstrap.php';
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext::CLI, [
|
2026-04-17 19:56:58 +03:00
|
|
|
'cached' => true,
|
|
|
|
|
'process' => 'xc_vm: my-job',
|
|
|
|
|
]);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-06-15 18:27:23 +03:00
|
|
|
### BootContext::STREAM
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
Lightweight context for high-load streaming endpoints.
|
|
|
|
|
|
|
|
|
|
Includes:
|
|
|
|
|
|
|
|
|
|
- DB connection (`cached=true`)
|
|
|
|
|
- flood protection and host verification
|
|
|
|
|
|
|
|
|
|
Excludes: Redis, translator, admin APIs, sessions.
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
require_once '/home/xc_vm/bootstrap.php';
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext::STREAM, ['cached' => true]);
|
2026-04-17 19:56:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-06-15 18:27:23 +03:00
|
|
|
### BootContext::ADMIN
|
2026-04-17 19:56:58 +03:00
|
|
|
|
|
|
|
|
Full initialization for admin/reseller panel.
|
|
|
|
|
|
|
|
|
|
Includes:
|
|
|
|
|
|
|
|
|
|
- secure session (`SameSite=Strict`)
|
|
|
|
|
- DB connection (`cached=false`)
|
|
|
|
|
- `LegacyInitializer`
|
|
|
|
|
- Redis
|
|
|
|
|
- admin/reseller APIs
|
|
|
|
|
- translator
|
|
|
|
|
- shutdown handler
|
|
|
|
|
- status constants and admin globals
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
require_once '/home/xc_vm/bootstrap.php';
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext::ADMIN);
|
2026-04-17 19:56:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Subsystem Matrix
|
|
|
|
|
|
|
|
|
|
| Subsystem | MINIMAL | CLI | STREAM | ADMIN |
|
|
|
|
|
| --- | :---: | :---: | :---: | :---: |
|
|
|
|
|
| Constants/paths | ✅ | ✅ | ✅ | ✅ |
|
|
|
|
|
| Logger | ✅ | ✅ | ✅ | ✅ |
|
|
|
|
|
| Flood protection | — | — | ✅ | ✅ |
|
|
|
|
|
| Host verification | — | — | ✅ | ✅ |
|
|
|
|
|
| Database | — | ✅ | ✅ | ✅ |
|
|
|
|
|
| LegacyInitializer | — | ✅ | — | ✅ |
|
|
|
|
|
| Redis | — | opt | — | ✅ |
|
|
|
|
|
| Session | — | — | — | ✅ |
|
|
|
|
|
| Admin API | — | — | — | ✅ |
|
|
|
|
|
| Translator | — | — | — | ✅ |
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## `boot()` options
|
|
|
|
|
|
|
|
|
|
```php
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext $context, array $options = []);
|
2026-04-17 19:56:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
| Option | Type | Default | Description |
|
|
|
|
|
| --- | --- | --- | --- |
|
2026-06-15 18:27:23 +03:00
|
|
|
| `cached` | `bool` | `true` for STREAM, `false` otherwise | Use cached settings |
|
|
|
|
|
| `redis` | `bool` | `true` for ADMIN, `false` otherwise | Connect Redis |
|
2026-04-17 19:56:58 +03:00
|
|
|
| `process` | `string` | `''` | Process title for CLI |
|
|
|
|
|
| `shutdown` | `callable` | built-in | Override shutdown callback |
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Idempotency
|
|
|
|
|
|
|
|
|
|
`boot()` is executed once per process. Repeated calls are ignored.
|
|
|
|
|
|
|
|
|
|
```php
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::boot(BootContext::ADMIN);
|
|
|
|
|
XC_Bootstrap::boot(BootContext::CLI); // ignored
|
2026-04-17 19:56:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
For tests:
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
XC_Bootstrap::reset();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Public Methods
|
|
|
|
|
|
|
|
|
|
```php
|
2026-06-15 18:27:23 +03:00
|
|
|
XC_Bootstrap::getContext(): ?BootContext
|
2026-04-17 19:56:58 +03:00
|
|
|
XC_Bootstrap::isBooted(): bool
|
|
|
|
|
XC_Bootstrap::isCli(): bool
|
|
|
|
|
XC_Bootstrap::getDatabase(): ?Database
|
|
|
|
|
XC_Bootstrap::getContainer(): ServiceContainer
|
|
|
|
|
```
|
2026-06-26 15:56:15 +03:00
|
|
|
|
|
|
|
|
## Related files
|
|
|
|
|
|
|
|
|
|
| File | Role |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
| `src/bootstrap.php` | Defines MAIN_HOME, requires the Composer autoloader, boots a context |
|
|
|
|
|
| `src/Core/Enum/BootContext.php` | Boot context enum |
|
|
|
|
|
| `src/Core/Init/LegacyInitializer.php` | Per-context legacy initialization |
|