@@ -71,7 +71,7 @@ public function process($html, $options = [])
71
71
if ($ scheme === 'data ' ) {
72
72
$ componentHTML = $ this ->processData ($ sourceParts [1 ], isset ($ componentOptions ) ? $ componentOptions : $ options );
73
73
} elseif ($ scheme === 'file ' ) {
74
- $ componentHTML = $ this ->processFile (urldecode ($ sourceParts [1 ]), $ attributes , $ component ->innerHTML , isset ($ componentOptions ) ? $ componentOptions : $ options );
74
+ $ componentHTML = $ this ->processFile (urldecode ($ sourceParts [1 ]), $ attributes , $ component ->innerHTML , [], isset ($ componentOptions ) ? $ componentOptions : $ options );
75
75
} else {
76
76
throw new \Exception ('URI scheme not valid! ' . $ domDocument ->saveHTML ($ component ));
77
77
}
@@ -126,13 +126,14 @@ public function processData($data, $options = [])
126
126
* @param string $file
127
127
* @param array $attributes
128
128
* @param string $innerHTML
129
+ * @param array $variables
129
130
* @param array $options
130
131
* @return string
131
132
*/
132
- public function processFile ($ file , $ attributes = [], $ innerHTML = '' , $ options = [])
133
+ public function processFile ($ file , $ attributes = [], $ innerHTML = '' , $ variables = [], $ options = [])
133
134
{
134
135
$ component = $ this ->constructComponent ($ attributes , $ innerHTML );
135
- return $ this ->process ($ this ->getComponentFileContent ($ file , $ component ), $ options );
136
+ return $ this ->process ($ this ->getComponentFileContent ($ file , array_merge ( $ variables , [ ' component ' => $ component ]) ), $ options );
136
137
}
137
138
138
139
/**
@@ -152,19 +153,24 @@ protected function constructComponent($attributes = [], $innerHTML = '')
152
153
/**
153
154
*
154
155
* @param string $file
155
- * @param \IvoPetkov\HTMLServerComponent $component
156
+ * @param array $variables
156
157
* @throws \Exception
157
158
* @return string
158
159
*/
159
- protected function getComponentFileContent ($ file , $ component )
160
+ protected function getComponentFileContent ($ file , $ variables )
160
161
{
161
162
if (is_file ($ file )) {
163
+ $ __componentFile = $ file ;
164
+ unset($ file );
165
+ if (!empty ($ variables )) {
166
+ extract ($ variables , EXTR_SKIP );
167
+ }
162
168
ob_start ();
163
- include $ file ;
169
+ include $ __componentFile ;
164
170
$ content = ob_get_clean ();
165
171
return $ content ;
166
172
} else {
167
- throw new \Exception ('Component file cannot be found ' );
173
+ throw new \Exception ('Component file cannot be found ( ' . $ file . ' ) ' );
168
174
}
169
175
}
170
176
0 commit comments