zoukankan      html  css  js  c++  java
  • 生成config文件到内存中

    <?php
    
    $site_code='property';
            $common = [ 'API_HOST_V3'=>'http://10.1.118.12:83/apiv3.json' ,'SITE_CODE'=>'CP'];
            $api_v3 = 'http://10.1.118.12:83/apiv3.json';
            $data = [['api'=>"config/lists", 'data'=>['site_code'=>' '.$site_code.' ']]];
            //$data = [['api'=>"appMemberAuth/lists", 'data'=>['SITE_CODE'=>'CP']]];
            $data_string = json_encode($data);
            $header = [
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string)
            ];
            $ch = curl_init($api_v3);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT,5);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $result = curl_exec($ch);
            $result = json_decode($result,true);
            $result_data = $result['data'][0]['data'];
            $result_lists = json_decode($result_data);
            $cfg_file_path = RUNTIME_PATH.'/config.php';
            if(!file_exists($cfg_file_path))
            {
                            
                file_put_contents($cfg_file_path, "<?php".PHP_EOL, FILE_APPEND);
                file_put_contents($cfg_file_path, "    return array(".PHP_EOL, FILE_APPEND);
                
                foreach ($result_lists->data->lists as $key=>$item)
                {
                    $config_str = "";
                    if($item->value==='true')
                    {
                        $config_str = $config_str . "'". $item->key ."'";
                        $config_str = $config_str . "=>  true ,".PHP_EOL;
                    }else if($item->value==='false')
                    {
                        $config_str = $config_str . "'". $item->key ."'";
                        $config_str = $config_str . "=>  false ,".PHP_EOL;
                    }else if($item->data_type==='array')
                    {
                        if(is_array(json_decode($item->value,true)))
                        {    
                            $config_str = $config_str . "'". $item->key ."'";
                            $config_str = $config_str . "=> [".PHP_EOL;
                           foreach(json_decode($item->value,true) as $k=>$v)
                           { 
                                    $config_str = $config_str . "'". $k ."'";
                                     if(is_array($v))
                                    {
                                        $config_str = $config_str . "=>[".PHP_EOL;
                                        foreach($v as $kk=>$vv)
                                        {
                                            $config_str = $config_str . "'". $kk ."'";
                                                
                                            $config_str = $config_str . "=>'" .$vv ."',".PHP_EOL;
                                        }
                                        $config_str = $config_str . "],".PHP_EOL;
                                    }else{
                                        $config_str = $config_str . "=>'" .$v ." ',".PHP_EOL;
                                    }    
                           }
                           $config_str = $config_str . "],".PHP_EOL;
                        }
                        $data_arr[]=$item->value;
    
                    }else if(is_numeric($item->value))
                    {
                        $config_str = $config_str . "'". $item->key ."'";
                        $config_str = $config_str . "=>  " .$item->value .",".PHP_EOL;
                    }else{
                        $config_str = $config_str . "'". $item->key ."'";
                        $config_str = $config_str . "=>  '" .$item->value ."',".PHP_EOL;
                    }
                    
                    file_put_contents($cfg_file_path, $config_str, FILE_APPEND);
                }
                
                file_put_contents($cfg_file_path, ");", FILE_APPEND);
            }
             return  array_merge(file_exists($cfg_file_path) ? require_once $cfg_file_path : [], $common);
  • 相关阅读:
    public,protected,private辨析
    转载---Java集合对象的深度复制与普通复制
    SSM框架学习之高并发秒杀业务--笔记4-- web层
    PCB布线总的原则
    模拟电子技术目录
    放大器(PA+LAN)在射频上的应用
    AD软件Bug和自我失误的对战
    二、cadence焊盘与封装制作操作步骤详细说明
    图腾柱电路工作原理
    转载:介绍AD另外一种奇葩的多通道复用的方法
  • 原文地址:https://www.cnblogs.com/stj123/p/12354275.html
Copyright © 2011-2022 走看看