How to automatically add configuration files?

There will be a lot of configuration files in the project.If the project is particularly large, then adding a configuration may change many files and many projects, which
is very labor and time consuming, and it is easy to make mistakes.We
need a dynamic configuration file template. Every time a new merchant waits for configuration, we only need to modify this file, then write a script, and then dynamically read the configuration, and then update these contents to other configuration files, simple and fast

[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

Example method of dynamic insertion:

/**
     * 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= "\n\n") {
        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) == "\n") {
                $front = substr($front, 0, -1);
            }
            $content = $front.$insert_str.$split_char.$behind;
            file_put_contents($file, $content);
        } else {
            file_put_contents($file, $insert_str."\n", FILE_APPEND);
        }

    }

Guess you like

Origin www.cnblogs.com/djwhome/p/12739930.html
Recommended