@@ -45,20 +45,19 @@ public function __construct()
4545 {
4646 }
4747
48-
4948 /**
5049 * This will make shortcuts to container.
5150 * @param string $m [description]
5251 * @param string $a [description]
5352 * @return ContainerInterface
5453 */
55- public function __call ($ m , $ a )
54+ public function __call ($ method , $ args )
5655 {
5756 if (!is_null ($ this ->container )) {
58- if ($ this ->container ->has ($ m )) {
59- return $ this ->container ->get ($ m , $ a );
57+ if ($ this ->container ->has ($ method )) {
58+ return $ this ->container ->get ($ method , $ args );
6059 } else {
61- throw new BadMethodCallException ('The method " ' .$ m .'" does not exist in the Container ' .
60+ throw new BadMethodCallException ('The method " ' .$ method .'" does not exist in the Container ' .
6261 'or the Class " ' .static ::class.'"! ' , 1 );
6362 }
6463 }
@@ -212,24 +211,23 @@ public function withView(string $file, array $args = array()): self
212211
213212 /**
214213 * Create a partial view
215- * @param string $key Partal key, example: ("sidebar", "breadcrumb")
216- * @param string $file Filename
217- * @param array $args Pass on argummets to template
218- * @return self
214+ * @param string $keyA Filename/key
215+ * @param array $keyB Args/filename
216+ * @param array $keyC Args
219217 */
220- public function setPartial (string $ key , string |array $ a = array (), array $ b = array ()): self
218+ public function setPartial (string $ keyA , string |array $ keyB = array (), array $ keyC = array ()): self
221219 {
222- if (is_array ($ a )) {
223- $ b = $ a ;
224- $ partial = $ key ;
220+ if (is_array ($ keyB )) {
221+ $ keyC = $ keyB ;
222+ $ partial = $ keyA ;
225223 } else {
226- $ partial = $ a ;
224+ $ partial = $ keyB ;
227225 }
228226
229227 if (is_null ($ this ->file )) {
230- $ this ->setFile ($ key );
228+ $ this ->setFile ($ keyA );
231229 }
232- $ func = $ this ->build ($ this ->file , $ b );
230+ $ func = $ this ->build ($ this ->file , $ keyC );
233231 $ this ->partial [$ partial ][] = $ func ;
234232 return $ this ;
235233 }
@@ -338,17 +336,7 @@ public function partial(string $key): self
338336 */
339337 final public function get (?array $ args = null ): string
340338 {
341- if (!is_null ($ this ->bindView )) {
342- if (($ b = $ this ->existAtGet ("buffer " )) || ($ v = $ this ->existAtGet ("index " ))) {
343- if ($ b ) {
344- $ this ->buffer = $ this ->bindView ;
345- }
346- if ($ v ) {
347- $ this ->view = $ this ->bindView ;
348- }
349- }
350- }
351-
339+ $ this ->buildView ();
352340 $ output = $ this ->{$ this ->get };
353341
354342 // Will merge/replace arguments with current/deafult arguments
@@ -380,6 +368,20 @@ final public function get(?array $args = null): string
380368 return (string )$ output ;
381369 }
382370
371+ private function buildView (): void
372+ {
373+ if (!is_null ($ this ->bindView )) {
374+ if (($ hasBuffer = $ this ->existAtGet ("buffer " )) || ($ hasIndex = $ this ->existAtGet ("index " ))) {
375+ if ($ hasBuffer ) {
376+ $ this ->buffer = $ this ->bindView ;
377+ }
378+ if ($ hasIndex ) {
379+ $ this ->view = $ this ->bindView ;
380+ }
381+ }
382+ }
383+ }
384+
383385 /**
384386 * Build and Contain template and data until it's executed,
385387 * this means that code is prepared and will not take any extra memory if view would not be called.
@@ -390,8 +392,10 @@ final public function get(?array $args = null): string
390392 */
391393 private function build (string |callable $ file , array $ args = array ()): callable
392394 {
395+
393396 $ this ->arguments = $ args ;
394- $ func = function ($ a ) use ($ file , $ args ) {
397+ $ func = function ($ argsFromFile ) use ($ file , $ args ) {
398+
395399 if (($ dir = ($ this ->dir [$ this ->get ] ?? null )) || !is_null ($ dir )) {
396400 if (is_callable ($ file )) {
397401 $ out = $ file ($ this , $ args );
@@ -401,11 +405,12 @@ private function build(string|callable $file, array $args = array()): callable
401405 } else {
402406 $ filePath = "{$ dir }{$ file }. {$ this ->ending }" ;
403407 if (is_string ($ filePath ) && is_file ($ filePath )) {
404- if (is_array ($ a ) && count ($ a ) > 0 ) {
405- $ args = $ a ;
408+ if (is_array ($ argsFromFile ) && count ($ argsFromFile ) > 0 ) {
409+ $ args = $ argsFromFile ;
406410 }
407411 $ obj = Traverse::value ($ args );
408412 include ($ filePath );
413+
409414 } else {
410415 throw new Exception ("Could not require template file add {$ this ->get }: {$ dir }{$ file }. " , 1 );
411416 }
@@ -457,18 +462,18 @@ public function dom(string $key): Document
457462 public function createTag (string $ element , string $ value , ?array $ attr = null )
458463 {
459464 $ inst = new Document ();
460- $ el = $ inst ->create ($ element , $ value )->attrArr ($ attr );
461- return $ el ;
465+ $ elem = $ inst ->create ($ element , $ value )->attrArr ($ attr );
466+ return $ elem ;
462467 }
463468
464- public function isDoc ($ el ): bool
469+ public function isDoc ($ elem ): bool
465470 {
466- return (bool )($ el instanceof Document || $ el instanceof Element);
471+ return (bool )($ elem instanceof Document || $ elem instanceof Element);
467472 }
468473
469- public function isEl ($ el ): bool
474+ public function isEl ($ elem ): bool
470475 {
471- return (bool )($ el instanceof Element);
476+ return (bool )($ elem instanceof Element);
472477 }
473478
474479 /*
0 commit comments