| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- function getFilesTxt($files){
- $str = '';
- foreach($files as $file){
- if(!$file){
- continue;
- }
- $str.=<<<EOF
- "{$file}",
- EOF;
- }
- return $str;
- }
- function getUnpackTxt($unpack)
- {
- $str = '';
- foreach($unpack as $file){
- if(!$file){
- continue;
- }
- $str.=<<<EOF
- "{$file}",
- EOF;
- }
- return $str;
- }
- function getRequireTxt($require)
- {
- $str = '';
- foreach($require as $re){
- if(!$re){
- continue;
- }
- if(!class_exists($re)){
- throw new \Exception("{$re}类不存在");
- }
- $str.=<<<EOF
- {$re}::class,
- EOF;
- }
- return $str;
- }
- function getAddonsTxt($addons)
- {
- $str = '';
- foreach($addons as $re){
- if(!$re){
- continue;
- }
- if(!addons_installed($re)){
- $ad=get_addons($re);
- throw new \Exception("扩展{$ad->name}不存在");
- }
- $ad=get_addons($re);
- $str.=<<<EOF
- "{$re}"=>"{$ad->name}",
- EOF;
- }
- return $str;
- }
- function getMenuTxt($menulist)
- {
- if(count($menulist)==0){
- return '';
- }
- $str='';
- foreach ($menulist as $menu){
- $arr=parseMenu($menu);
- $txt=getArrayTxt($arr);
- $str.=<<<EOF
- {$txt}
- EOF;
- }
- return $str;
- }
- function getTableTxt($table)
- {
- if(empty($table)){
- return '';
- }
- $str='';
- foreach ($table as $te){
- $str.=<<<EOF
- "{$te}",
- EOF;
- }
- return $str;
- }
- function parseMenu($menu){
- $arr=[
- 'id'=>$menu['id'],
- 'controller'=>$menu['controller'],
- 'action'=>$menu['action'],
- 'title'=>$menu['title'],
- 'icon'=>$menu['icon'],
- 'ismenu'=>$menu['ismenu'],
- 'menutype'=>$menu['menutype'],
- 'extend'=>$menu['extend'],
- 'weigh'=>$menu['weigh'],
- ];
- if(count($menu['childlist'])>0){
- foreach ($menu['childlist'] as $key=>$value){
- $menu['childlist'][$key]=parseMenu($value);
- }
- $arr['childlist']=$menu['childlist'];
- }
- return $arr;
- }
- function getConfigTxt($config)
- {
- $str = '';
- foreach($config as $fig){
- $arr=[
- 'id'=>$fig['id'],
- 'name'=>$fig['name'],
- 'title'=>$fig['title'],
- 'type'=>$fig['type'],
- 'tip'=>$fig['tip'],
- 'rules'=>$fig['rules'],
- 'extend'=>$fig['extend']
- ];
- $txt=getArrayTxt($arr);
- //去掉末尾的逗号
- $str.=<<<EOF
- {$txt}
- EOF;
- }
- return $str;
- }
- function getArrayTxt($arr)
- {
- $str = '[';
- foreach($arr as $key=>$value){
- if(is_array($value)){
- if(is_numeric($key)){
- $str.=getArrayTxt($value);
- }else{
- $str.='\''.$key.'\'=>'.getArrayTxt($value);
- }
- }else{
- if(is_numeric($value)){
- $str.=<<<EOF
- '{$key}'=>{$value},
- EOF;
- }else{
- $str.=<<<EOF
- '{$key}'=>'{$value}',
- EOF;
- }
- }
- }
- $str=substr($str,0,strlen($str)-1);
- return $str.'],';
- }
|