@@ -43,36 +43,43 @@ public function __invoke(ServerRequestInterface $request, callable $next)
43
43
$ result = $ next ($ request );
44
44
$ context = $ this ->getContext ($ request );
45
45
$ renderer = $ context ->getRenderer ();
46
- if ($ renderer instanceof Phtml && is_object ($ context ->route ->handler )) {
47
- $ rc = new \ReflectionClass (get_class ($ context ->route ->handler ));
48
- $ controllerFilePath = $ rc ->getFileName ();
49
- $ controllerFilePathinfo = pathinfo ($ controllerFilePath );
46
+ if (! isset ($ renderer )) {
47
+ return $ result ;
48
+ }
49
+ if (! $ renderer instanceof Phtml) {
50
+ return $ result ;
51
+ }
52
+ if (! is_object ($ context ->route ->handler )) {
53
+ return $ result ;
54
+ }
55
+ $ rc = new \ReflectionClass (get_class ($ context ->route ->handler ));
56
+ $ controllerFilePath = $ rc ->getFileName ();
57
+ $ controllerFilePathinfo = pathinfo ($ controllerFilePath );
50
58
51
- // PHTML view file
52
- $ phtmlFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.phtml " ;
53
- if (!array_key_exists ('viewFilePath ' , $ context ->renderOptions )) {
54
- $ context ->renderOptions ['viewFilePath ' ] = $ phtmlFile ;
55
- }
59
+ // PHTML view file
60
+ $ phtmlFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.phtml " ;
61
+ if (!array_key_exists ('viewFilePath ' , $ context ->renderOptions )) {
62
+ $ context ->renderOptions ['viewFilePath ' ] = $ phtmlFile ;
63
+ }
56
64
57
- // JS file
58
- $ jsFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.js " ;
59
- if (!isset ($ context ->renderOptions ['inlineScripts ' ])) {
60
- $ context ->renderOptions ['inlineScripts ' ] = [];
61
- }
62
- if (is_file ($ jsFile )) {
63
- //TODO async file get contents?
64
- $ context ->renderOptions ['inlineScripts ' ][] = file_get_contents ($ jsFile );
65
- }
65
+ // JS file
66
+ $ jsFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.js " ;
67
+ if (!isset ($ context ->renderOptions ['inlineScripts ' ])) {
68
+ $ context ->renderOptions ['inlineScripts ' ] = [];
69
+ }
70
+ if (is_file ($ jsFile )) {
71
+ //TODO async file get contents?
72
+ $ context ->renderOptions ['inlineScripts ' ][] = file_get_contents ($ jsFile );
73
+ }
66
74
67
- // CSS file
68
- $ cssFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.css " ;
69
- if (!isset ($ context ->renderOptions ['inlineCss ' ])) {
70
- $ context ->renderOptions ['inlineCss ' ] = [];
71
- }
72
- if (is_file ($ cssFile )) {
73
- //TODO async file get contents?
74
- $ context ->renderOptions ['inlineCss ' ][] = file_get_contents ($ cssFile );
75
- }
75
+ // CSS file
76
+ $ cssFile = "{$ controllerFilePathinfo ['dirname ' ]}/ {$ controllerFilePathinfo ['filename ' ]}.css " ;
77
+ if (!isset ($ context ->renderOptions ['inlineCss ' ])) {
78
+ $ context ->renderOptions ['inlineCss ' ] = [];
79
+ }
80
+ if (is_file ($ cssFile )) {
81
+ //TODO async file get contents?
82
+ $ context ->renderOptions ['inlineCss ' ][] = file_get_contents ($ cssFile );
76
83
}
77
84
78
85
return $ result ;
0 commit comments