diff options
| author | 2023-05-11 12:53:32 +0200 | |
|---|---|---|
| committer | 2023-05-11 12:53:32 +0200 | |
| commit | fe7d9bbcd68660a59b813346c236b61b25a51c80 (patch) | |
| tree | 95be837c2838659a3ea72974c9f9b18b1ee634ca /app/Models | |
| parent | 2343f0ded14ac6970575c23e4de34e536241b623 (diff) | |
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
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/View.php | 44 | ||||
| -rw-r--r-- | app/Models/ViewJavascript.php | 16 | ||||
| -rw-r--r-- | app/Models/ViewStats.php | 55 |
3 files changed, 71 insertions, 44 deletions
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<string,string> */ public $message; - // Statistics - /** @var float */ - public $average; - /** @var float */ - public $averageDayOfWeek; - /** @var float */ - public $averageHour; - /** @var float */ - public $averageMonth; - /** @var array<string> */ - public $days; - /** @var array<string,array<int,int|string>> */ - public $entryByCategory; - /** @var array<int,int> */ - public $entryCount; - /** @var array<string,array<int,int|string>> */ - public $feedByCategory; - /** @var array<int, string> */ - public $hours24Labels; - /** @var array<string,array<int,array<string,int|string>>> */ - public $idleFeeds; - /** @var array<int,string> */ - public $last30DaysLabel; - /** @var array<int,string> */ - public $last30DaysLabels; - /** @var array<string,string> */ - 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<int,int> */ - public $repartitionDayOfWeek; - /** @var array<string,int>|array<int,int> */ - public $repartitionHour; - /** @var array<int,int> */ - public $repartitionMonth; - /** @var array<array{'id':int,'name':string,'category':string,'count':int}> */ - 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 @@ +<?php + +final class FreshRSS_ViewJavascript extends FreshRSS_View { + + /** @var array<FreshRSS_Category> */ + public $categories; + /** @var array<FreshRSS_Feed> */ + public $feeds; + /** @var array<FreshRSS_Tag> */ + 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 @@ +<?php + +final class FreshRSS_ViewStats extends FreshRSS_View { + + /** @var FreshRSS_Category|null */ + public $default_category; + /** @var array<FreshRSS_Category> */ + public $categories; + /** @var FreshRSS_Feed|null */ + public $feed; + /** @var array<FreshRSS_Feed> */ + public $feeds; + /** @var bool */ + public $displaySlider; + + /** @var float */ + public $average; + /** @var float */ + public $averageDayOfWeek; + /** @var float */ + public $averageHour; + /** @var float */ + public $averageMonth; + /** @var array<string> */ + public $days; + /** @var array<string,array<int,int|string>> */ + public $entryByCategory; + /** @var array<int,int> */ + public $entryCount; + /** @var array<string,array<int,int|string>> */ + public $feedByCategory; + /** @var array<int, string> */ + public $hours24Labels; + /** @var array<string,array<int,array<string,int|string>>> */ + public $idleFeeds; + /** @var array<int,string> */ + public $last30DaysLabel; + /** @var array<int,string> */ + public $last30DaysLabels; + /** @var array<string,string> */ + 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<int,int> */ + public $repartitionDayOfWeek; + /** @var array<string,int>|array<int,int> */ + public $repartitionHour; + /** @var array<int,int> */ + public $repartitionMonth; + /** @var array<array{'id':int,'name':string,'category':string,'count':int}> */ + public $topFeed; + +} |
