|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright (c) 2024 Jorge Patricio Castro Castillo MIT License. |
| 4 | + */ |
| 5 | +include "../lib/BladeOne.php"; |
| 6 | +use eftec\bladeone\BladeOne; |
| 7 | + |
| 8 | +$views = __DIR__ . '/views'; |
| 9 | +$compiledFolder = __DIR__ . '/compiled'; |
| 10 | +$blade=new BladeOne($views, $compiledFolder, BladeOne::MODE_DEBUG); |
| 11 | +$blade->pipeEnable=true; |
| 12 | + |
| 13 | + |
| 14 | +$blade->clearMethods(); |
| 15 | + |
| 16 | +$blade->addMethod('runtime','table',static function($args) { |
| 17 | + // in this context, $this means the autoTest class and not the blade class. |
| 18 | + $args=array_merge(['alias'=>'alias'],$args); // you could use array merge to set a default value. |
| 19 | + BladeOne::$instance->addControlStackChild('runtimeTable',$args); // we store the current control in the stack. |
| 20 | + return '<ul>'; |
| 21 | +}); |
| 22 | +$blade->addMethod('runtime','endtable',static function($args) { |
| 23 | + BladeOne::$instance->closeControlStack(); |
| 24 | + return '</ul>'; |
| 25 | +}); |
| 26 | +$blade->addMethod('runtime','row',static function() { |
| 27 | + $parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack |
| 28 | + $result=''; |
| 29 | + foreach($parent['values'] as $v) { |
| 30 | + $result.=BladeOne::$instance->runChild('auto.test2_control',[$parent['alias']=>$v]); |
| 31 | + } |
| 32 | + return $result; |
| 33 | +}); |
| 34 | +$blade->addMethod('runtime','row2',function() { |
| 35 | + $parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack |
| 36 | + $result=''; |
| 37 | + foreach($parent['values'] as $v) { |
| 38 | + $result.="<li>$v</li>\n"; |
| 39 | + } |
| 40 | + return $result; |
| 41 | +}); |
| 42 | + |
| 43 | + |
| 44 | +try { |
| 45 | + echo $blade->run("auto.test2",['countries' => ["chile","argentina","peru"]]); |
| 46 | +} catch (Exception $e) { |
| 47 | + echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString(); |
| 48 | +} |
0 commit comments