UserConfiguration.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @property string $apiPasswordHash
  5. * @property array{'keep_period':string|false,'keep_max':int|false,'keep_min':int|false,'keep_favourites':bool,'keep_labels':bool,'keep_unreads':bool} $archiving
  6. * @property bool $auto_load_more
  7. * @property bool $auto_remove_article
  8. * @property bool $bottomline_date
  9. * @property bool $bottomline_favorite
  10. * @property bool $bottomline_link
  11. * @property bool $bottomline_read
  12. * @property bool $bottomline_sharing
  13. * @property bool $bottomline_tags
  14. * @property bool $bottomline_myLabels
  15. * @property string $content_width
  16. * @property-read int $default_state
  17. * @property string $default_view
  18. * @property string|bool $display_categories
  19. * @property string $show_tags
  20. * @property int $show_tags_max
  21. * @property string $show_author_date
  22. * @property string $show_feed_name
  23. * @property string $show_article_icons
  24. * @property bool $display_posts
  25. * @property string $email_validation_token
  26. * @property-read bool $enabled
  27. * @property string $feverKey
  28. * @property bool $hide_read_feeds
  29. * @property int $html5_notif_timeout
  30. * @property-read bool $is_admin
  31. * @property int|null $keep_history_default
  32. * @property string $language
  33. * @property string $timezone
  34. * @property bool $lazyload
  35. * @property string $mail_login
  36. * @property bool $mark_updated_article_unread
  37. * @property array<string,bool|int> $mark_when
  38. * @property int $max_posts_per_rss
  39. * @property-read array<string,int> $limits
  40. * @property int|null $old_entries
  41. * @property bool $onread_jump_next
  42. * @property string $passwordHash
  43. * @property int $posts_per_page
  44. * @property array<array{'get'?:string,'name'?:string,'order'?:string,'search'?:string,'state'?:int,'url'?:string,'token'?:string}> $queries
  45. * @property bool $reading_confirm
  46. * @property int $since_hours_posts_per_rss
  47. * @property bool $show_fav_unread
  48. * @property bool $show_favicons
  49. * @property bool $icons_as_emojis
  50. * @property int $simplify_over_n_feeds
  51. * @property bool $show_nav_buttons
  52. * @property 'ASC'|'DESC' $sort_order
  53. * @property array<string,array<string>> $sharing
  54. * @property array<string,string> $shortcuts
  55. * @property bool $sides_close_article
  56. * @property bool $sticky_post
  57. * @property string $theme
  58. * @property string $darkMode
  59. * @property string $token
  60. * @property bool $topline_date
  61. * @property bool $topline_display_authors
  62. * @property bool $topline_favorite
  63. * @property bool $topline_link
  64. * @property bool $topline_read
  65. * @property bool $topline_summary
  66. * @property string $topline_website
  67. * @property string $topline_thumbnail
  68. * @property int $ttl_default
  69. * @property int $dynamic_opml_ttl_default
  70. * @property-read bool $unsafe_autologin_enabled
  71. * @property string $view_mode
  72. * @property array<string,bool|int|string> $volatile
  73. * @property array<string,array<string,mixed>> $extensions
  74. */
  75. final class FreshRSS_UserConfiguration extends Minz_Configuration {
  76. use FreshRSS_FilterActionsTrait;
  77. /** @throws Minz_FileNotExistException */
  78. public static function init(string $config_filename, ?string $default_filename = null): FreshRSS_UserConfiguration {
  79. parent::register('user', $config_filename, $default_filename);
  80. try {
  81. return parent::get('user');
  82. } catch (Minz_ConfigurationNamespaceException $ex) {
  83. FreshRSS::killApp($ex->getMessage());
  84. }
  85. }
  86. /**
  87. * Access the default configuration for users.
  88. * @throws Minz_FileNotExistException
  89. */
  90. public static function default(): FreshRSS_UserConfiguration {
  91. static $default_user_conf = null;
  92. if ($default_user_conf == null) {
  93. $namespace = 'user_default';
  94. FreshRSS_UserConfiguration::register($namespace, '_', FRESHRSS_PATH . '/config-user.default.php');
  95. $default_user_conf = FreshRSS_UserConfiguration::get($namespace);
  96. }
  97. return $default_user_conf;
  98. }
  99. /**
  100. * @param non-empty-string $key
  101. * @return array<int|string,mixed>|null
  102. */
  103. public function attributeArray(string $key): ?array {
  104. $a = parent::param($key, null);
  105. return is_array($a) ? $a : null;
  106. }
  107. /** @param non-empty-string $key */
  108. public function attributeBool(string $key): ?bool {
  109. $a = parent::param($key, null);
  110. return is_bool($a) ? $a : null;
  111. }
  112. /** @param non-empty-string $key */
  113. public function attributeInt(string $key): ?int {
  114. $a = parent::param($key, null);
  115. return is_numeric($a) ? (int)$a : null;
  116. }
  117. /** @param non-empty-string $key */
  118. public function attributeString(string $key): ?string {
  119. $a = parent::param($key, null);
  120. return is_string($a) ? $a : null;
  121. }
  122. /**
  123. * @param non-empty-string $key
  124. * @param array<string,mixed>|mixed|null $value Value, not HTML-encoded
  125. */
  126. public function _attribute(string $key, $value = null): void {
  127. parent::_param($key, $value);
  128. }
  129. }