@@ -171,8 +171,13 @@ function setView(string|callable $file, array $args = array()): self
171171 $ this ->view = $ func ;
172172 return $ this ;
173173 }
174-
175-
174+
175+ /**
176+ * Keep prev view immutable and create a new one.
177+ * @param string $file [description]
178+ * @param array $args [description]
179+ * @return static
180+ */
176181 function withView (string $ file , array $ args = array ()): self
177182 {
178183 $ inst = clone $ this ;
@@ -187,13 +192,30 @@ function withView(string $file, array $args = array()): self
187192 * @param array $args Pass on argummets to template
188193 * @return self
189194 */
190- function setPartial (string $ key , array $ args = array ()): self
195+ function setPartial (string $ key , string | array $ a = array (), array $ b = array ()): self
191196 {
197+ if (is_array ($ a )) {
198+ $ b = $ a ;
199+ $ partial = $ key ;
200+ } else {
201+ $ partial = $ a ;
202+ }
203+
192204 if (is_null ($ this ->file )) $ this ->setFile ($ key );
193- $ func = $ this ->build ($ this ->file , $ args );
194- $ this ->partial [$ key ] = $ func ;
205+ $ func = $ this ->build ($ this ->file , $ b );
206+ $ this ->partial [$ partial ][ ] = $ func ;
195207 return $ this ;
196208 }
209+
210+ /**
211+ * Unset a setted partial
212+ * @param string $key Partal key, example: ("sidebar", "breadcrumb")
213+ * @return void
214+ */
215+ function unsetPartial ($ key ): void
216+ {
217+ if (isset ($ this ->partial [$ key ])) unset($ this ->partial [$ key ]);
218+ }
197219
198220 /**
199221 * Bind a View to a HTTP status reponse code
@@ -262,9 +284,6 @@ function view(?array $args = NULL): self
262284 return $ this ;
263285 }
264286
265-
266-
267-
268287 /**
269288 * Prepare partial for return
270289 * @param string $key select partial to read
@@ -298,8 +317,9 @@ final function get(?array $args = NULL): string
298317
299318 ob_start ();
300319 if (!is_null ($ this ->arg )){
301- if (is_array ($ output )) {
302- if (isset ($ output [$ this ->arg ])) $ output [$ this ->arg ]($ args );
320+ if (is_array ($ output )) {
321+ //if(isset($output[$this->arg])) $output[$this->arg]($args);
322+ if (isset ($ output [$ this ->arg ])) foreach ($ output [$ this ->arg ] as $ part ) $ part ($ args );
303323 }
304324 } else {
305325 if (is_null ($ output )) {
@@ -375,11 +395,21 @@ function exists(string $key): bool
375395 return (bool )(in_array ($ key , $ this ::VIEWS ) && isset ($ this ->{$ key }));
376396 }
377397
398+ /**
399+ * Check if view exists at row
400+ * @param string $key
401+ * @return bool
402+ */
403+ private function existAtGet (string $ key ): bool
404+ {
405+ return (bool )(isset ($ this ->{$ key }) && $ this ->get === $ key );
406+ }
407+
408+ /*
378409 function dom(string $key): Document
379410 {
380411 return Document::dom($key);
381412 }
382-
383413 function createTag(string $element, string $value, ?array $attr = NULL) {
384414 $inst = new Document();
385415 $el = $inst->create($element, $value)->attrArr($attr);
@@ -395,17 +425,7 @@ function isEl($el): bool
395425 {
396426 return (bool)($el instanceof Element);
397427 }
398-
399-
400- /**
401- * Check if view exists at row
402- * @param string $key
403- * @return bool
404- */
405- private function existAtGet (string $ key ): bool
406- {
407- return (bool )(isset ($ this ->{$ key }) && $ this ->get === $ key );
408- }
428+ */
409429
410430
411431}
0 commit comments