@@ -71,7 +71,7 @@ public function process($html, $options = [])
7171 if ($ scheme === 'data ' ) {
7272 $ componentHTML = $ this ->processData ($ sourceParts [1 ], isset ($ componentOptions ) ? $ componentOptions : $ options );
7373 } 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 );
7575 } else {
7676 throw new \Exception ('URI scheme not valid! ' . $ domDocument ->saveHTML ($ component ));
7777 }
@@ -126,13 +126,14 @@ public function processData($data, $options = [])
126126 * @param string $file
127127 * @param array $attributes
128128 * @param string $innerHTML
129+ * @param array $variables
129130 * @param array $options
130131 * @return string
131132 */
132- public function processFile ($ file , $ attributes = [], $ innerHTML = '' , $ options = [])
133+ public function processFile ($ file , $ attributes = [], $ innerHTML = '' , $ variables = [], $ options = [])
133134 {
134135 $ 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 );
136137 }
137138
138139 /**
@@ -152,19 +153,24 @@ protected function constructComponent($attributes = [], $innerHTML = '')
152153 /**
153154 *
154155 * @param string $file
155- * @param \IvoPetkov\HTMLServerComponent $component
156+ * @param array $variables
156157 * @throws \Exception
157158 * @return string
158159 */
159- protected function getComponentFileContent ($ file , $ component )
160+ protected function getComponentFileContent ($ file , $ variables )
160161 {
161162 if (is_file ($ file )) {
163+ $ __componentFile = $ file ;
164+ unset($ file );
165+ if (!empty ($ variables )) {
166+ extract ($ variables , EXTR_SKIP );
167+ }
162168 ob_start ();
163- include $ file ;
169+ include $ __componentFile ;
164170 $ content = ob_get_clean ();
165171 return $ content ;
166172 } else {
167- throw new \Exception ('Component file cannot be found ' );
173+ throw new \Exception ('Component file cannot be found ( ' . $ file . ' ) ' );
168174 }
169175 }
170176
0 commit comments