NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Services\Binaries; |
||
| 6 | |||
| 7 | use App\Models\Settings; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Configuration DTO for Binaries processing. |
||
| 11 | * Encapsulates all settings in an immutable object for easier testing and injection. |
||
| 12 | */ |
||
| 13 | final readonly class BinariesConfig |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 14 | { |
||
| 15 | public function __construct( |
||
| 16 | public int $messageBuffer = 20000, |
||
| 17 | public bool $compressedHeaders = true, |
||
| 18 | public bool $partRepair = true, |
||
| 19 | public bool $newGroupScanByDays = false, |
||
| 20 | public int $newGroupMessagesToScan = 50000, |
||
| 21 | public int $newGroupDaysToScan = 3, |
||
| 22 | public int $partRepairLimit = 15000, |
||
| 23 | public int $partRepairMaxTries = 3, |
||
| 24 | public int $partsChunkSize = 5000, |
||
| 25 | public int $binariesUpdateChunkSize = 1000, |
||
| 26 | public bool $echoCli = false, |
||
| 27 | ) {} |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Create configuration from application settings. |
||
| 31 | */ |
||
| 32 | public static function fromSettings(): self |
||
| 33 | { |
||
| 34 | return new self( |
||
| 35 | messageBuffer: self::getSettingInt('maxmssgs', 20000), |
||
| 36 | compressedHeaders: (bool) config('nntmux_nntp.compressed_headers'), |
||
| 37 | partRepair: self::getSettingInt('partrepair', 1) === 1, |
||
| 38 | newGroupScanByDays: self::getSettingInt('newgroupscanmethod', 0) === 1, |
||
| 39 | newGroupMessagesToScan: self::getSettingInt('newgroupmsgstoscan', 50000), |
||
| 40 | newGroupDaysToScan: self::getSettingInt('newgroupdaystoscan', 3), |
||
| 41 | partRepairLimit: self::getSettingInt('maxpartrepair', 15000), |
||
| 42 | partRepairMaxTries: self::getSettingInt('partrepairmaxtries', 3), |
||
| 43 | partsChunkSize: max(100, (int) config('nntmux.parts_chunk_size', 5000)), |
||
| 44 | binariesUpdateChunkSize: max(100, (int) config('nntmux.binaries_update_chunk_size', 1000)), |
||
| 45 | echoCli: (bool) config('nntmux.echocli'), |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | |||
| 49 | private static function getSettingInt(string $key, int $default): int |
||
| 50 | { |
||
| 51 | $value = Settings::settingValue($key); |
||
| 52 | |||
| 53 | return $value !== '' ? (int) $value : $default; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 |