From fe7d9bbcd68660a59b813346c236b61b25a51c80 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 11 May 2023 12:53:32 +0200 Subject: Typed view model classes (#5380) * Typed view model classes * Add ability to provide a typed view model class to a controller * Use `::class` instead of string for referring to classes * Examplified with `stats` and `javascript` controllers / views (more to do) * Also useful for extensions (my usecase today), which did not have the ability to define own view model attributes before. * Typo --- app/Models/View.php | 44 ---------------------------------- app/Models/ViewJavascript.php | 16 +++++++++++++ app/Models/ViewStats.php | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 app/Models/ViewJavascript.php create mode 100644 app/Models/ViewStats.php (limited to 'app/Models') diff --git a/app/Models/View.php b/app/Models/View.php index 3c56afa0e..cfa06da62 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -109,10 +109,6 @@ class FreshRSS_View extends Minz_View { // Form login /** @var int */ public $cookie_days; - /** @var string */ - public $nonce; - /** @var string */ - public $salt1; // Registration /** @var bool */ @@ -174,44 +170,4 @@ class FreshRSS_View extends Minz_View { /** @var array */ public $message; - // Statistics - /** @var float */ - public $average; - /** @var float */ - public $averageDayOfWeek; - /** @var float */ - public $averageHour; - /** @var float */ - public $averageMonth; - /** @var array */ - public $days; - /** @var array> */ - public $entryByCategory; - /** @var array */ - public $entryCount; - /** @var array> */ - public $feedByCategory; - /** @var array */ - public $hours24Labels; - /** @var array>> */ - public $idleFeeds; - /** @var array */ - public $last30DaysLabel; - /** @var array */ - public $last30DaysLabels; - /** @var array */ - public $months; - /** @var array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false */ - public $repartition; - /** @var array{'main_stream':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false,'all_feeds':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false} */ - public $repartitions; - /** @var array */ - public $repartitionDayOfWeek; - /** @var array|array */ - public $repartitionHour; - /** @var array */ - public $repartitionMonth; - /** @var array */ - public $topFeed; - } diff --git a/app/Models/ViewJavascript.php b/app/Models/ViewJavascript.php new file mode 100644 index 000000000..f14810572 --- /dev/null +++ b/app/Models/ViewJavascript.php @@ -0,0 +1,16 @@ + */ + public $categories; + /** @var array */ + public $feeds; + /** @var array */ + public $tags; + + /** @var string */ + public $nonce; + /** @var string */ + public $salt1; +} diff --git a/app/Models/ViewStats.php b/app/Models/ViewStats.php new file mode 100644 index 000000000..03e0bc00d --- /dev/null +++ b/app/Models/ViewStats.php @@ -0,0 +1,55 @@ + */ + public $categories; + /** @var FreshRSS_Feed|null */ + public $feed; + /** @var array */ + public $feeds; + /** @var bool */ + public $displaySlider; + + /** @var float */ + public $average; + /** @var float */ + public $averageDayOfWeek; + /** @var float */ + public $averageHour; + /** @var float */ + public $averageMonth; + /** @var array */ + public $days; + /** @var array> */ + public $entryByCategory; + /** @var array */ + public $entryCount; + /** @var array> */ + public $feedByCategory; + /** @var array */ + public $hours24Labels; + /** @var array>> */ + public $idleFeeds; + /** @var array */ + public $last30DaysLabel; + /** @var array */ + public $last30DaysLabels; + /** @var array */ + public $months; + /** @var array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false */ + public $repartition; + /** @var array{'main_stream':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false,'all_feeds':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false} */ + public $repartitions; + /** @var array */ + public $repartitionDayOfWeek; + /** @var array|array */ + public $repartitionHour; + /** @var array */ + public $repartitionMonth; + /** @var array */ + public $topFeed; + +} -- cgit v1.2.3