'; $stream .= self::recursive_sample($dataset, $level,$parent); $stream .= ''; return $stream; } public function recursive_sample($dataset,$level = 0,$parent=''){ $stream = ''; $parent = ($parent!=''?$parent.'.':''); $indentation = str_repeat("
", $level); foreach($dataset as $macro => $infos){ $infos['type'] = isset($infos['type']) ? $infos['type'] : ''; switch($infos['type']){ case 'list': $stream .= $indentation.'

-'.$parent.$macro.' '.(isset($infos['label'])?': '.$infos['label']:'').' (liste)'.'

'.PHP_EOL; $stream .= $indentation.'{{#'.$parent.$macro.'}}'.'
'.PHP_EOL;; if(is_array($infos['value']) && isset($infos['value'][0])) $stream .= self::sample($infos['value'][0],$level+1); $stream .=$indentation.'
{{/'.$parent.$macro.'}}'; break; case 'image': $stream .= $indentation.''.$infos['label']; break; case 'object': $stream .= '

'.$indentation.'-'.$parent.$macro.' '.(isset($infos['label'])?': '.$infos['label']:'').'

'.PHP_EOL;; $stream .= self::sample($infos['value'],$level+1,$parent.$macro); break; default : $stream .= $indentation.'{{'.$parent.$macro.'}} : '.( !isset($infos['label']) ? '': $infos['label']).'
'.PHP_EOL; break; } } return $stream; } public function formatValue($type,$value){ if($type == 'image') return 'data:image/png;base64,'.base64_encode($value); return $value; } } ?>