Subversion Repositories php-qbpwcf

Rev

Rev 3 | Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 36
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 Min-Jhin,Chen
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
11
    it under the terms of the GNU General Public License as published by
Line 10751... Line 10751...
10751
	#$result["fileName"],暫存檔案的名稱.
10751
	#$result["fileName"],暫存檔案的名稱.
10752
	#$result["path"],暫存檔案的路徑.
10752
	#$result["path"],暫存檔案的路徑.
10753
	#必填參數:
10753
	#必填參數:
10754
	#無.
10754
	#無.
10755
	#可省略參數:
10755
	#可省略參數:
-
 
10756
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10756
	#無.
10757
	#$conf["contant"]=array();
10757
	#參考資料:
10758
	#參考資料:
10758
	#無.
10759
	#無.
10759
	#備註:
10760
	#備註:
10760
	#無.
10761
	#無.
10761
	*/
10762
	*/
10762
	public static function createTempFile(){
10763
	public static function createTempFile(&$conf){
10763
		
10764
		
10764
		#初始化要回傳的結果
10765
		#初始化要回傳的結果
10765
		$result=array();
10766
		$result=array();
10766
 
10767
 
10767
		#取得當前執行的函數名稱
10768
		#取得當前執行的函數名稱
10768
		$result["function"]=__FUNCTION__;
10769
		$result["function"]=__FUNCTION__;
-
 
10770
		
-
 
10771
		#取得參數
-
 
10772
		$result["argu"]=$conf;
-
 
10773
 
-
 
10774
		#如果 $conf 不為陣列
-
 
10775
		if(gettype($conf)!="array"){
-
 
10776
 
-
 
10777
			#設置執行失敗
-
 
10778
			$result["status"]="false";
-
 
10779
 
-
 
10780
			#設置執行錯誤訊息
-
 
10781
			$result["error"][]="\$conf變數須為陣列形態";
-
 
10782
 
-
 
10783
			#如果傳入的參數為 null
-
 
10784
			if(is_null($conf)){
-
 
10785
 
-
 
10786
				#設置執行錯誤訊息
-
 
10787
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
10788
 
-
 
10789
				}#if end
-
 
10790
 
-
 
10791
			#回傳結果
-
 
10792
			return $result;
-
 
10793
 
-
 
10794
			}#if end
-
 
10795
		
-
 
10796
		#檢查參數
-
 
10797
		#函式說明:
-
 
10798
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
-
 
10799
		#回傳結果:
-
 
10800
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
10801
		#$result["error"],執行不正常結束的錯訊息陣列.
-
 
10802
		#$result["simpleError"],簡單表示的錯誤訊息.
-
 
10803
		#$result["function"],當前執行的函式名稱.
-
 
10804
		#$result["argu"],設置給予的參數.
-
 
10805
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
10806
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
10807
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
10808
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
10809
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
10810
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
10811
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
10812
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
10813
		#必填參數:
-
 
10814
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
10815
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
10816
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
10817
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
10818
		#可省略參數:
-
 
10819
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
10820
		#$conf["mustBeFilledVariableName"]=array();
-
 
10821
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
-
 
10822
		#$conf["mustBeFilledVariableType"]=array();
-
 
10823
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
10824
		#$conf["canBeEmptyString"]="false";
-
 
10825
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
-
 
10826
		#$conf["canNotBeEmpty"]=array();
-
 
10827
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
-
 
10828
		#$conf["canBeEmpty"]=array();
-
 
10829
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
-
 
10830
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
10831
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
10832
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
-
 
10833
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
10834
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
-
 
10835
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
10836
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
-
 
10837
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
-
 
10838
		#$conf["disallowAllSkipableVarIsEmpty"]="";
-
 
10839
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
-
 
10840
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
-
 
10841
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
-
 
10842
		#$conf["disallowAllSkipableVarNotExist"]="";
-
 
10843
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
10844
		#$conf["arrayCountEqualCheck"][]=array();
-
 
10845
		#參考資料:
-
 
10846
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
10847
		#備註:
-
 
10848
		#無.
-
 
10849
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
10850
		unset($conf["variableCheck::checkArguments"]);
-
 
10851
		
-
 
10852
		#如果執行失敗
-
 
10853
		if($checkArguments["status"]==="false"){
-
 
10854
		
-
 
10855
			#設置執行異常
-
 
10856
			$result["status"]="false";
-
 
10857
			
-
 
10858
			#設置錯誤訊息
-
 
10859
			$result["error"]=$checkArguments;
-
 
10860
			
-
 
10861
			#回傳結果
-
 
10862
			return $result;
-
 
10863
		
-
 
10864
			}#if end
-
 
10865
			
-
 
10866
		#如果檢查不通過
-
 
10867
		if($checkArguments["passed"]==="false"){
-
 
10868
		
-
 
10869
			#設置執行異常
-
 
10870
			$result["status"]="false";
-
 
10871
			
-
 
10872
			#設置錯誤訊息
-
 
10873
			$result["error"]=$checkArguments;
10769
			
10874
			
-
 
10875
			#回傳結果
-
 
10876
			return $result;
-
 
10877
		
-
 
10878
			}#if end
-
 
10879
		
10770
		#取得相對於當前路徑的  tmp 目錄.
10880
		#取得相對於當前路徑的  tmp 目錄.
10771
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
10881
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
10772
		
10882
		
10773
		#如果執行失敗
10883
		#如果執行失敗
10774
		if($status!==0){
10884
		if($status!==0){
Line 10904... Line 11014...
10904
			}#if end
11014
			}#if end
10905
		
11015
		
10906
		#取得路徑
11016
		#取得路徑
10907
		$result["path"]=$delStrAfterKeyWord["content"];
11017
		$result["path"]=$delStrAfterKeyWord["content"];
10908
		
11018
		
-
 
11019
		#如果有內容要寫入
-
 
11020
		if(!empty($conf["content"])){
-
 
11021
		
-
 
11022
			#函式說明:
-
 
11023
			#將多行字串寫入到檔案
-
 
11024
			#回傳結果:
-
 
11025
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
-
 
11026
			#$result["error"],錯誤訊息陣列.
-
 
11027
			#$result["function"],當前執行函數的名稱.
-
 
11028
			#必填參數:
-
 
11029
			#$conf["fileName"],字串,爲要編輯的檔案名稱
-
 
11030
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
-
 
11031
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
-
 
11032
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
-
 
11033
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
11034
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
-
 
11035
			#可省略參數:
-
 
11036
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
-
 
11037
			#參考資料:
-
 
11038
			#無.
-
 
11039
			#備註:
-
 
11040
			#無.
-
 
11041
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
-
 
11042
			unset($conf["fileAccess::writeMultiLine"]);
-
 
11043
		
-
 
11044
			#如果執行失敗
-
 
11045
			if($writeMultiLine["status"]==="false"){
-
 
11046
			
-
 
11047
				#設置執行失敗
-
 
11048
				$result["status"]="false";
-
 
11049
 
-
 
11050
				#設置執行錯誤訊息
-
 
11051
				$result["error"]=$writeMultiLine;
-
 
11052
				
-
 
11053
				#回傳結果
-
 
11054
				return $result;
-
 
11055
			
-
 
11056
				}#if end
-
 
11057
		
-
 
11058
			}#if end
-
 
11059
		
10909
		#設置執行正常
11060
		#設置執行正常
10910
		$result["status"]="true";
11061
		$result["status"]="true";
10911
		
11062
		
10912
		#回傳結果
11063
		#回傳結果
10913
		return $result;
11064
		return $result;