zoukankan      html  css  js  c++  java
  • 如何自动化新增配置文件呢?

    在项目中会有很多的配置文件,如果项目特别庞大,那么新增一个配置,可能要改很多个文件和很多项目,
    很费人力和时间,而且容易改错
    我们需要一个动态的配置文件模板,每次新上商家等配置时候,我们只需要修改这个文件,然后写一个脚本,然后动态读取配置,再把这些内容,更新到其他配置文件中,简单快捷

    [im_info]
    odp_code_conf_path: /home/work/odp/app/bcp/conf/bcp/
    third_name:mb 
    #api_secret采用md5(third_name)
    im_type: 17
    open_url: http://test.zchat.net.cn/bcp_start
    push_url: http://test.zchat.net.cn/bcp_message
    close_url: http://test.zchat.net.cn/bcp_end
    system_url: http://test.zchat.net.cn/bcp_system
    sitein_url: http://test.zchat.net.cn/bcp_insite
    siteout_url: http://test.zchat.net.cn/bcp_outsite
    

    动态插入示例方法:

    /**
         * insertData 插入配置文件字符
         *
         * @param string $file 插入文件
         * @param string $insert_str 插入字符串
         * @param string $insert_pos_str 插入位置的字符串
         * @param string $split_char 插入后面分割字符串
         * @access private
         * @return void
         */
        private function insertData ($file, $insert_str, $insert_pos_str, $split_char= "
    
    ") {
            if($insert_pos_str != '') {
                $content = file_get_contents($file);
                $pos = strpos($content, $insert_pos_str);
                $front = substr($content, 0, $pos);
                $behind = substr($content, $pos);
    
                if (substr($front, -1) == "
    ") {
                    $front = substr($front, 0, -1);
                }
                $content = $front.$insert_str.$split_char.$behind;
                file_put_contents($file, $content);
            } else {
                file_put_contents($file, $insert_str."
    ", FILE_APPEND);
            }
    
        }
    
  • 相关阅读:
    第009讲:了不起的分支和循环3
    Term_Application
    十大编程算法助程序员走上高手之路
    每天工作4小时的程序员
    编程真相_节选
    Sublime_Snippet
    VIM资源管理
    微信企业号开发资源整理
    vitruviano
    VIM_git
  • 原文地址:https://www.cnblogs.com/djwhome/p/12739930.html
Copyright © 2011-2022 走看看