Skip to content

Commit

Permalink
Fix type hints regressions (#4855)
Browse files Browse the repository at this point in the history
Fix regressions from #4561

Example:

```
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to checkToken() must be an instance of FreshRSS_UserConfiguration, instance of Minz_Configuration given, called in /var/www/FreshRSS/p/api/greader.php on line 1091 and defined in /var/www/FreshRSS/p/api/greader.php:223
Stack trace:
#0 /var/www/FreshRSS/p/api/greader.php(1091): checkToken()
#1 {main}
  thrown in /var/www/FreshRSS/p/api/greader.php on line 223
```

Improvement of #4110
  • Loading branch information
Alkarex committed Nov 15, 2022
1 parent 07c9406 commit 42eeb40
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/Controllers/updateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function checkAction() {
}

public function applyAction() {
if (Minz_Configuration::get('system')->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) {
if (FreshRSS_Context::$system_conf->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) {
Minz_Request::forward(array('c' => 'update'), true);
}

Expand Down
14 changes: 2 additions & 12 deletions app/Models/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ class FreshRSS_Context {
public static function initSystem($reload = false) {
if ($reload || FreshRSS_Context::$system_conf == null) {
//TODO: Keep in session what we need instead of always reloading from disk
Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');
/**
* @var FreshRSS_SystemConfiguration $system_conf
*/
$system_conf = Minz_Configuration::get('system');
FreshRSS_Context::$system_conf = $system_conf;
FreshRSS_Context::$system_conf = FreshRSS_SystemConfiguration::init(DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');
// Register the configuration setter for the system configuration
$configurationSetter = new FreshRSS_ConfigurationSetter();
FreshRSS_Context::$system_conf->_configurationSetter($configurationSetter);
Expand All @@ -88,17 +83,12 @@ public static function initUser($username = '', $userMustExist = true) {
(!$userMustExist || FreshRSS_user_Controller::userExists($username))) {
try {
//TODO: Keep in session what we need instead of always reloading from disk
Minz_Configuration::register('user',
FreshRSS_Context::$user_conf = FreshRSS_UserConfiguration::init(
USERS_PATH . '/' . $username . '/config.php',
FRESHRSS_PATH . '/config-user.default.php',
FreshRSS_Context::$system_conf->configurationSetter());

Minz_Session::_param('currentUser', $username);
/**
* @var FreshRSS_UserConfiguration $user_conf
*/
$user_conf = Minz_Configuration::get('user');
FreshRSS_Context::$user_conf = $user_conf;
} catch (Exception $ex) {
Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/' . LOG_FILENAME);
}
Expand Down
6 changes: 5 additions & 1 deletion app/Models/SystemConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
* @property string $unsafe_autologin_enabled
* @property-read array<string> $trusted_sources
*/
class FreshRSS_SystemConfiguration extends Minz_Configuration {
final class FreshRSS_SystemConfiguration extends Minz_Configuration {

public static function init($config_filename, $default_filename = null): FreshRSS_SystemConfiguration {
parent::register('system', $config_filename, $default_filename);
return parent::get('system');
}
}
6 changes: 5 additions & 1 deletion app/Models/UserConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
* @property string $view_mode
* @property array<string,mixed> $volatile
*/
class FreshRSS_UserConfiguration extends Minz_Configuration {
final class FreshRSS_UserConfiguration extends Minz_Configuration {

public static function init($config_filename, $default_filename = null, $configuration_setter = null): FreshRSS_UserConfiguration {
parent::register('user', $config_filename, $default_filename, $configuration_setter);
return parent::get('user');
}
}
8 changes: 2 additions & 6 deletions app/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,15 @@ function freshrss_already_installed() {
// A configuration file already exists, we try to load it.
$system_conf = null;
try {
Minz_Configuration::register('system', $conf_path);
/**
* @var FreshRSS_SystemConfiguration $system_conf
*/
$system_conf = Minz_Configuration::get('system');
$system_conf = FreshRSS_SystemConfiguration::init($conf_path);
} catch (Minz_FileNotExistException $e) {
return false;
}

// ok, the global conf exists… but what about default user conf?
$current_user = $system_conf->default_user;
try {
Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php'));
FreshRSS_UserConfiguration::init(USERS_PATH . '/' . $current_user . '/config.php');
} catch (Minz_FileNotExistException $e) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions app/layout/aside_configure.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<nav class="nav nav-list aside" id="aside_feed">
<a class="toggle_aside" href="#close"><?= _i('close') ?></a>

<ul>
<li class="nav-header"><?= _t('gen.menu.account') ?>: <?= htmlspecialchars(Minz_Session::param('currentUser', '_'), ENT_NOQUOTES, 'UTF-8')?></li>
<li class="nav-header"><?= _t('gen.menu.account') ?>: <?= htmlspecialchars(Minz_Session::param('currentUser', '_'), ENT_NOQUOTES, 'UTF-8')?></li>
<li class="item<?= Minz_Request::controllerName() === 'user' && Minz_Request::actionName() === 'profile' ? ' active' : '' ?>">
<a href="<?= _url('user', 'profile') ?>"><?= _t('gen.menu.user_profile') ?></a>
</li>
Expand Down Expand Up @@ -54,7 +54,7 @@
<li class="item<?= Minz_Request::controllerName() === 'update' && Minz_Request::actionName() === 'checkInstall' ? ' active' : '' ?>">
<a href="<?= _url('update', 'checkInstall') ?>"><?= _t('gen.menu.check_install') ?></a>
</li>
<?php if (!Minz_Configuration::get('system')->disable_update) { ?>
<?php if (!FreshRSS_Context::$system_conf->disable_update) { ?>
<li class="item<?= Minz_Request::controllerName() === 'update' && Minz_Request::actionName() === 'index' ? ' active' : '' ?>">
<a href="<?= _url('update', 'index') ?>"><?= _t('gen.menu.update') ?></a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/layout/header.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<li class="item"><a href="<?= _url('user', 'manage') ?>"><?= _t('gen.menu.user_management') ?></a></li>
<li class="item"><a href="<?= _url('auth', 'index') ?>"><?= _t('gen.menu.authentication') ?></a></li>
<li class="item"><a href="<?= _url('update', 'checkInstall') ?>"><?= _t('gen.menu.check_install') ?></a></li>
<?php if (!Minz_Configuration::get('system')->disable_update) { ?>
<?php if (!FreshRSS_Context::$system_conf->disable_update) { ?>
<li class="item"><a href="<?= _url('update', 'index') ?>"><?= _t('gen.menu.update') ?></a></li>
<?php } ?>
<?= Minz_ExtensionManager::callHook('menu_admin_entry') ?>
Expand Down
6 changes: 3 additions & 3 deletions lib/Minz/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Minz_Configuration {
* @param object $configuration_setter an optional helper to set values in configuration
*/
public static function register($namespace, $config_filename, $default_filename = null, $configuration_setter = null) {
self::$config_list[$namespace] = new Minz_Configuration(
self::$config_list[$namespace] = new static(
$namespace, $config_filename, $default_filename, $configuration_setter
);
}
Expand All @@ -51,7 +51,7 @@ public static function load($filename) {
* Return the configuration related to a given namespace.
*
* @param string $namespace the name of the configuration to get.
* @return Minz_Configuration object
* @return static object
* @throws Minz_ConfigurationNamespaceException if the namespace does not exist.
*/
public static function get($namespace) {
Expand Down Expand Up @@ -117,7 +117,7 @@ public function addExtension($ext_name) {
* @param string $default_filename the file containing default values, null by default.
* @param object $configuration_setter an optional helper to set values in configuration
*/
private function __construct($namespace, $config_filename, $default_filename = null, $configuration_setter = null) {
private final function __construct($namespace, $config_filename, $default_filename = null, $configuration_setter = null) {
$this->namespace = $namespace;
$this->config_filename = $config_filename;
$this->default_filename = $default_filename;
Expand Down

0 comments on commit 42eeb40

Please sign in to comment.