diff options
| author | 2023-11-24 14:50:03 +0100 | |
|---|---|---|
| committer | 2023-11-24 14:50:03 +0100 | |
| commit | 76cbfadcdfdcbf675b83f6162a229938aca3bbe1 (patch) | |
| tree | 01aa96c6774dcf2a692fd3062ae1ffccb0a8bfa0 /lib | |
| parent | bc9ef0d188fa43d4a4d06835f74e2d94799b65c6 (diff) | |
Fix types for extensions (#5901)
* Fix types for extensions
To accompany https://github.com/FreshRSS/Extensions/pull/185
* Avoid bug redeclared function
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/Extension.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Mailer.php | 14 | ||||
| -rw-r--r-- | lib/Minz/View.php | 32 |
3 files changed, 34 insertions, 14 deletions
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index e227eb964..a8f883eb6 100644 --- a/lib/Minz/Extension.php +++ b/lib/Minz/Extension.php @@ -164,7 +164,7 @@ abstract class Minz_Extension { * Return the url for a given file. * * @param string $filename name of the file to serve. - * @param 'css'|'js' $type the type (js or css) of the file to serve. + * @param 'css'|'js'|'svg' $type the type (js or css or svg) of the file to serve. * @param bool $isStatic indicates if the file is a static file or a user file. Default is static. * @return string url corresponding to the file. */ diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.php index bd5e97ceb..86c5c33da 100644 --- a/lib/Minz/Mailer.php +++ b/lib/Minz/Mailer.php @@ -39,10 +39,18 @@ class Minz_Mailer { private int $debug_level; /** - * Constructor. + * @phpstan-param class-string|'' $viewType + * @param string $viewType Name of the class (inheriting from Minz_View) to use for the view model */ - public function __construct () { - $this->view = new Minz_View(); + public function __construct(string $viewType = '') { + $view = null; + if ($viewType !== '' && class_exists($viewType)) { + $view = new $viewType(); + if (!($view instanceof Minz_View)) { + $view = null; + } + } + $this->view = $view ?? new Minz_View(); $this->view->_layout(null); $this->view->attributeParams(); diff --git a/lib/Minz/View.php b/lib/Minz/View.php index da6e55a23..f67cf6277 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -157,7 +157,7 @@ class Minz_View { /** * Choose the current view layout. - * @param string|null $layout the layout name to use, false to use no layouts. + * @param string|null $layout the layout name to use, null to use no layouts. */ public function _layout(?string $layout): void { if ($layout != null) { @@ -205,7 +205,7 @@ class Minz_View { */ public static function headStyle(): string { $styles = ''; - foreach(self::$styles as $style) { + foreach (self::$styles as $style) { $styles .= '<link rel="stylesheet" ' . ($style['media'] === 'all' ? '' : 'media="' . $style['media'] . '" ') . 'href="' . $style['url'] . '" />'; @@ -220,10 +220,13 @@ class Minz_View { * @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated */ public static function prependStyle(string $url, string $media = 'all', bool $cond = false): void { - array_unshift (self::$styles, array ( + if ($url === '') { + return; + } + array_unshift(self::$styles, [ 'url' => $url, 'media' => $media, - )); + ]); } /** @@ -233,10 +236,13 @@ class Minz_View { * @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated */ public static function appendStyle(string $url, string $media = 'all', bool $cond = false): void { - self::$styles[] = array ( + if ($url === '') { + return; + } + self::$styles[] = [ 'url' => $url, 'media' => $media, - ); + ]; } /** @@ -298,12 +304,15 @@ class Minz_View { * @param string $id Add a script `id` attribute */ public static function prependScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void { - array_unshift(self::$scripts, array ( + if ($url === '') { + return; + } + array_unshift(self::$scripts, [ 'url' => $url, 'defer' => $defer, 'async' => $async, 'id' => $id, - )); + ]); } /** @@ -315,12 +324,15 @@ class Minz_View { * @param string $id Add a script `id` attribute */ public static function appendScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void { - self::$scripts[] = array ( + if ($url === '') { + return; + } + self::$scripts[] = [ 'url' => $url, 'defer' => $defer, 'async' => $async, 'id' => $id, - ); + ]; } /** |
