@@ -25,10 +25,10 @@ class ViewRenderer
25
25
private $ currentDir = '' ;
26
26
27
27
/** @var string Views file path. */
28
- protected $ viewsPath = '' ;
28
+ protected $ viewsPath ;
29
29
30
- /** @var null| string Default layout file. */
31
- protected $ layout = '' ;
30
+ /** @var string Default layout file. */
31
+ protected $ layout ;
32
32
33
33
/** @var array Attributes for the view */
34
34
protected $ attributes = [];
@@ -54,12 +54,12 @@ class ViewRenderer
54
54
* @param string $layout
55
55
* @param array $attributes
56
56
*/
57
- public function __construct (string $ viewsPath = null , string $ layout = null , array $ attributes = [])
57
+ public function __construct (string $ viewsPath = '' , string $ layout = '' , array $ attributes = [])
58
58
{
59
59
$ this ->layout = $ layout ;
60
60
$ this ->attributes = $ attributes ;
61
61
62
- $ this ->setViewsPath ($ this -> viewsPath );
62
+ $ this ->setViewsPath ($ viewsPath );
63
63
}
64
64
65
65
/********************************************************************************
@@ -71,12 +71,12 @@ public function __construct(string $viewsPath = null, string $layout = null, arr
71
71
* throws RuntimeException if view file does not exist
72
72
* @param string $view
73
73
* @param array $data extract data to view, cannot contain view as a key
74
- * @param string|null| false $layout Override default layout file.
74
+ * @param string|false $layout Override default layout file.
75
75
* False - will disable use layout file
76
76
* @return string
77
77
* @throws \RuntimeException
78
78
*/
79
- public function render (string $ view , array $ data = [], $ layout = null ): string
79
+ public function render (string $ view , array $ data = [], $ layout = '' ): string
80
80
{
81
81
$ output = $ this ->fetch ($ view , $ data );
82
82
@@ -120,11 +120,12 @@ public function renderBody(string $content, array $data = [], string $layout = '
120
120
*/
121
121
public function renderContent (string $ content , array $ data = [], string $ layout = '' ): string
122
122
{
123
+ $ layout = $ layout ?: $ this ->layout ;
124
+
123
125
// render layout
124
- if ($ layout = $ layout ?: $ this ->layout ) {
125
- $ mark = $ this ->placeholder ;
126
+ if ($ layout && $ this ->placeholder ) {
126
127
$ main = $ this ->fetch ($ layout , $ data );
127
- $ content = (string )\str_replace ($ mark , $ content , $ main );
128
+ $ content = (string )\str_replace ($ this -> placeholder , $ content , $ main );
128
129
}
129
130
130
131
if ($ this ->minify ) {
0 commit comments