生成ini文件

class create
{
    private $file_type;
    private $file_name;
    private $file_handle;
    private  $file_path;
    function create($param){
        $this->file_name= $param['file_name'];
        $this->file_type= $param['file_type'];
        $this->file_path = $param['file_path'];
    }
    
    private function get_data($class,$method,$id) {
        $model = new $class();
        $data = $model->$method($id);
        $data['company'] = Basesetting::get_company();
        return $data;
    }
    
    public function create_file($class,$method,$id,$note) {
        $data = $this->get_data($class,$method,$id);
        $this->open_file();
        $this->create_note($note);
        $this->write_file('[template]');
        $this->write_file(' ');
        $this->create_data($data['company'], '## this is the template company info', 'company');
        $this->write_file(' ');
        $this->create_data($data['master'], '## this is the template master ', 'master');
        $this->write_file(' ');
        $this->create_data($data['slave'][0], '## this is the template slave ', 'slave.0');
        $this->close_file();

    }

    private function  create_note($bill_name){
        $note  = "#################################################";
        $this->write_file($note);
        $note = "### 本配置文件是 $bill_name 单据打印 配置模板";
        $this->write_file($note);
        $note = "### 如需要添加字段请在配置文件中添加相应的字段项";
        $this->write_file($note);
        $note = "### “
        $this->write_file($note);
        $note = "#################################################";
        $this->write_file($note);
    }
    private function create_data($data,$note,$title){
        $this->write_file($note);
        foreach ($data as $key => $value) {
            $this->create_row($title.'.'.$key,$value);
        }

    }
    private function create_row($key , $val){
        $str = str_pad($key,35);
        $str .=' = '.$val;
        $this->write_file($str);
    }
    private function open_file(){
        $this->file_handle = fopen($this->file_path.'/'.$this->file_name.'.'.$this->file_type, 'wb');
    }
    private function close_file(){
        fclose($this->file_handle);
    }
    private function write_file($str){
        fwrite($this->file_handle,$str."\r\n");
    }
    
    public function create_files($arr) {
        foreach ($arr as  $value) {
            $this->file_name = $value['file_name'];
            $this->create_file($value['class'], $value['method'], $value['id'],$value['note']);
        }
    }
}


你可能感兴趣的:(技術,ini,file,function,class,path)