@@ -11,6 +11,7 @@ class Minz_View {
1111 private const VIEWS_PATH_NAME = '/views ' ;
1212 private const LAYOUT_PATH_NAME = '/layout/ ' ;
1313 private const LAYOUT_DEFAULT = 'layout ' ;
14+
1415 /** @var string */
1516 private $ view_filename = '' ;
1617 /** @var string */
@@ -19,14 +20,14 @@ class Minz_View {
1920 private static $ base_pathnames = array (APP_PATH );
2021 /** @var string */
2122 private static $ title = '' ;
22- /** @var array<array< string, string>|string > */
23- private static $ styles = array () ;
24- /** @var array<array< string, bool| string>| string> */
25- private static $ scripts = array () ;
26- /** @var string|array< string> */
23+ /** @var array<array{'media': string,'url': string} > */
24+ private static $ styles = [] ;
25+ /** @var array<array{'url': string,'id': string,'defer': string,'async':string} > */
26+ private static $ scripts = [] ;
27+ /** @var string|array{'dark'?: string,'light'?:string,'default'?:string} */
2728 private static $ themeColors ;
28- /** @var array<string> */
29- private static $ params = array () ;
29+ /** @var array<string,mixed > */
30+ private static $ params = [] ;
3031
3132 /**
3233 * Determines if a layout is used or not
@@ -117,13 +118,10 @@ public function render(): void {
117118 }
118119 }
119120
120- /**
121- * @return string|false
122- */
123- public function renderToString () {
121+ public function renderToString (): string {
124122 ob_start ();
125123 $ this ->render ();
126- return ob_get_clean ();
124+ return ob_get_clean () ?: '' ;
127125 }
128126
129127 /**
@@ -151,12 +149,11 @@ public function renderHelper(string $helper): void {
151149 /**
152150 * Returns renderHelper() in a string
153151 * @param string $helper the element to be treated
154- * @return false|string
155152 */
156- public function helperToString (string $ helper ) {
153+ public function helperToString (string $ helper ): string {
157154 ob_start ();
158155 $ this ->renderHelper ($ helper );
159- return ob_get_clean ();
156+ return ob_get_clean () ?: '' ;
160157 }
161158
162159 /**
@@ -209,12 +206,10 @@ public static function appendTitle(string $title): void {
209206 */
210207 public static function headStyle (): string {
211208 $ styles = '' ;
212- /** @var array{'media':string,'url':string} $style */
213209 foreach (self ::$ styles as $ style ) {
214210 $ styles .= '<link rel="stylesheet" ' .
215211 ($ style ['media ' ] === 'all ' ? '' : 'media=" ' . $ style ['media ' ] . '" ' ) .
216212 'href=" ' . $ style ['url ' ] . '" /> ' ;
217-
218213 $ styles .= "\n" ;
219214 }
220215
@@ -246,7 +241,7 @@ public static function appendStyle(string $url, string $media = 'all', bool $con
246241 }
247242
248243 /**
249- * @param array< string>| string $themeColors
244+ * @param string|array{'dark'?: string,'light'?:string,'default'?:string} $themeColors
250245 */
251246 public static function appendThemeColors ($ themeColors ): void {
252247 self ::$ themeColors = $ themeColors ;
@@ -257,22 +252,19 @@ public static function appendThemeColors($themeColors): void {
257252 */
258253 public static function metaThemeColor (): string {
259254 $ meta = '' ;
260-
261- if (!empty (self ::$ themeColors ['light ' ])) {
262- $ meta .= '<meta name="theme-color" media="(prefers-color-scheme: light)" content=" ' . htmlspecialchars (self ::$ themeColors ['light ' ]) . '" /> ' ;
263- }
264- if (!empty (self ::$ themeColors ['dark ' ])) {
265- $ meta .= '<meta name="theme-color" media="(prefers-color-scheme: dark)" content=" ' . htmlspecialchars (self ::$ themeColors ['dark ' ]) . '" /> ' ;
266- }
267- if (!empty (self ::$ themeColors ['default ' ])) {
268- $ meta .= '<meta name="theme-color" content=" ' . htmlspecialchars (self ::$ themeColors ['default ' ]) . '" /> ' ;
269- }
270- if (empty (self ::$ themeColors ['default ' ]) && !empty (self ::$ themeColors ) && empty (self ::$ themeColors ['light ' ]) && empty (self ::$ themeColors ['dark ' ])) {
271- if (is_string (self ::$ themeColors )) {
272- $ meta .= '<meta name="theme-color" content=" ' . htmlspecialchars (self ::$ themeColors ) . '" /> ' ;
255+ if (is_array (self ::$ themeColors )) {
256+ if (!empty (self ::$ themeColors ['light ' ])) {
257+ $ meta .= '<meta name="theme-color" media="(prefers-color-scheme: light)" content=" ' . htmlspecialchars (self ::$ themeColors ['light ' ]) . '" /> ' ;
273258 }
259+ if (!empty (self ::$ themeColors ['dark ' ])) {
260+ $ meta .= '<meta name="theme-color" media="(prefers-color-scheme: dark)" content=" ' . htmlspecialchars (self ::$ themeColors ['dark ' ]) . '" /> ' ;
261+ }
262+ if (!empty (self ::$ themeColors ['default ' ])) {
263+ $ meta .= '<meta name="theme-color" content=" ' . htmlspecialchars (self ::$ themeColors ['default ' ]) . '" /> ' ;
264+ }
265+ } elseif (is_string (self ::$ themeColors )) {
266+ $ meta .= '<meta name="theme-color" content=" ' . htmlspecialchars (self ::$ themeColors ) . '" /> ' ;
274267 }
275-
276268 return $ meta ;
277269 }
278270
@@ -281,7 +273,6 @@ public static function metaThemeColor(): string {
281273 */
282274 public static function headScript (): string {
283275 $ scripts = '' ;
284- /** @var array{'url':string,'id':string, 'defer':string, 'async':string} $script */
285276 foreach (self ::$ scripts as $ script ) {
286277 $ scripts .= '<script src=" ' . $ script ['url ' ] . '" ' ;
287278 if (!empty ($ script ['id ' ])) {
0 commit comments