Files
FreshRSS/app/Models/ViewMode.php
T
Alexandre Alapetite fd3f75b3a2 Require PHP 8.2+ (#9470)
Drop PHP 8.1 (EOL December 2025), drop Ubuntu 22.04 (EOL May 2027, and there is now 24.04 and 26.04 LTS).
PHP 8.1 is already EOL, and Debian, Alpine, Fedora, Red Hat, Synology have dropped PHP 8.1 already.
See https://github.com/FreshRSS/FreshRSS/discussions/5474#discussioncomment-16791937

With PHP 8.6 around the corner and in particular a relevant `FILTER_FLAG_GLOBAL_RANGE` in PHP 8.2+.
* https://www.php.net/releases/8.2
* https://www.php.net/filter.constants.validation#constant.filter-flag-global-range
* https://www.php.net/class.sensitiveparameter
* https://php.watch/versions/8.2/readonly-classes
* https://www.php.net/function.ini-parse-quantity

Allows updating to PHPUnit 11.x instead of 10.x
https://phpunit.de/supported-versions.html

Contributes to https://github.com/FreshRSS/FreshRSS/issues/9475

* Add regression test for FILTER_FLAG_GLOBAL_RANGE
https://github.com/FreshRSS/FreshRSS/pull/9470#discussion_r4371168720
2026-10-26 21:02:32 +01:00

66 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* Represents a view mode option for the reading configuration
*/
final readonly class FreshRSS_ViewMode {
private string $id;
private string $name;
private string $controller;
private string $action;
public function __construct(string $id, string $name, string $controller = 'index', string $action = '') {
$this->id = $id;
$this->name = $name;
$this->controller = $controller;
$this->action = $action ?: $id;
}
public function id(): string {
return $this->id;
}
public function name(): string {
return $this->name;
}
public function controller(): string {
return $this->controller;
}
public function action(): string {
return $this->action;
}
/**
* @return array<string,FreshRSS_ViewMode> Mode ID => FreshRSS_ViewMode
*/
public static function getDefaultModes(): array {
return [
'normal' => new self(id: 'normal', name: _t('conf.reading.view.normal'), controller: 'index', action: 'normal'),
'reader' => new self(id: 'reader', name: _t('conf.reading.view.reader'), controller: 'index', action: 'reader'),
'global' => new self(id: 'global', name: _t('conf.reading.view.global'), controller: 'index', action: 'global'),
];
}
/**
* @return array<string,FreshRSS_ViewMode> Mode ID => FreshRSS_ViewMode
*/
public static function getAllModes(): array {
$modes = self::getDefaultModes();
// Allow extensions to add their own view modes
$extensionModes = Minz_ExtensionManager::callHook(Minz_HookType::ViewModes, []);
if (is_array($extensionModes)) {
foreach ($extensionModes as $mode) {
if ($mode instanceof FreshRSS_ViewMode) {
$modes[$mode->id()] = $mode;
}
}
}
return $modes;
}
}