Subversion Repositories php-qbpwcf

Rev

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

Rev 3 Rev 226
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 ZHI, 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 28... Line 28...
28
跟程式中止有關的類別.
28
跟程式中止有關的類別.
29
備註:
29
備註:
30
無.
30
無.
31
*/
31
*/
32
class stop{
32
class stop{
33
	
33
 
34
	/*
34
	/*
35
	#函式說明:
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 43... Line 43...
43
	#$arguments,陣列,為呼叫方法時所用的參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
46
	*/
47
	public function __call($method,$arguments){
47
	public function __call($method,$arguments){
48
		
48
 
49
		#取得當前執行的函式
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
50
		$result["function"]=__FUNCTION__;
51
		
51
 
52
		#設置執行不正常
52
		#設置執行不正常
53
		$result["status"]="false";
53
		$result["status"]="false";
54
		
54
 
55
		#設置執行錯誤
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
		
57
 
58
		#設置所丟入的參數
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
59
		$result["error"][]=$arguments;
60
		
60
 
61
		#回傳結果
61
		#回傳結果
62
		return $result;
62
		return $result;
63
		
63
 
64
		}#function __call end
64
		}#function __call end
65
		
65
 
66
	/*
66
	/*
67
	#函式說明:
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 75... Line 75...
75
	#$arguments,陣列,為呼叫方法時所用的參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
78
	*/
79
	public static function __callStatic($method,$arguments){
79
	public static function __callStatic($method,$arguments){
80
		
80
 
81
		#取得當前執行的函式
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
82
		$result["function"]=__FUNCTION__;
83
		
83
 
84
		#設置執行不正常
84
		#設置執行不正常
85
		$result["status"]="false";
85
		$result["status"]="false";
86
		
86
 
87
		#設置執行錯誤
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
		
89
 
90
		#設置所丟入的參數
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
91
		$result["error"][]=$arguments;
92
		
92
 
93
		#回傳結果
93
		#回傳結果
94
		return $result;
94
		return $result;
95
		
95
 
96
		}#function __callStatic end
96
		}#function __callStatic end
97
	
97
 
98
	/*
98
	/*
99
	#函式說明:
99
	#函式說明:
100
	#停止執行程式,中止前一刻會印出一段內容
100
	#停止執行程式,中止前一刻會印出一段內容
101
	#回傳結果:
101
	#回傳結果:
102
	#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
102
	#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
Line 109... Line 109...
109
	#exit=>http://php.net/manual/en/function.exit.php
109
	#exit=>http://php.net/manual/en/function.exit.php
110
	#備註:
110
	#備註:
111
	#正常來說不會得到回傳的$result,若有則代表異常.
111
	#正常來說不會得到回傳的$result,若有則代表異常.
112
	*/
112
	*/
113
	function exitWithComment(&$conf){
113
	function exitWithComment(&$conf){
114
		
114
 
115
		#初始化要回傳的變數
115
		#初始化要回傳的變數
116
		$result=array();
116
		$result=array();
117
 
117
 
118
		#取得當前執行的函數名稱
118
		#取得當前執行的函數名稱
119
		$result["function"]=__FUNCTION__;
119
		$result["function"]=__FUNCTION__;
120
 
120
 
121
		#如果 $conf 不為陣列
121
		#如果 $conf 不為陣列
122
		if(gettype($conf)!="array"){
122
		if(gettype($conf)!="array"){
123
			
123
 
124
			#設置執行失敗
124
			#設置執行失敗
125
			$result["status"]="false";
125
			$result["status"]="false";
126
			
126
 
127
			#設置執行錯誤訊息
127
			#設置執行錯誤訊息
128
			$result["error"][]="\$conf變數須為陣列形態";
128
			$result["error"][]="\$conf變數須為陣列形態";
129
 
129
 
130
			#如果傳入的參數為 null
130
			#如果傳入的參數為 null
131
			if($conf==null){
131
			if($conf==null){
132
				
132
 
133
				#設置執行錯誤訊息
133
				#設置執行錯誤訊息
134
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
134
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
135
				
135
 
136
				}#if end
136
				}#if end
137
 
137
 
138
			#回傳結果
138
			#回傳結果
139
			return $result;
139
			return $result;
140
			
140
 
141
			}#if end
141
			}#if end
142
			
142
 
143
		#函式說明:
143
		#函式說明:
144
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
144
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
145
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
145
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
146
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
146
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
147
		#$result["function"],當前執行的函式名稱.
147
		#$result["function"],當前執行的函式名稱.
Line 167... Line 167...
167
		#$conf["canBeEmptyString"]="false";
167
		#$conf["canBeEmptyString"]="false";
168
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
168
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
169
		#$conf["skipableVariableCanNotBeEmpty"]=array();
169
		#$conf["skipableVariableCanNotBeEmpty"]=array();
170
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
170
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
171
		#$conf["skipableVariableName"]=array();
171
		#$conf["skipableVariableName"]=array();
172
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
172
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
173
		#$conf["skipableVariableType"]=array();
173
		#$conf["skipableVariableType"]=array();
174
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
174
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
175
		#$conf["skipableVarDefaultValue"]=array("");
175
		#$conf["skipableVarDefaultValue"]=array("");
176
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
176
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
177
		#$conf["arrayCountEqualCheck"][]=array();
177
		#$conf["arrayCountEqualCheck"][]=array();
178
		#參考資料來源:
178
		#參考資料來源:
179
		#array_keys=>http://php.net/manual/en/function.array-keys.php
179
		#array_keys=>http://php.net/manual/en/function.array-keys.php
180
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
180
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
181
		unset($conf["variableCheck::checkArguments"]);
181
		unset($conf["variableCheck::checkArguments"]);
182
		
182
 
183
		#如果檢查失敗
183
		#如果檢查失敗
184
		if($checkArguments["status"]=="false"){
184
		if($checkArguments["status"]=="false"){
185
			
185
 
186
			#設置錯誤識別
186
			#設置錯誤識別
187
			$result["status"]="false";
187
			$result["status"]="false";
188
			
188
 
189
			#設置錯誤訊息
189
			#設置錯誤訊息
190
			$result["error"]=$checkArguments;
190
			$result["error"]=$checkArguments;
191
			
191
 
192
			#回傳結果
192
			#回傳結果
193
			return $result;
193
			return $result;
194
			
194
 
195
			}#if end
195
			}#if end
196
	
196
 
197
		#如果檢查不通過
197
		#如果檢查不通過
198
		if($checkArguments["passed"]=="false"){
198
		if($checkArguments["passed"]=="false"){
199
			
199
 
200
			#設置錯誤識別
200
			#設置錯誤識別
201
			$result["status"]="false";
201
			$result["status"]="false";
202
			
202
 
203
			#設置錯誤訊息
203
			#設置錯誤訊息
204
			$result["error"]=$checkArguments;
204
			$result["error"]=$checkArguments;
205
			
205
 
206
			#回傳結果
206
			#回傳結果
207
			return $result;
207
			return $result;
208
			
208
 
209
			}#if end
209
			}#if end
210
			
210
 
211
		#停止執行之前輸出 $conf["comment"] 的內容
211
		#停止執行之前輸出 $conf["comment"] 的內容
212
		exit($conf["comment"]);
212
		exit($conf["comment"]);
213
		
213
 
214
		#執行到這邊代表不正常
214
		#執行到這邊代表不正常
215
		$result["status"]="false";
215
		$result["status"]="false";
216
		
216
 
217
		#設置錯誤訊息
217
		#設置錯誤訊息
218
		$result["error"][]="非預期的錯誤";
218
		$result["error"][]="非預期的錯誤";
219
		
219
 
220
		#回傳結果
220
		#回傳結果
221
		return $result;
221
		return $result;
222
		
222
 
223
		}#function exitWithComment end
223
		}#function exitWithComment end
224
		
224
 
225
	/*
225
	/*
226
	#函式說明:
226
	#函式說明:
227
	#停止執行程式,中止前一刻會印出一段內容
227
	#停止執行程式,中止前一刻會印出一段內容
228
	#回傳結果:
228
	#回傳結果:
229
	#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
229
	#$result["status"],執行是否正常,正常的話為"true",不正常的話為"false".
Line 242... Line 242...
242
	#exit=>http://php.net/manual/en/function.exit.php
242
	#exit=>http://php.net/manual/en/function.exit.php
243
	#備註:
243
	#備註:
244
	#正常來說不會得到回傳的$result,若有則代表異常.
244
	#正常來說不會得到回傳的$result,若有則代表異常.
245
	*/
245
	*/
246
	public static function exitWithReturnValueToShell(&$conf){
246
	public static function exitWithReturnValueToShell(&$conf){
247
	
247
 
248
		#初始化要回傳的變數
248
		#初始化要回傳的變數
249
		$result=array();
249
		$result=array();
250
 
250
 
251
		#取得當前執行的函數名稱
251
		#取得當前執行的函數名稱
252
		$result["function"]=__FUNCTION__;
252
		$result["function"]=__FUNCTION__;
253
 
253
 
254
		#如果 $conf 不為陣列
254
		#如果 $conf 不為陣列
255
		if(gettype($conf)!="array"){
255
		if(gettype($conf)!="array"){
256
			
256
 
257
			#設置執行失敗
257
			#設置執行失敗
258
			$result["status"]="false";
258
			$result["status"]="false";
259
			
259
 
260
			#設置執行錯誤訊息
260
			#設置執行錯誤訊息
261
			$result["error"][]="\$conf變數須為陣列形態";
261
			$result["error"][]="\$conf變數須為陣列形態";
262
 
262
 
263
			#如果傳入的參數為 null
263
			#如果傳入的參數為 null
264
			if($conf==null){
264
			if($conf==null){
265
				
265
 
266
				#設置執行錯誤訊息
266
				#設置執行錯誤訊息
267
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
267
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
268
				
268
 
269
				}#if end
269
				}#if end
270
 
270
 
271
			#回傳結果
271
			#回傳結果
272
			return $result;
272
			return $result;
273
			
273
 
274
			}#if end
274
			}#if end
275
			
275
 
276
		#函式說明:
276
		#函式說明:
277
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
277
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
279
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
279
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
280
		#$result["function"],當前執行的函式名稱.
280
		#$result["function"],當前執行的函式名稱.
Line 300... Line 300...
300
		#$conf["canBeEmptyString"]="false";
300
		#$conf["canBeEmptyString"]="false";
301
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
301
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
302
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("returnVal","normalExit","unexpectedEixt");
302
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("returnVal","normalExit","unexpectedEixt");
303
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
303
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
304
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("returnVal","normalExit","unexpectedEixt");
304
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("returnVal","normalExit","unexpectedEixt");
305
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
305
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
306
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer","string","string");
306
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer","string","string");
307
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
307
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
308
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(0,"false","false");
308
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(0,"false","false");
309
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
309
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
310
		#$conf["arrayCountEqualCheck"][]=array();
310
		#$conf["arrayCountEqualCheck"][]=array();
311
		#參考資料來源:
311
		#參考資料來源:
312
		#array_keys=>http://php.net/manual/en/function.array-keys.php
312
		#array_keys=>http://php.net/manual/en/function.array-keys.php
313
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
313
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
314
		unset($conf["variableCheck::checkArguments"]);
314
		unset($conf["variableCheck::checkArguments"]);
315
		
315
 
316
		#如果檢查失敗
316
		#如果檢查失敗
317
		if($checkArguments["status"]=="false"){
317
		if($checkArguments["status"]=="false"){
318
			
318
 
319
			#設置錯誤識別
319
			#設置錯誤識別
320
			$result["status"]="false";
320
			$result["status"]="false";
321
			
321
 
322
			#設置錯誤訊息
322
			#設置錯誤訊息
323
			$result["error"]=$checkArguments;
323
			$result["error"]=$checkArguments;
324
			
324
 
325
			#回傳結果
325
			#回傳結果
326
			return $result;
326
			return $result;
327
			
327
 
328
			}#if end
328
			}#if end
329
	
329
 
330
		#如果檢查不通過
330
		#如果檢查不通過
331
		if($checkArguments["passed"]=="false"){
331
		if($checkArguments["passed"]=="false"){
332
			
332
 
333
			#設置錯誤識別
333
			#設置錯誤識別
334
			$result["status"]="false";
334
			$result["status"]="false";
335
			
335
 
336
			#設置錯誤訊息
336
			#設置錯誤訊息
337
			$result["error"]=$checkArguments;
337
			$result["error"]=$checkArguments;
338
			
338
 
339
			#回傳結果
339
			#回傳結果
340
			return $result;
340
			return $result;
341
			
341
 
342
			}#if end
342
			}#if end
343
		
343
 
344
		#如果是正常結束
344
		#如果是正常結束
345
		if($conf["normalExit"]==="true"){
345
		if($conf["normalExit"]==="true"){
346
		
346
 
347
			#回傳代碼設置為0
347
			#回傳代碼設置為0
348
			$conf["returnVal"]=0;
348
			$conf["returnVal"]=0;
349
		
349
 
350
			}#if end
350
			}#if end
351
			
351
 
352
		else if($conf["unexpectedEixt"]==="true"){
352
		else if($conf["unexpectedEixt"]==="true"){
353
		
353
 
354
			#回傳代碼設置為1
354
			#回傳代碼設置為1
355
			$conf["returnVal"]=1;
355
			$conf["returnVal"]=1;
356
		
356
 
357
			}#if end
357
			}#if end
358
		
358
 
359
		#停止執行並回傳 $conf["returnVal"] 給 shell
359
		#停止執行並回傳 $conf["returnVal"] 給 shell
360
		exit($conf["returnVal"]);
360
		exit($conf["returnVal"]);
361
		
361
 
362
		#執行到這邊代表不正常
362
		#執行到這邊代表不正常
363
		$result["status"]="false";
363
		$result["status"]="false";
364
		
364
 
365
		#設置錯誤訊息
365
		#設置錯誤訊息
366
		$result["error"][]="非預期的錯誤";
366
		$result["error"][]="非預期的錯誤";
367
		
367
 
368
		#回傳結果
368
		#回傳結果
369
		return $result;
369
		return $result;
370
	
370
 
371
		}#function exitWithReturnValueToShell end
371
		}#function exitWithReturnValueToShell end
372
	
372
 
373
	}#class stop end
373
	}#class stop end
374
 
374
 
375
?>
375
?>