| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 32 |
liveuser |
6 |
Copyright (C) 2014~2025 Min-Jhin,Chen
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
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
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟函式參數檢查相關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class variableCheck{
|
|
|
33 |
|
|
|
34 |
#給予 $setErrorHandler 函式使用的 conf
|
|
|
35 |
public static $setErrorHandlerConf=array();
|
|
|
36 |
|
|
|
37 |
/*
|
|
|
38 |
#函式說明:
|
|
|
39 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
40 |
#回傳結果:
|
|
|
41 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
42 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
43 |
#$result["function"],當前執行的函式名稱.
|
|
|
44 |
#必填參數:
|
|
|
45 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
46 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
47 |
#可省略參數:
|
|
|
48 |
#無.
|
|
|
49 |
#參考資料:
|
|
|
50 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
51 |
#備註:
|
|
|
52 |
#無.
|
|
|
53 |
*/
|
|
|
54 |
public function __call($method,$arguments){
|
|
|
55 |
|
|
|
56 |
#取得當前執行的函式
|
|
|
57 |
$result["function"]=__FUNCTION__;
|
|
|
58 |
|
|
|
59 |
#設置執行不正常
|
|
|
60 |
$result["status"]="false";
|
|
|
61 |
|
|
|
62 |
#設置執行錯誤
|
|
|
63 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
64 |
|
|
|
65 |
#設置所丟入的參數
|
|
|
66 |
$result["error"][]=$arguments;
|
|
|
67 |
|
|
|
68 |
#回傳結果
|
|
|
69 |
return $result;
|
|
|
70 |
|
|
|
71 |
}#function __call end
|
|
|
72 |
|
|
|
73 |
/*
|
|
|
74 |
#函式說明:
|
|
|
75 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
76 |
#回傳結果:
|
|
|
77 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
78 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
79 |
#$result["function"],當前執行的函式名稱.
|
|
|
80 |
#必填參數:
|
|
|
81 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
82 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
83 |
#可省略資料:
|
|
|
84 |
#無.
|
|
|
85 |
#參考資料:
|
|
|
86 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
87 |
#備註:
|
|
|
88 |
#無.
|
|
|
89 |
*/
|
|
|
90 |
public static function __callStatic($method,$arguments){
|
|
|
91 |
|
|
|
92 |
#取得當前執行的函式
|
|
|
93 |
$result["function"]=__FUNCTION__;
|
|
|
94 |
|
|
|
95 |
#設置執行不正常
|
|
|
96 |
$result["status"]="false";
|
|
|
97 |
|
|
|
98 |
#設置執行錯誤
|
|
|
99 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
100 |
|
|
|
101 |
#設置所丟入的參數
|
|
|
102 |
$result["error"][]=$arguments;
|
|
|
103 |
|
|
|
104 |
#回傳結果
|
|
|
105 |
return $result;
|
|
|
106 |
|
|
|
107 |
}#function __callStatic end
|
|
|
108 |
|
|
|
109 |
/*
|
|
|
110 |
#函式說明:
|
|
|
111 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
112 |
#回傳結果:
|
|
|
113 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
114 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
115 |
#$result["function"],當前執行的函式名稱.
|
|
|
116 |
#$result["argu"],設置給予的參數.
|
|
|
117 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
118 |
#$result["warning"],警告訊息
|
|
|
119 |
#$result["content"][$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
120 |
#$result["content"][$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
121 |
#$result["content"][$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
122 |
#必填參數:
|
|
|
123 |
$conf["varInput"],陣列,要檢查的陣列變數
|
|
|
124 |
$conf["varInput"]=array();
|
|
|
125 |
$conf["variableCheck"],陣列,要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
126 |
$conf["variableCheck"]=array();
|
|
|
127 |
#可省略參數:
|
|
|
128 |
#$conf["variableType"],字串陣列,要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); ,null/any代表沒有指定變數形態.若為"resource"則包含"resource (closed)".
|
|
|
129 |
#$conf["variableType"]=array();#
|
|
|
130 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置.
|
|
|
131 |
#$conf["canBeEmpty"],陣列,可以為空字串或集合的變數,僅當$conf["canBeEmptyString"]為"false"時生效.
|
|
|
132 |
#$conf["canBeEmpty"]=array();
|
|
|
133 |
#$conf["canNotBeEmpty"],陣列,不可以為空字串或集合的變數,僅當$conf["canBeEmptyString"]為"true"時生效.
|
|
|
134 |
#$conf["canNotBeEmpty"]=array();
|
|
|
135 |
#參考資料:
|
|
|
136 |
#無.
|
|
|
137 |
#備註:
|
|
|
138 |
#無.
|
|
|
139 |
*/
|
|
|
140 |
public static function isexistMulti(&$conf){
|
|
|
141 |
|
|
|
142 |
#初始化要回傳的內容
|
|
|
143 |
$result=array();
|
|
|
144 |
|
|
|
145 |
#取得當前執行的函式
|
|
|
146 |
$result["function"]=__FUNCTION__;
|
|
|
147 |
|
|
|
148 |
#如果 $conf 不為陣列
|
|
|
149 |
if(gettype($conf)!="array"){
|
|
|
150 |
|
|
|
151 |
#設置執行失敗
|
|
|
152 |
$result["status"]="false";
|
|
|
153 |
|
|
|
154 |
#設置執行錯誤訊息
|
|
|
155 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
156 |
|
|
|
157 |
#如果傳入的參數為 null
|
|
|
158 |
if($conf==null){
|
|
|
159 |
|
|
|
160 |
#設置執行錯誤訊息
|
|
|
161 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
162 |
|
|
|
163 |
}#if end
|
|
|
164 |
|
|
|
165 |
#回傳結果
|
|
|
166 |
return $result;
|
|
|
167 |
|
|
|
168 |
}#if end
|
|
|
169 |
|
|
|
170 |
#取得所使用的參數
|
|
|
171 |
$result["argu"]=$conf;
|
|
|
172 |
|
|
|
173 |
#如果 $conf["varInput"] 沒有設定
|
|
|
174 |
if(!isset($conf["varInput"])){
|
|
|
175 |
|
|
|
176 |
#設置錯誤識別
|
|
|
177 |
$result["status"]="false";
|
|
|
178 |
|
|
|
179 |
#設置錯誤訊息
|
|
|
180 |
$resutl["error"][]="\$conf[\"varInput\"]未設置";
|
|
|
181 |
|
|
|
182 |
#回傳結果
|
|
|
183 |
return $result;
|
|
|
184 |
|
|
|
185 |
}#if end
|
|
|
186 |
|
|
|
187 |
#反之代表 $conf["varInput"] 有設定
|
|
|
188 |
else{
|
|
|
189 |
|
|
|
190 |
#如果 gettype($conf["varInput"]) 不等於 "array"
|
|
|
191 |
if(gettype($conf["varInput"])!=="array"){
|
|
|
192 |
|
|
|
193 |
#echo "須為陣列";
|
|
|
194 |
|
|
|
195 |
#設置錯誤識別
|
|
|
196 |
$result["status"]="false";
|
|
|
197 |
|
|
|
198 |
#設置錯誤訊息
|
|
|
199 |
$result["error"][]="\$conf[\"varInput\"]型態須為陣列";
|
|
|
200 |
|
|
|
201 |
#回傳結果
|
|
|
202 |
return $result;
|
|
|
203 |
|
|
|
204 |
}#if end
|
|
|
205 |
|
|
|
206 |
}#else end
|
|
|
207 |
|
|
|
208 |
#如果 $conf["variableCheck"] 沒有設定
|
|
|
209 |
if(!isset($conf["variableCheck"])){
|
|
|
210 |
|
|
|
211 |
#設置錯誤識別
|
|
|
212 |
$result["status"]="false";
|
|
|
213 |
|
|
|
214 |
#設置錯誤訊息
|
|
|
215 |
$resutl["error"][]="\$conf[\"variableCheck\"]未設置";
|
|
|
216 |
|
|
|
217 |
#回傳結果
|
|
|
218 |
return $result;
|
|
|
219 |
|
|
|
220 |
}#if end
|
|
|
221 |
|
|
|
222 |
#如果可為空值的變數不存在
|
|
|
223 |
if(!isset($conf["canBeEmptyString"])){
|
|
|
224 |
|
|
|
225 |
#預設為 "true"
|
|
|
226 |
$conf["canBeEmptyString"]="true";
|
|
|
227 |
|
|
|
228 |
}#if end
|
|
|
229 |
|
|
|
230 |
#如果未設置 $conf["canBeEmpty"]
|
|
|
231 |
if(!isset($conf["canBeEmpty"])){
|
|
|
232 |
|
|
|
233 |
#設置為空陣列
|
|
|
234 |
$conf["canBeEmpty"]=array();
|
|
|
235 |
|
|
|
236 |
}#if end
|
|
|
237 |
|
|
|
238 |
#如果未設置 $conf["canNotBeEmpty"]
|
|
|
239 |
if(!isset($conf["canNotBeEmpty"])){
|
|
|
240 |
|
|
|
241 |
#設置為空陣列
|
|
|
242 |
$conf["canNotBeEmpty"]=array();
|
|
|
243 |
|
|
|
244 |
}#if end
|
|
|
245 |
|
|
|
246 |
#反之 $conf["variableCheck"] 有設定
|
|
|
247 |
else{
|
|
|
248 |
|
|
|
249 |
#如果 gettype($conf["variableCheck"]) 不等於 "array"
|
|
|
250 |
if(gettype($conf["variableCheck"])!="array"){
|
|
|
251 |
|
|
|
252 |
#設置錯誤識別
|
|
|
253 |
$result["status"]="false";
|
|
|
254 |
|
|
|
255 |
#設置錯誤訊息
|
|
|
256 |
$resutl["error"][]="\$conf[\"variableCheck\"]型態須為陣列";
|
|
|
257 |
|
|
|
258 |
#回傳結果
|
|
|
259 |
return $result;
|
|
|
260 |
|
|
|
261 |
}#if end
|
|
|
262 |
|
|
|
263 |
}#else end
|
|
|
264 |
|
|
|
265 |
#初始化目前要檢查的變數型態計數
|
|
|
266 |
$typeCount=-1;
|
|
|
267 |
|
|
|
268 |
#針對每個要檢查的變數名稱
|
|
|
269 |
foreach($conf["variableCheck"] as $shouldBtCheckedVarName){
|
|
|
270 |
|
|
|
271 |
#目前要檢查的變數型態計數+1
|
|
|
272 |
$typeCount++;
|
|
|
273 |
|
|
|
274 |
#如果有輸入的參數
|
|
|
275 |
if(isset($conf["varInput"])){
|
|
|
276 |
|
|
|
277 |
#如果 $conf["varInput"] 裡面有元素
|
|
|
278 |
if(count($conf["varInput"])!=0){
|
|
|
279 |
|
|
|
280 |
#var_dump($conf["varInput"]);
|
|
|
281 |
|
|
|
282 |
#針對每個已經放入的參數
|
|
|
283 |
foreach($conf["varInput"] as $varInputKey=>$varInputValue){
|
|
|
284 |
|
|
|
285 |
#函式說明:
|
|
|
286 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
287 |
#回傳結果:
|
|
|
288 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
289 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
290 |
#$result["error"],錯誤訊息
|
|
|
291 |
#$result["function"],當前執行的函數名稱
|
|
|
292 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
293 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
294 |
#必填參數:
|
|
|
295 |
$conf["search"]["getEqualVar"]["conditionElement"]=$shouldBtCheckedVarName;#條件元素,要等於的元素內容。
|
|
|
296 |
$conf["search"]["getEqualVar"]["compareElements"]=array($varInputKey);#要比對的陣列變數內容。
|
|
|
297 |
$temp=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
298 |
unset($conf["search"]["getEqualVar"]);
|
|
|
299 |
|
|
|
300 |
#如果 search::getEqualVar 執行失敗
|
|
|
301 |
if($temp["status"]=="false"){
|
|
|
302 |
|
|
|
303 |
#設置執行不正常
|
|
|
304 |
$result["status"]="false";
|
|
|
305 |
|
|
|
306 |
#設置錯誤訊息陣列
|
|
|
307 |
$result["error"]=$temp;
|
|
|
308 |
|
|
|
309 |
#回傳結果
|
|
|
310 |
return $result;
|
|
|
311 |
|
|
|
312 |
}#if end
|
|
|
313 |
|
|
|
314 |
#如果 search::getEqualVar 找不到必填的參數
|
|
|
315 |
if($temp["founded"]=="false"){
|
|
|
316 |
|
|
|
317 |
#則儲存其結果
|
|
|
318 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
319 |
|
|
|
320 |
#儲存給予的參數
|
|
|
321 |
$result["content"][$shouldBtCheckedVarName]["argu"]=$temp["argv"];
|
|
|
322 |
|
|
|
323 |
}#if end
|
|
|
324 |
|
|
|
325 |
#反之有找到必填的參數
|
|
|
326 |
else{
|
|
|
327 |
|
|
|
328 |
#如果$conf["canBeEmptyString"]為"false"
|
|
|
329 |
#代表變數內容不能為空字串
|
|
|
330 |
if($conf["canBeEmptyString"]=="false"){
|
|
|
331 |
|
|
|
332 |
#如果該參數不在可例外為空字串或集合的陣列裡面
|
|
|
333 |
if(!(in_array($varInputKey,$conf["canBeEmpty"]))){
|
|
|
334 |
|
|
|
335 |
#變數要有存在才行
|
|
|
336 |
if(isset($varInputValue)){
|
|
|
337 |
|
|
|
338 |
#則檢查變數內容是否為空字串
|
|
|
339 |
if($varInputValue===""){
|
|
|
340 |
|
|
|
341 |
#則儲存其結果
|
|
|
342 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
343 |
|
|
|
344 |
#設置警告訊息訊息
|
|
|
345 |
$result["error"][]="變數「".$shouldBtCheckedVarName."」不得為空字串";
|
|
|
346 |
|
|
|
347 |
#將其設為 "false"
|
|
|
348 |
$result["passed"]="false";
|
|
|
349 |
|
|
|
350 |
#換找下一個變數是否存在
|
|
|
351 |
break;
|
|
|
352 |
|
|
|
353 |
}#if end
|
|
|
354 |
|
|
|
355 |
#初始化計數為0
|
|
|
356 |
$countOFvarInputValue=false;
|
|
|
357 |
|
|
|
358 |
#如果是陣列
|
|
|
359 |
if(gettype($varInputValue)==="array"){
|
|
|
360 |
|
|
|
361 |
#計數
|
|
|
362 |
$countOFvarInputValue=count($varInputValue);
|
|
|
363 |
|
|
|
364 |
}#if end
|
|
|
365 |
|
|
|
366 |
#則檢查變數內容是否為空陣列
|
|
|
367 |
if($countOFvarInputValue===0){
|
|
|
368 |
|
|
|
369 |
#則儲存其結果
|
|
|
370 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
371 |
|
|
|
372 |
#設置警告訊息訊息
|
|
|
373 |
$result["error"][]="變數「".$shouldBtCheckedVarName."」不得為空陣列";
|
|
|
374 |
|
|
|
375 |
#將其設為 "false"
|
|
|
376 |
$result["passed"]="false";
|
|
|
377 |
|
|
|
378 |
#換找下一個變數是否存在
|
|
|
379 |
break;
|
|
|
380 |
|
|
|
381 |
}#if end
|
|
|
382 |
|
|
|
383 |
}#if end
|
|
|
384 |
|
|
|
385 |
}#if end
|
|
|
386 |
|
|
|
387 |
}#if end
|
|
|
388 |
|
|
|
389 |
#反之 $conf["canBeEmptyString"]為"true"
|
|
|
390 |
#代表變數內容可為空字串
|
|
|
391 |
else if($conf["canBeEmptyString"]==="true"){
|
|
|
392 |
|
|
|
393 |
#如果該參數不在可例外不為空字串或集合
|
|
|
394 |
if((in_array($varInputKey,$conf["canNotBeEmpty"]))){
|
|
|
395 |
|
|
|
396 |
#則檢查變數內容是否為空字串
|
|
|
397 |
#或是空集合
|
|
|
398 |
if($varInputValue===""){
|
|
|
399 |
|
|
|
400 |
#則儲存其結果
|
|
|
401 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
402 |
|
|
|
403 |
#設置警告訊息訊息
|
|
|
404 |
$result["error"][]="變數「".$shouldBtCheckedVarName."」不得為空字串";
|
|
|
405 |
|
|
|
406 |
#將其設為 "false"
|
|
|
407 |
$result["passed"]="false";
|
|
|
408 |
|
|
|
409 |
#換找下一個變數是否存在
|
|
|
410 |
break;
|
|
|
411 |
|
|
|
412 |
}#if end
|
|
|
413 |
|
|
|
414 |
#反之如果可以計數
|
|
|
415 |
else if(is_array($varInputValue)){
|
|
|
416 |
|
|
|
417 |
#或是空集合
|
|
|
418 |
if(count($varInputValue)==0){
|
|
|
419 |
|
|
|
420 |
#則儲存其結果
|
|
|
421 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
422 |
|
|
|
423 |
#設置警告訊息訊息
|
|
|
424 |
$result["error"][]="變數「".$shouldBtCheckedVarName."」不得為空陣列";
|
|
|
425 |
|
|
|
426 |
#將其設為 "false"
|
|
|
427 |
$result["passed"]="false";
|
|
|
428 |
|
|
|
429 |
#換找下一個變數是否存在
|
|
|
430 |
break;
|
|
|
431 |
|
|
|
432 |
}#if end
|
|
|
433 |
|
|
|
434 |
}#else end
|
|
|
435 |
|
|
|
436 |
}#if end
|
|
|
437 |
|
|
|
438 |
}#if end
|
|
|
439 |
|
|
|
440 |
#則儲存其結果
|
|
|
441 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="true";
|
|
|
442 |
|
|
|
443 |
#如果有設定$conf["variableType"]
|
|
|
444 |
if(isset($conf["variableType"])){
|
|
|
445 |
|
|
|
446 |
#如果正確 type 為 "resource"
|
|
|
447 |
if($conf["variableType"][$typeCount]==="resource"){
|
|
|
448 |
|
|
|
449 |
#如果是 resource 開頭的形態
|
|
|
450 |
if(strpos(gettype($varInputValue),$conf["variableType"][$typeCount])===0){
|
|
|
451 |
|
|
|
452 |
#則給予型態認證通過的識別
|
|
|
453 |
$result["content"][$shouldBtCheckedVarName]["varType"]="true";
|
|
|
454 |
|
|
|
455 |
}#if end
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#反之如果該變數的型態正確 或是要求的形態為null 或為 "any"
|
|
|
460 |
else if($conf["variableType"][$typeCount]===gettype($varInputValue) || $conf["variableType"][$typeCount]===null || $conf["variableType"][$typeCount]==="any"){
|
|
|
461 |
|
|
|
462 |
#則給予型態認證通過的識別
|
|
|
463 |
$result["content"][$shouldBtCheckedVarName]["varType"]="true";
|
|
|
464 |
|
|
|
465 |
}#if end
|
|
|
466 |
|
|
|
467 |
#反之形態不正確
|
|
|
468 |
else{
|
|
|
469 |
|
|
|
470 |
#則給予型態認不證通過的識別
|
|
|
471 |
$result["content"][$shouldBtCheckedVarName]["varType"]="false";
|
|
|
472 |
|
|
|
473 |
/*
|
|
|
474 |
#debug
|
|
|
475 |
var_dump($varInputValue);
|
|
|
476 |
echo "實際是=>".gettype($varInputValue);
|
|
|
477 |
echo "規定要=>".$conf["variableType"][$typeCount];
|
|
|
478 |
var_dump($typeCount);
|
|
|
479 |
*/
|
|
|
480 |
|
|
|
481 |
#設置錯誤的形態
|
|
|
482 |
$result["content"][$shouldBtCheckedVarName]["wrongType"]=gettype($varInputValue);
|
|
|
483 |
|
|
|
484 |
#設置正確的形態
|
|
|
485 |
$result["content"][$shouldBtCheckedVarName]["rightType"]=$conf["variableType"][$typeCount];
|
|
|
486 |
|
|
|
487 |
#設置錯誤形態的數值內容
|
|
|
488 |
$result["content"][$shouldBtCheckedVarName]["value"]=$varInputValue;
|
|
|
489 |
|
|
|
490 |
}#else end
|
|
|
491 |
|
|
|
492 |
}#if end
|
|
|
493 |
|
|
|
494 |
#換找下一個變數是否存在
|
|
|
495 |
break;
|
|
|
496 |
|
|
|
497 |
}#else end
|
|
|
498 |
|
|
|
499 |
}#foreach end
|
|
|
500 |
|
|
|
501 |
}#if end
|
|
|
502 |
|
|
|
503 |
#反之 $conf["varInput"] 裡面沒有元素
|
|
|
504 |
else{
|
|
|
505 |
|
|
|
506 |
#設置該變數不存在
|
|
|
507 |
$result["content"][$shouldBtCheckedVarName]["varExist"]="false";
|
|
|
508 |
|
|
|
509 |
#設置該變數形態不對
|
|
|
510 |
$result["content"][$shouldBtCheckedVarName]["varType"]="false";
|
|
|
511 |
|
|
|
512 |
}#else end
|
|
|
513 |
|
|
|
514 |
}#if end
|
|
|
515 |
|
|
|
516 |
}#foreach end
|
|
|
517 |
|
|
|
518 |
#如果有要檢查的變數
|
|
|
519 |
if(isset($result["content"])){
|
|
|
520 |
|
|
|
521 |
#檢查是否每個要檢查的變數都存在且形態皆正確
|
|
|
522 |
foreach($result["content"] as $name => $statusArray){
|
|
|
523 |
|
|
|
524 |
#檢查是否存在與形態是否正確的識別
|
|
|
525 |
foreach($statusArray as $status){
|
|
|
526 |
|
|
|
527 |
#如果有個變數的檢查是否通過識別為 "false"
|
|
|
528 |
if($status=="false"){
|
|
|
529 |
|
|
|
530 |
#將其設為 "false"
|
|
|
531 |
$result["passed"]="false";
|
|
|
532 |
|
|
|
533 |
}#if end
|
|
|
534 |
|
|
|
535 |
}#foreach end
|
|
|
536 |
|
|
|
537 |
}#foreach end
|
|
|
538 |
|
|
|
539 |
}#if end
|
|
|
540 |
|
|
|
541 |
#如果 $result["passed"] 沒有設置
|
|
|
542 |
if(!isset($result["passed"])){
|
|
|
543 |
|
|
|
544 |
#將其設為 true
|
|
|
545 |
$result["passed"]="true";
|
|
|
546 |
|
|
|
547 |
}#if end
|
|
|
548 |
|
|
|
549 |
#執行到這邊代表執行正常
|
|
|
550 |
$result["status"]="true";
|
|
|
551 |
|
|
|
552 |
#回傳陣列結果
|
|
|
553 |
return $result;
|
|
|
554 |
|
|
|
555 |
}#function isexistMulti end
|
|
|
556 |
|
|
|
557 |
/*
|
|
|
558 |
#函式說明:
|
|
|
559 |
#檢查變數的形態是否正確
|
|
|
560 |
#回傳結果:
|
|
|
561 |
#$result["status"],執行是否正常
|
|
|
562 |
#$result["error"].錯誤訊息陣列
|
|
|
563 |
#$result["passed"],若爲"true"則表示形態正確,"false"為形態有誤.
|
|
|
564 |
#$result["function"],當前執行的函數名稱.
|
|
|
565 |
#必填參數:
|
|
|
566 |
#$conf["vName"],字串,要檢查的變數.
|
|
|
567 |
$conf["vName"]="";
|
|
|
568 |
#$conf["vType"],字串,變數的形態,若為"any"則代表不檢查型態,若為"resource",則也允許"resource (closed)".
|
|
|
569 |
$conf["vType"]="";
|
|
|
570 |
#可省略參數:
|
|
|
571 |
#無.
|
|
|
572 |
#參考資料:
|
|
|
573 |
#無.
|
|
|
574 |
#備註:
|
|
|
575 |
#無.
|
|
|
576 |
*/
|
|
|
577 |
public static function checkType(&$conf){
|
|
|
578 |
|
|
|
579 |
#初始化要回傳的變數
|
|
|
580 |
$result=array();
|
|
|
581 |
|
|
|
582 |
#取得當前執行的函數名稱
|
|
|
583 |
$result["function"]=__FUNCTION__;
|
|
|
584 |
|
|
|
585 |
#如果 $conf 不為陣列
|
|
|
586 |
if(gettype($conf)!="array"){
|
|
|
587 |
|
|
|
588 |
#設置執行失敗
|
|
|
589 |
$result["status"]="false";
|
|
|
590 |
|
|
|
591 |
#設置執行錯誤訊息
|
|
|
592 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
593 |
|
|
|
594 |
#如果傳入的參數為 null
|
|
|
595 |
if($conf==null){
|
|
|
596 |
|
|
|
597 |
#設置執行錯誤訊息
|
|
|
598 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
599 |
|
|
|
600 |
}#if end
|
|
|
601 |
|
|
|
602 |
#回傳結果
|
|
|
603 |
return $result;
|
|
|
604 |
|
|
|
605 |
}#if end
|
|
|
606 |
|
|
|
607 |
#如果 $conf["vName"] 變數不存在
|
|
|
608 |
if(!isset($conf["vName"])){
|
|
|
609 |
|
|
|
610 |
#設置執行錯誤
|
|
|
611 |
$result["status"]="false";
|
|
|
612 |
|
|
|
613 |
#設置錯誤訊息
|
|
|
614 |
$result["error"][]="\$conf[\"vName\"]參數不存在";
|
|
|
615 |
|
|
|
616 |
#回傳結果
|
|
|
617 |
return $result;
|
|
|
618 |
|
|
|
619 |
}#if end
|
|
|
620 |
|
|
|
621 |
#如果 $conf["vType"] 變數不存在
|
|
|
622 |
if(!isset($conf["vType"])){
|
|
|
623 |
|
|
|
624 |
#設置執行錯誤
|
|
|
625 |
$result["status"]="false";
|
|
|
626 |
|
|
|
627 |
#設置錯誤訊息
|
|
|
628 |
$result["error"][]="\$conf[\"vType\"]參數不存在";
|
|
|
629 |
|
|
|
630 |
#回傳結果
|
|
|
631 |
return $result;
|
|
|
632 |
|
|
|
633 |
}#if end
|
|
|
634 |
|
|
|
635 |
#如果是 resource
|
|
|
636 |
if($conf["vType"]==="resource"){
|
|
|
637 |
|
|
|
638 |
#如果不是開頭為 "resource" 的形態
|
|
|
639 |
if(strpos(gettype($conf["vName"]),$conf["vType"])!==0){
|
|
|
640 |
|
|
|
641 |
#設置執行正常
|
|
|
642 |
$result["status"]="true";
|
|
|
643 |
|
|
|
644 |
#設置檢查不通過
|
|
|
645 |
$result["passed"]="false";
|
|
|
646 |
|
|
|
647 |
#設置錯誤訊息
|
|
|
648 |
$result["error"][]="變數\$conf[\"vName\"]的形態應為".$conf["vType"];
|
|
|
649 |
|
|
|
650 |
#回傳結果
|
|
|
651 |
return $result;
|
|
|
652 |
|
|
|
653 |
}#if end
|
|
|
654 |
|
|
|
655 |
}#if end
|
|
|
656 |
|
|
|
657 |
#反之若其變數形態不爲 $conf["vType"] 且期望的變數型態不為 "any"
|
|
|
658 |
else if(gettype($conf["vName"])!=$conf["vType"] && $conf["vType"]!=="any"){
|
|
|
659 |
|
|
|
660 |
#設置執行正常
|
|
|
661 |
$result["status"]="true";
|
|
|
662 |
|
|
|
663 |
#設置檢查不通過
|
|
|
664 |
$result["passed"]="false";
|
|
|
665 |
|
|
|
666 |
#設置錯誤訊息
|
|
|
667 |
$result["error"][]="變數\$conf[\"vName\"]的形態應為".$conf["vType"];
|
|
|
668 |
|
|
|
669 |
#回傳結果
|
|
|
670 |
return $result;
|
|
|
671 |
|
|
|
672 |
}#if end
|
|
|
673 |
|
|
|
674 |
#執行到這表代表執行正常
|
|
|
675 |
$result["status"]="true";
|
|
|
676 |
|
|
|
677 |
#執行到這邊代表形態檢查通過
|
|
|
678 |
$result["passed"]="true";
|
|
|
679 |
|
|
|
680 |
#回傳結果
|
|
|
681 |
return $result;
|
|
|
682 |
|
|
|
683 |
}#function checkType end
|
|
|
684 |
|
|
|
685 |
/*
|
|
|
686 |
#函式說明:
|
|
|
687 |
#檢查一個陣列變數裏面含有指定key的元素共有個
|
|
|
688 |
#回傳結果:
|
|
|
689 |
#$result["status"],執行是否正常
|
|
|
690 |
#$result["error"].錯誤訊息陣列
|
|
|
691 |
#$result["function"],當前執行的函數名稱.
|
|
|
692 |
#$result["content"],爲總共找到幾個不是空值的數量
|
|
|
693 |
#必填參數:
|
|
|
694 |
#$conf["conditionValue"],陣列,想要調查具有該名稱的陣列元素,須為陣列值.
|
|
|
695 |
$conf["conditionValue"]=array();
|
|
|
696 |
#$conf["inputArray"],陣列,想要檢查的陣列變數,須為陣列值.
|
|
|
697 |
$conf["inputArray"]=array();
|
|
|
698 |
#可省略參數:
|
|
|
699 |
#無.
|
|
|
700 |
#參考資料:
|
|
|
701 |
#無.
|
|
|
702 |
#備註:
|
|
|
703 |
#無.
|
|
|
704 |
*/
|
|
|
705 |
public static function computeIsset(&$conf){
|
|
|
706 |
|
|
|
707 |
#初始化要回傳的變數
|
|
|
708 |
$result=array();
|
|
|
709 |
|
|
|
710 |
#取得當前執行的函數名稱
|
|
|
711 |
$result["function"]=__FUNCTION__;
|
|
|
712 |
|
|
|
713 |
#如果 $conf 不為陣列
|
|
|
714 |
if(gettype($conf)!="array"){
|
|
|
715 |
|
|
|
716 |
#設置執行失敗
|
|
|
717 |
$result["status"]="false";
|
|
|
718 |
|
|
|
719 |
#設置執行錯誤訊息
|
|
|
720 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
721 |
|
|
|
722 |
#如果傳入的參數為 null
|
|
|
723 |
if($conf==null){
|
|
|
724 |
|
|
|
725 |
#設置執行錯誤訊息
|
|
|
726 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
727 |
|
|
|
728 |
}#if end
|
|
|
729 |
|
|
|
730 |
#回傳結果
|
|
|
731 |
return $result;
|
|
|
732 |
|
|
|
733 |
}#if end
|
|
|
734 |
|
|
|
735 |
#如果 $conf["conditionValue"] 變數不存在
|
|
|
736 |
if(!isset($conf["conditionValue"])){
|
|
|
737 |
|
|
|
738 |
#回傳錯誤訊息
|
|
|
739 |
return "\$conf[\"conditionValue\"]參數不存在";
|
|
|
740 |
|
|
|
741 |
}#if end
|
|
|
742 |
|
|
|
743 |
#如果 $conf["inputArray"] 變數不存在
|
|
|
744 |
if(!isset($conf["inputArray"])){
|
|
|
745 |
|
|
|
746 |
#回傳錯誤訊息
|
|
|
747 |
return "\$conf[\"inputArray\"]參數不存在";
|
|
|
748 |
|
|
|
749 |
}#if end
|
|
|
750 |
|
|
|
751 |
#設定預設的計數爲0
|
|
|
752 |
$result["content"]=0;
|
|
|
753 |
|
|
|
754 |
#看有幾個要尋找是否存在的變數,就執行幾次
|
|
|
755 |
for($i=0;$i<count($conf["conditionValue"]);$i++){
|
|
|
756 |
|
|
|
757 |
#檢查是否有該變數存在
|
|
|
758 |
if(isset($conf["inputArray"][$conf["conditionValue"][$i]])){
|
|
|
759 |
|
|
|
760 |
#若存在則計數+1
|
|
|
761 |
$result["content"]++;
|
|
|
762 |
|
|
|
763 |
}#if end
|
|
|
764 |
|
|
|
765 |
}#for end
|
|
|
766 |
|
|
|
767 |
#設置執行正常
|
|
|
768 |
$result["status"]="true";
|
|
|
769 |
|
|
|
770 |
#回傳結果
|
|
|
771 |
return $result;
|
|
|
772 |
|
|
|
773 |
}#function computeIsset end
|
|
|
774 |
|
|
|
775 |
/*
|
|
|
776 |
#函式說明:
|
|
|
777 |
#檢查某個元素是否存在於該一維陣列變數裏面
|
|
|
778 |
#回傳結果:
|
|
|
779 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
780 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
781 |
#$result["function"],當前執行的函式名稱.
|
|
|
782 |
#$result["founded"],"true",表示該元素已經存在於該一維陣列變數裏面,"false"表示該元素不存在於該一維陣列變數裏面 .
|
|
|
783 |
#必填參數:
|
|
|
784 |
#$conf["searchString"],字串,要搜尋的元素內容.
|
|
|
785 |
$conf["searchString"]="";
|
|
|
786 |
#$conf["searchArray"],字串陣列,要搜尋的陣列變數.
|
|
|
787 |
$conf["searchArray"]=array();
|
|
|
788 |
#可省略參數:
|
|
|
789 |
#無.
|
|
|
790 |
#參考資料:
|
|
|
791 |
#無.
|
|
|
792 |
#備註:
|
|
|
793 |
#無.
|
|
|
794 |
*/
|
|
|
795 |
public static function checkElementExistFromAnArray(&$conf){
|
|
|
796 |
|
|
|
797 |
#初始化要回傳的內容
|
|
|
798 |
$result=array();
|
|
|
799 |
|
|
|
800 |
#記錄當前執行的函數名稱
|
|
|
801 |
$result["function"]=__FUNCTION__;
|
|
|
802 |
|
|
|
803 |
#如果 $conf 不為陣列
|
|
|
804 |
if(gettype($conf)!="array"){
|
|
|
805 |
|
|
|
806 |
#設置執行失敗
|
|
|
807 |
$result["status"]="false";
|
|
|
808 |
|
|
|
809 |
#設置執行錯誤訊息
|
|
|
810 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
811 |
|
|
|
812 |
#如果傳入的參數為 null
|
|
|
813 |
if($conf==null){
|
|
|
814 |
|
|
|
815 |
#設置執行錯誤訊息
|
|
|
816 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
817 |
|
|
|
818 |
}#if end
|
|
|
819 |
|
|
|
820 |
#回傳結果
|
|
|
821 |
return $result;
|
|
|
822 |
|
|
|
823 |
}#if end
|
|
|
824 |
|
|
|
825 |
#檢查參數
|
|
|
826 |
#函式說明:
|
|
|
827 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
828 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
829 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
830 |
#$result["function"],當前執行的函式名稱.
|
|
|
831 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
832 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
833 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
834 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
835 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
836 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
837 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
838 |
#必填參數:
|
|
|
839 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
840 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
841 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
842 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("searchString","searchArray");
|
|
|
843 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
844 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
845 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
846 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
847 |
#可省略參數:
|
|
|
848 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
849 |
$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
850 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
851 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("firstLineVarName");
|
|
|
852 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
853 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
854 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
855 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
856 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
857 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
858 |
#參考資料來源:
|
|
|
859 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
860 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
861 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
862 |
|
|
|
863 |
#如果檢查參數失敗
|
|
|
864 |
if($checkArguments["status"]=="false"){
|
|
|
865 |
|
|
|
866 |
#設置執行失敗
|
|
|
867 |
$result["status"]="false";
|
|
|
868 |
|
|
|
869 |
#設置執行錯誤訊息
|
|
|
870 |
$result["error"]=$checkArguments;
|
|
|
871 |
|
|
|
872 |
#回傳結果
|
|
|
873 |
return $result;
|
|
|
874 |
|
|
|
875 |
}#if end
|
|
|
876 |
|
|
|
877 |
#如果檢查不通過
|
|
|
878 |
if($checkArguments["passed"]=="false"){
|
|
|
879 |
|
|
|
880 |
#設置執行失敗
|
|
|
881 |
$result["status"]="false";
|
|
|
882 |
|
|
|
883 |
#設置執行錯誤訊息
|
|
|
884 |
$result["error"]=$checkArguments;
|
|
|
885 |
|
|
|
886 |
#回傳結果
|
|
|
887 |
return $result;
|
|
|
888 |
|
|
|
889 |
}#if end
|
|
|
890 |
|
|
|
891 |
#檢查 $conf["searchString"] 是否存在於 $conf["searchArray"]
|
|
|
892 |
$in_array=in_array($conf["searchString"],$conf["searchArray"]);
|
|
|
893 |
|
|
|
894 |
#如果 $conf["searchString"] 存在於 $conf["searchArray"]
|
|
|
895 |
if($in_array){
|
|
|
896 |
|
|
|
897 |
#設置沒有找到元素
|
|
|
898 |
$result["founded"]="true";
|
|
|
899 |
|
|
|
900 |
}#if end
|
|
|
901 |
|
|
|
902 |
#反之
|
|
|
903 |
else{
|
|
|
904 |
|
|
|
905 |
#設置沒有找到元素
|
|
|
906 |
$result["founded"]="false";
|
|
|
907 |
|
|
|
908 |
}#else end
|
|
|
909 |
|
|
|
910 |
#設置執行正常
|
|
|
911 |
$result["status"]="true";
|
|
|
912 |
|
|
|
913 |
#回傳結果
|
|
|
914 |
return $result;
|
|
|
915 |
|
|
|
916 |
}#function checkElementExistFromAnArray end
|
|
|
917 |
|
|
|
918 |
/*
|
|
|
919 |
#函式說明:
|
|
|
920 |
#判斷session變數 $_SESSION["key1"]["key2"]["key3"]... 是否存在,若存在則可以將其內容回傳,若目標session變數不存在則可以指定要回傳的內容,取得變數內容之後可以卸除其session變數.
|
|
|
921 |
#回傳結果:
|
|
|
922 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
923 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
924 |
#$result["function"],當前執行的函式名稱.
|
|
|
925 |
#$result["content"],取得的session變數內容
|
|
|
926 |
#必填參數:
|
|
|
927 |
#$conf["sessionName"],陣列字串,要取得的session變數名稱,須爲陣列字串值。$conf["sessionName"][0]對應的是session變數的第1個key;$conf["sessionName"][1]對應的是session變數的第2個key;$conf["sessionName"][2]對應的是session變數的第3個key。
|
|
|
928 |
$conf["sessionName"]=array();
|
|
|
929 |
#可省略參數:
|
|
|
930 |
#$conf["ifEmptyThenSet"],字串,如果目標session變數不存在,則指派爲什麼樣的數值給目標變數?預設爲"".
|
|
|
931 |
#$conf["ifEmptyThenSet"]="";
|
|
|
932 |
#$conf["unsetSessionVar"],字串,是否要在指派完變數之後將該sesssion變數卸除,其數值會變成NULL,若設爲"true",表示要卸除,預設為"false",表示不卸除.
|
|
|
933 |
#$conf["unsetSessionVar"]="true";
|
|
|
934 |
#參考資料:
|
|
|
935 |
#無.
|
|
|
936 |
#備註:
|
|
|
937 |
#無.
|
|
|
938 |
*/
|
|
|
939 |
public static function assignSessionValueToVar(&$conf){
|
|
|
940 |
|
|
|
941 |
#初始化要回傳的內容
|
|
|
942 |
$result=array();
|
|
|
943 |
|
|
|
944 |
#記錄當前執行的函數名稱
|
|
|
945 |
$result["function"]=__FUNCTION__;
|
|
|
946 |
|
|
|
947 |
#如果 $conf 不為陣列
|
|
|
948 |
if(gettype($conf)!="array"){
|
|
|
949 |
|
|
|
950 |
#設置執行失敗
|
|
|
951 |
$result["status"]="false";
|
|
|
952 |
|
|
|
953 |
#設置執行錯誤訊息
|
|
|
954 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
955 |
|
|
|
956 |
#如果傳入的參數為 null
|
|
|
957 |
if($conf==null){
|
|
|
958 |
|
|
|
959 |
#設置執行錯誤訊息
|
|
|
960 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
961 |
|
|
|
962 |
}#if end
|
|
|
963 |
|
|
|
964 |
#回傳結果
|
|
|
965 |
return $result;
|
|
|
966 |
|
|
|
967 |
}#if end
|
|
|
968 |
|
|
|
969 |
#檢查參數
|
|
|
970 |
#函式說明:
|
|
|
971 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
972 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
973 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
974 |
#$result["function"],當前執行的函式名稱.
|
|
|
975 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
976 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
977 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
978 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
979 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
980 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
981 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
982 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
983 |
#必填參數:
|
|
|
984 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
985 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
986 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
987 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sessionName");
|
|
|
988 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
989 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
990 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
991 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
992 |
#可省略參數:
|
|
|
993 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
994 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
995 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
996 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
997 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
998 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ifEmptyThenSet","unsetSessionVar");
|
|
|
999 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1000 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
1001 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1002 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","false");
|
|
|
1003 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1004 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1005 |
#參考資料來源:
|
|
|
1006 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1007 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1008 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1009 |
|
|
|
1010 |
#如果檢查失敗
|
|
|
1011 |
if($checkArguments["status"]=="false"){
|
|
|
1012 |
|
|
|
1013 |
#設置錯誤識別
|
|
|
1014 |
$result["status"]="false";
|
|
|
1015 |
|
|
|
1016 |
#設置錯誤訊息
|
|
|
1017 |
$result["error"]=$checkArguments;
|
|
|
1018 |
|
|
|
1019 |
#回傳結果
|
|
|
1020 |
return $result;
|
|
|
1021 |
|
|
|
1022 |
}#if end
|
|
|
1023 |
|
|
|
1024 |
#如果檢查不通過
|
|
|
1025 |
if($checkArguments["passed"]=="false"){
|
|
|
1026 |
|
|
|
1027 |
#設置錯誤識別
|
|
|
1028 |
$result["status"]="false";
|
|
|
1029 |
|
|
|
1030 |
#設置錯誤訊息
|
|
|
1031 |
$result["error"]=$checkArguments;
|
|
|
1032 |
|
|
|
1033 |
#回傳結果
|
|
|
1034 |
return $result;
|
|
|
1035 |
|
|
|
1036 |
}#if end
|
|
|
1037 |
|
|
|
1038 |
#指派一個沒有內容的變數
|
|
|
1039 |
$tempVar=null;
|
|
|
1040 |
|
|
|
1041 |
#依據 $conf["sessionName"] 的元素數量與內如來判斷特定的 session 變數是否存在.
|
|
|
1042 |
for($i=0;$i<count($conf["sessionName"]);$i++){
|
|
|
1043 |
|
|
|
1044 |
#如果是第一層
|
|
|
1045 |
if($i==0){
|
|
|
1046 |
|
|
|
1047 |
#如果 session 變數不存在
|
|
|
1048 |
if(!isset($_SESSION[$conf["sessionName"][$i]])){
|
|
|
1049 |
|
|
|
1050 |
#取得指定的內容
|
|
|
1051 |
$result["content"]=$conf["ifEmptyThenSet"];
|
|
|
1052 |
|
|
|
1053 |
#設置執行正常
|
|
|
1054 |
$result["status"]="true";
|
|
|
1055 |
|
|
|
1056 |
#回傳結果
|
|
|
1057 |
return $result;
|
|
|
1058 |
|
|
|
1059 |
}#if end
|
|
|
1060 |
|
|
|
1061 |
#取得第一層 session 變數的參照
|
|
|
1062 |
$tempVar=&$_SESSION[$conf["sessionName"][$i]];
|
|
|
1063 |
|
|
|
1064 |
}#if end
|
|
|
1065 |
|
|
|
1066 |
#反之
|
|
|
1067 |
else{
|
|
|
1068 |
|
|
|
1069 |
#如果 session 變數不存在
|
|
|
1070 |
if(!isset($tempVar[$conf["sessionName"][$i]])){
|
|
|
1071 |
|
|
|
1072 |
#取得指定的內容
|
|
|
1073 |
$result["content"]=$conf["ifEmptyThenSet"];
|
|
|
1074 |
|
|
|
1075 |
#設置執行正常
|
|
|
1076 |
$result["status"]="true";
|
|
|
1077 |
|
|
|
1078 |
#回傳結果
|
|
|
1079 |
return $result;
|
|
|
1080 |
|
|
|
1081 |
}#if end
|
|
|
1082 |
|
|
|
1083 |
#取得 session 變數下一層key的參照
|
|
|
1084 |
$tempVar=&$tempVar[$conf["sessionName"][$i]];
|
|
|
1085 |
|
|
|
1086 |
}#else end
|
|
|
1087 |
|
|
|
1088 |
}#for end
|
|
|
1089 |
|
|
|
1090 |
#取得 session 變數的內容
|
|
|
1091 |
$result["content"]=$tempVar;
|
|
|
1092 |
|
|
|
1093 |
#如果 $conf["unsetSessionVar"] 為 "true"
|
|
|
1094 |
if($conf["unsetSessionVar"]=="true"){
|
|
|
1095 |
|
|
|
1096 |
#透過指定 session 變數為 NULL 來卸除變數
|
|
|
1097 |
$tempVar=NULL;
|
|
|
1098 |
|
|
|
1099 |
#卸除session變數,僅會卸除$tempVar而已,session變數不會卸除.
|
|
|
1100 |
#unset($tempVar);
|
|
|
1101 |
|
|
|
1102 |
}#if end
|
|
|
1103 |
|
|
|
1104 |
#設置執行正常
|
|
|
1105 |
$result["status"]="true";
|
|
|
1106 |
|
|
|
1107 |
#回傳結果
|
|
|
1108 |
return $result;
|
|
|
1109 |
|
|
|
1110 |
}#assignSessionValueToVariable end
|
|
|
1111 |
|
|
|
1112 |
/*
|
|
|
1113 |
#函式說明:
|
|
|
1114 |
#判斷變數是否存在,將之儲存到session變數裏面
|
|
|
1115 |
#回傳結果:
|
|
|
1116 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1117 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1118 |
#$result["function"],當前執行的函式名稱.
|
|
|
1119 |
#$result["founded"],變數是否存在,"true"為存在,"false"為不存在.
|
|
|
1120 |
#必填參數:
|
|
|
1121 |
#$conf["var"],參考變數,想要確認是否存在的變數
|
|
|
1122 |
$conf["var"]=&;
|
|
|
1123 |
#$conf["sessionVarName"],陣列字串,要將變數存到key為什麼的session多維變數裏面
|
|
|
1124 |
$conf["sessionVarName"]=array();
|
|
|
1125 |
#可省略參數:
|
|
|
1126 |
#無.
|
|
|
1127 |
#參考資料:
|
|
|
1128 |
#無.
|
|
|
1129 |
#備註:
|
|
|
1130 |
#要改寫成可以依據 $conf["sessionVarName"] 元素數量建立多維的session變數.
|
|
|
1131 |
*/
|
|
|
1132 |
public static function assignVarToSessionValue(&$conf){
|
|
|
1133 |
|
|
|
1134 |
#初始化要回傳的內容
|
|
|
1135 |
$result=array();
|
|
|
1136 |
|
|
|
1137 |
#記錄當前執行的函數名稱
|
|
|
1138 |
$result["function"]=__FUNCTION__;
|
|
|
1139 |
|
|
|
1140 |
#如果 $conf 不為陣列
|
|
|
1141 |
if(gettype($conf)!="array"){
|
|
|
1142 |
|
|
|
1143 |
#設置執行失敗
|
|
|
1144 |
$result["status"]="false";
|
|
|
1145 |
|
|
|
1146 |
#設置執行錯誤訊息
|
|
|
1147 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1148 |
|
|
|
1149 |
#如果傳入的參數為 null
|
|
|
1150 |
if($conf==null){
|
|
|
1151 |
|
|
|
1152 |
#設置執行錯誤訊息
|
|
|
1153 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1154 |
|
|
|
1155 |
}#if end
|
|
|
1156 |
|
|
|
1157 |
#回傳結果
|
|
|
1158 |
return $result;
|
|
|
1159 |
|
|
|
1160 |
}#if end
|
|
|
1161 |
|
|
|
1162 |
#檢查參數
|
|
|
1163 |
#函式說明:
|
|
|
1164 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1165 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1166 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1167 |
#$result["function"],當前執行的函式名稱.
|
|
|
1168 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1169 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1170 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1171 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1172 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1173 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1174 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1175 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1176 |
#必填參數:
|
|
|
1177 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1178 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1179 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1180 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("var","sessionVarName");
|
|
|
1181 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
1182 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"array");
|
|
|
1183 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1184 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1185 |
#可省略參數:
|
|
|
1186 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1187 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1188 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1189 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1190 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1191 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ifEmptyThenSet","unsetSessionVar");
|
|
|
1192 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1193 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
1194 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1195 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","false");
|
|
|
1196 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1197 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1198 |
#參考資料來源:
|
|
|
1199 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1200 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1201 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1202 |
|
|
|
1203 |
#如果檢查失敗
|
|
|
1204 |
if($checkArguments["status"]==="false"){
|
|
|
1205 |
|
|
|
1206 |
#設置錯誤識別
|
|
|
1207 |
$result["status"]="false";
|
|
|
1208 |
|
|
|
1209 |
#設置錯誤訊息
|
|
|
1210 |
$result["error"]=$checkArguments;
|
|
|
1211 |
|
|
|
1212 |
#回傳結果
|
|
|
1213 |
return $result;
|
|
|
1214 |
|
|
|
1215 |
}#if end
|
|
|
1216 |
|
|
|
1217 |
#如果檢查不通過
|
|
|
1218 |
if($checkArguments["passed"]==="false"){
|
|
|
1219 |
|
|
|
1220 |
#設置錯誤識別
|
|
|
1221 |
$result["status"]="false";
|
|
|
1222 |
|
|
|
1223 |
#設置錯誤訊息
|
|
|
1224 |
$result["error"]=$checkArguments;
|
|
|
1225 |
|
|
|
1226 |
#回傳結果
|
|
|
1227 |
return $result;
|
|
|
1228 |
|
|
|
1229 |
}#if end
|
|
|
1230 |
|
|
|
1231 |
#若變數是不存在
|
|
|
1232 |
if(!isset($conf["var"])){
|
|
|
1233 |
|
|
|
1234 |
#設置找不到變數
|
|
|
1235 |
$result["founded"]="false";
|
|
|
1236 |
|
|
|
1237 |
}#if end
|
|
|
1238 |
|
|
|
1239 |
#反之
|
|
|
1240 |
else{
|
|
|
1241 |
|
|
|
1242 |
#設置找到變數
|
|
|
1243 |
$result["founded"]="true";
|
|
|
1244 |
|
|
|
1245 |
#初始化暫存 session 變數參考的變數
|
|
|
1246 |
$tempVar;
|
|
|
1247 |
|
|
|
1248 |
#依據 $conf["sessionVarName"] 的元素個數建立 session 變數
|
|
|
1249 |
for($i=0;$i<count($conf["sessionVarName"]);$i++){
|
|
|
1250 |
|
|
|
1251 |
#如果是第一層
|
|
|
1252 |
if($i==0){
|
|
|
1253 |
|
|
|
1254 |
#如果是最後一層
|
|
|
1255 |
if($i==count($conf["sessionVarName"])-1){
|
|
|
1256 |
|
|
|
1257 |
#建立 session 變數,並指定內容.
|
|
|
1258 |
$_SESSION[$conf["sessionVarName"][$i]]=$conf["var"];
|
|
|
1259 |
|
|
|
1260 |
}#if end
|
|
|
1261 |
|
|
|
1262 |
#反之
|
|
|
1263 |
else{
|
|
|
1264 |
|
|
|
1265 |
#如果 session 變數未建立
|
|
|
1266 |
if(!isset($_SESSION[$conf["sessionVarName"][$i]])){
|
|
|
1267 |
|
|
|
1268 |
#建立 session 變數,指派為空陣列
|
|
|
1269 |
$_SESSION[$conf["sessionVarName"][$i]]=array();
|
|
|
1270 |
|
|
|
1271 |
}#if end
|
|
|
1272 |
|
|
|
1273 |
}#else end
|
|
|
1274 |
|
|
|
1275 |
#取得 session 變數的參考
|
|
|
1276 |
$tempVar=&$_SESSION[$conf["sessionVarName"][$i]];
|
|
|
1277 |
|
|
|
1278 |
}#if end
|
|
|
1279 |
|
|
|
1280 |
#反之
|
|
|
1281 |
else{
|
|
|
1282 |
|
|
|
1283 |
#如果是最後一層
|
|
|
1284 |
if($i==count($conf["sessionVarName"])-1){
|
|
|
1285 |
|
|
|
1286 |
#建立 session 變數,並指定內容.
|
|
|
1287 |
$tempVar[$conf["sessionVarName"][$i]]=$conf["var"];
|
|
|
1288 |
|
|
|
1289 |
}#if end
|
|
|
1290 |
|
|
|
1291 |
#反之
|
|
|
1292 |
else{
|
|
|
1293 |
#如果 session 變數未建立
|
|
|
1294 |
if(!isset($tempVar[$conf["sessionVarName"][$i]])){
|
|
|
1295 |
|
|
|
1296 |
#建立 session 變數,指派為空陣列
|
|
|
1297 |
$tempVar[$conf["sessionVarName"][$i]]=array();
|
|
|
1298 |
|
|
|
1299 |
}#if end
|
|
|
1300 |
|
|
|
1301 |
}#else end
|
|
|
1302 |
|
|
|
1303 |
#取得 session 變數的參考
|
|
|
1304 |
$tempVar=&$tempVar[$conf["sessionVarName"][$i]];
|
|
|
1305 |
|
|
|
1306 |
}#else end
|
|
|
1307 |
|
|
|
1308 |
#debug
|
|
|
1309 |
#unset($_SESSION["manageDbAndTable"]);
|
|
|
1310 |
#unset($_SESSION[""]);
|
|
|
1311 |
#unset($_SESSION["variableCheck"]);
|
|
|
1312 |
#var_dump($_SESSION);
|
|
|
1313 |
|
|
|
1314 |
}#for end
|
|
|
1315 |
|
|
|
1316 |
}#else end
|
|
|
1317 |
|
|
|
1318 |
#設置執行正常
|
|
|
1319 |
$result["status"]="true";
|
|
|
1320 |
|
|
|
1321 |
#回傳結果
|
|
|
1322 |
return $result;
|
|
|
1323 |
|
|
|
1324 |
}#function assignVarToSessionValue end
|
|
|
1325 |
|
|
|
1326 |
/*
|
|
|
1327 |
#函式說明:
|
|
|
1328 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
1329 |
#回傳結果:
|
|
|
1330 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1331 |
#$result["error"],錯誤訊息陣列.
|
|
|
1332 |
#$result["function"],當前執行的函式名稱.
|
|
|
1333 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
1334 |
#必填參數:
|
|
|
1335 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
1336 |
$conf["checkedVar"]=$conf;
|
|
|
1337 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
1338 |
$conf["sikpableVarNameArray"]=array("",);
|
|
|
1339 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
1340 |
$argu=&$conf;
|
|
|
1341 |
#可省略參數:
|
|
|
1342 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.
|
|
|
1343 |
#$conf["skipableVarTypeArray"]=array("",);
|
|
|
1344 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.
|
|
|
1345 |
#$conf["skipableVarDefaultValue"]=array("",);
|
|
|
1346 |
#參考資料:
|
|
|
1347 |
#無.
|
|
|
1348 |
#備註:
|
|
|
1349 |
#無.
|
|
|
1350 |
*/
|
|
|
1351 |
public static function checkSkipableVarType($conf,&$argu){
|
|
|
1352 |
|
|
|
1353 |
#初始化要回傳的內容
|
|
|
1354 |
$result=array();
|
|
|
1355 |
|
|
|
1356 |
#記錄當前執行的函數名稱
|
|
|
1357 |
$result["function"]=__FUNCTION__;
|
|
|
1358 |
|
|
|
1359 |
#如果 $conf 不為陣列
|
|
|
1360 |
if(gettype($conf)!="array"){
|
|
|
1361 |
|
|
|
1362 |
#設置執行失敗
|
|
|
1363 |
$result["status"]="false";
|
|
|
1364 |
|
|
|
1365 |
#設置執行錯誤訊息
|
|
|
1366 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1367 |
|
|
|
1368 |
#如果傳入的參數為 null
|
|
|
1369 |
if($conf==null){
|
|
|
1370 |
|
|
|
1371 |
#設置執行錯誤訊息
|
|
|
1372 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1373 |
|
|
|
1374 |
}#if end
|
|
|
1375 |
|
|
|
1376 |
#回傳結果
|
|
|
1377 |
return $result;
|
|
|
1378 |
|
|
|
1379 |
}#if end
|
|
|
1380 |
|
|
|
1381 |
#設置當前函式名稱
|
|
|
1382 |
#參考資料來源:
|
|
|
1383 |
#http://php.net/manual/en/language.constants.predefined.php
|
|
|
1384 |
$result["function"]=__FUNCTION__;
|
|
|
1385 |
|
|
|
1386 |
#如果 $conf 不為陣列
|
|
|
1387 |
if(gettype($conf)!="array"){
|
|
|
1388 |
|
|
|
1389 |
#設置執行失敗
|
|
|
1390 |
$result["status"]="false";
|
|
|
1391 |
|
|
|
1392 |
#設置執行錯誤訊息
|
|
|
1393 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1394 |
|
|
|
1395 |
#回傳結果
|
|
|
1396 |
return $result;
|
|
|
1397 |
|
|
|
1398 |
}#if end
|
|
|
1399 |
|
|
|
1400 |
#檢查參數
|
|
|
1401 |
#函式說明:
|
|
|
1402 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1403 |
#回傳結果:
|
|
|
1404 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1405 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1406 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1407 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1408 |
#必填參數:
|
|
|
1409 |
$conf["variableCheck::isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1410 |
$conf["variableCheck::isexistMulti"]["variableCheck"]=array("checkedVar","sikpableVarNameArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1411 |
#可省略參數:
|
|
|
1412 |
$conf["variableCheck::isexistMulti"]["variableType"]=array("array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1413 |
#$conf["variableCheck::isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1414 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck::isexistMulti"]);
|
|
|
1415 |
unset($conf["variableCheck::isexistMulti"]);
|
|
|
1416 |
|
|
|
1417 |
#如果 $checkResult["status"]等於 "false"
|
|
|
1418 |
if($checkResult["status"]=="false"){
|
|
|
1419 |
|
|
|
1420 |
#設置執行錯誤的識別
|
|
|
1421 |
$result["status"]="false";
|
|
|
1422 |
|
|
|
1423 |
#設置錯誤訊息
|
|
|
1424 |
$result["error"]=$checkResult;
|
|
|
1425 |
|
|
|
1426 |
#回傳結果
|
|
|
1427 |
return $result;
|
|
|
1428 |
|
|
|
1429 |
}#if end
|
|
|
1430 |
|
|
|
1431 |
#如果 $checkResult["passed"]等於 "false"
|
|
|
1432 |
if($checkResult["passed"]=="false"){
|
|
|
1433 |
|
|
|
1434 |
#設置執行錯誤的識別
|
|
|
1435 |
$result["status"]="false";
|
|
|
1436 |
|
|
|
1437 |
#設置錯誤訊息
|
|
|
1438 |
$result["error"]=$checkResult;
|
|
|
1439 |
|
|
|
1440 |
#回傳結果
|
|
|
1441 |
return $result;
|
|
|
1442 |
|
|
|
1443 |
}#if end
|
|
|
1444 |
|
|
|
1445 |
#依據每個要檢查的可省略變數key
|
|
|
1446 |
for($i=0;$i<count($conf["sikpableVarNameArray"]);$i++){
|
|
|
1447 |
|
|
|
1448 |
#如果 $conf["checkedVar"][$conf["sikpableVarNameArray"][$i]] 有設定
|
|
|
1449 |
if(isset($conf["checkedVar"][$conf["sikpableVarNameArray"][$i]])){
|
|
|
1450 |
|
|
|
1451 |
#如果有設定 $conf["skipableVarTypeArray"][$i]
|
|
|
1452 |
if(isset($conf["skipableVarTypeArray"][$i])){
|
|
|
1453 |
|
|
|
1454 |
#如果 $conf["checkedVar"][$conf["sikpableVarNameArray"][$i]] 的型態不等於 $conf["sikpableVarTypeArray"][$i] 且 $conf["skipableVarTypeArray"][$i] 不為 null
|
|
|
1455 |
if(gettype($conf["checkedVar"][$conf["sikpableVarNameArray"][$i]])!=$conf["skipableVarTypeArray"][$i] && $conf["skipableVarTypeArray"][$i]!=null){
|
|
|
1456 |
|
|
|
1457 |
#type "any" 不用檢查
|
|
|
1458 |
if($conf["skipableVarTypeArray"][$i]!=="any"){
|
|
|
1459 |
|
|
|
1460 |
#設置執行正常
|
|
|
1461 |
$result["status"]="true";
|
|
|
1462 |
|
|
|
1463 |
#設置執行錯誤識別
|
|
|
1464 |
$result["passed"]="false";
|
|
|
1465 |
|
|
|
1466 |
#設置錯誤訊息
|
|
|
1467 |
$result["error"][]=$conf["sikpableVarNameArray"][$i]."須為".$conf["skipableVarTypeArray"][$i]."型態";
|
|
|
1468 |
|
|
|
1469 |
#回傳結果
|
|
|
1470 |
return $result;
|
|
|
1471 |
|
|
|
1472 |
}#if end
|
|
|
1473 |
|
|
|
1474 |
}#if end
|
|
|
1475 |
|
|
|
1476 |
}#if end
|
|
|
1477 |
|
|
|
1478 |
}#if end
|
|
|
1479 |
|
|
|
1480 |
#反之該變數不存在
|
|
|
1481 |
else{
|
|
|
1482 |
|
|
|
1483 |
#如果 $conf["skipableVarDefaultValue"] 有設置
|
|
|
1484 |
if(isset($conf["skipableVarDefaultValue"])){
|
|
|
1485 |
|
|
|
1486 |
#如果 $conf["skipableVarDefaultValue"] 為 "array"
|
|
|
1487 |
if(gettype($conf["skipableVarDefaultValue"])=="array"){
|
|
|
1488 |
|
|
|
1489 |
#如果 $conf["skipableVarDefaultValue"][$i] 完全不等於 null
|
|
|
1490 |
if($conf["skipableVarDefaultValue"][$i]!==null){
|
|
|
1491 |
|
|
|
1492 |
#初始化該變數內容
|
|
|
1493 |
$argu[$conf["sikpableVarNameArray"][$i]]=$conf["skipableVarDefaultValue"][$i];
|
|
|
1494 |
|
|
|
1495 |
}#if end
|
|
|
1496 |
|
|
|
1497 |
}#if end
|
|
|
1498 |
|
|
|
1499 |
}#if end
|
|
|
1500 |
|
|
|
1501 |
}#else end
|
|
|
1502 |
|
|
|
1503 |
}#for end
|
|
|
1504 |
|
|
|
1505 |
#設置執行正常
|
|
|
1506 |
$result["status"]="true";
|
|
|
1507 |
|
|
|
1508 |
#執行到這邊代表檢查通過
|
|
|
1509 |
$result["passed"]="true";
|
|
|
1510 |
|
|
|
1511 |
#回傳結果
|
|
|
1512 |
return $result;
|
|
|
1513 |
|
|
|
1514 |
}#funciton checkSkipableVarType end
|
|
|
1515 |
|
|
|
1516 |
/*
|
|
|
1517 |
#函式說明:
|
|
|
1518 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
1519 |
#回傳結果:
|
|
|
1520 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1521 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
1522 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
1523 |
#$result["function"],當前執行的函式名稱.
|
|
|
1524 |
#$result["argu"],設置給予的參數.
|
|
|
1525 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1526 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1527 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1528 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1529 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1530 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1531 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1532 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1533 |
#必填參數:
|
|
|
1534 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1535 |
$conf["varInput"]=&$conf;
|
|
|
1536 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1537 |
$conf["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1538 |
#可省略參數:
|
|
|
1539 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1540 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
1541 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
1542 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
1543 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1544 |
#$conf["canBeEmptyString"]="false";
|
|
|
1545 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1546 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1547 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1548 |
#$conf["canBeEmpty"]=array();
|
|
|
1549 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1550 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1551 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1552 |
#$conf["skipableVariableName"]=array();
|
|
|
1553 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1554 |
#$conf["skipableVariableType"]=array();
|
|
|
1555 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1556 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1557 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1558 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1559 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1560 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1561 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
1562 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
1563 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1564 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1565 |
#參考資料:
|
|
|
1566 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1567 |
#備註:
|
|
|
1568 |
#無.
|
|
|
1569 |
*/
|
|
|
1570 |
public static function checkArguments(&$conf){
|
|
|
1571 |
|
|
|
1572 |
#初始化要回傳的結果
|
|
|
1573 |
$result=array();
|
|
|
1574 |
|
|
|
1575 |
#設置當其函數名稱
|
|
|
1576 |
$result["function"]=__FUNCTION__;
|
|
|
1577 |
|
|
|
1578 |
#如果 $conf 不為陣列
|
|
|
1579 |
if(gettype($conf)!="array"){
|
|
|
1580 |
|
|
|
1581 |
#設置執行失敗
|
|
|
1582 |
$result["status"]="false";
|
|
|
1583 |
|
|
|
1584 |
#設置執行錯誤訊息
|
|
|
1585 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1586 |
|
|
|
1587 |
#如果傳入的參數為 null
|
| 182 |
liveuser |
1588 |
if($conf===null){
|
| 3 |
liveuser |
1589 |
|
|
|
1590 |
#設置執行錯誤訊息
|
|
|
1591 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1592 |
|
|
|
1593 |
}#if end
|
|
|
1594 |
|
|
|
1595 |
#函式說明:
|
|
|
1596 |
#取得簡單的錯誤訊息
|
|
|
1597 |
#回傳結果:
|
|
|
1598 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1599 |
#$result["content"],結果.
|
|
|
1600 |
#$result["function"],當前執行的函數
|
|
|
1601 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1602 |
#必填參數:
|
|
|
1603 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1604 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1605 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1606 |
#可省略參數:
|
|
|
1607 |
#無
|
|
|
1608 |
#參考資料:
|
|
|
1609 |
#無.
|
|
|
1610 |
#備註:
|
|
|
1611 |
#無.
|
|
|
1612 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1613 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1614 |
|
|
|
1615 |
#如果執行失敗
|
|
|
1616 |
if($getSimpleError["status"]==="false"){
|
|
|
1617 |
|
|
|
1618 |
#設置執行錯誤訊息
|
|
|
1619 |
$result["error"][]=$getSimpleError;
|
|
|
1620 |
|
|
|
1621 |
#回傳結果
|
|
|
1622 |
return $result;
|
|
|
1623 |
|
|
|
1624 |
}#if end
|
|
|
1625 |
|
|
|
1626 |
#設置 $simpleError
|
|
|
1627 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1628 |
|
|
|
1629 |
#回傳結果
|
|
|
1630 |
return $result;
|
|
|
1631 |
|
|
|
1632 |
}#if end
|
|
|
1633 |
|
|
|
1634 |
#設置放置的參數
|
|
|
1635 |
$result["argu"]=$conf;
|
|
|
1636 |
|
|
|
1637 |
#檢查必填參數
|
|
|
1638 |
#函式說明:
|
|
|
1639 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1640 |
#回傳結果:
|
|
|
1641 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1642 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1643 |
#$result["function"],當前執行的函式名稱.
|
|
|
1644 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1645 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1646 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1647 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1648 |
#必填參數:
|
|
|
1649 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1650 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("varInput","referenceVarKey");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1651 |
#可省略參數:
|
|
|
1652 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1653 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="true";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1654 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1655 |
#$conf["variableCheck.isexistMulti"]["canNotBeEmpty"]=array();
|
|
|
1656 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1657 |
#$conf["variableCheck.isexistMulti"]["canBeEmpty"]=array();
|
|
|
1658 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
1659 |
unset($conf["variableCheck.isexistMulti"]);
|
|
|
1660 |
|
|
|
1661 |
#如果檢查失敗
|
|
|
1662 |
if($checkResult["status"]==="false"){
|
|
|
1663 |
|
|
|
1664 |
#設置錯誤識別
|
|
|
1665 |
$result["status"]="false";
|
|
|
1666 |
|
|
|
1667 |
#設置錯誤訊息
|
|
|
1668 |
$result["error"]=$checkResult;
|
|
|
1669 |
|
|
|
1670 |
#函式說明:
|
|
|
1671 |
#取得簡單的錯誤訊息
|
|
|
1672 |
#回傳結果:
|
|
|
1673 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1674 |
#$result["content"],結果.
|
|
|
1675 |
#$result["function"],當前執行的函數
|
|
|
1676 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1677 |
#必填參數:
|
|
|
1678 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1679 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1680 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1681 |
#可省略參數:
|
|
|
1682 |
#無
|
|
|
1683 |
#參考資料:
|
|
|
1684 |
#無.
|
|
|
1685 |
#備註:
|
|
|
1686 |
#無.
|
|
|
1687 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1688 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1689 |
|
|
|
1690 |
#如果執行失敗
|
|
|
1691 |
if($getSimpleError["status"]==="false"){
|
|
|
1692 |
|
|
|
1693 |
#設置執行錯誤訊息
|
|
|
1694 |
$result["error"][]=$getSimpleError;
|
|
|
1695 |
|
|
|
1696 |
#回傳結果
|
|
|
1697 |
return $result;
|
|
|
1698 |
|
|
|
1699 |
}#if end
|
|
|
1700 |
|
|
|
1701 |
#設置 $simpleError
|
|
|
1702 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1703 |
|
|
|
1704 |
#回傳結果
|
|
|
1705 |
return $result;
|
|
|
1706 |
|
|
|
1707 |
}#if end
|
|
|
1708 |
|
|
|
1709 |
#如果檢查不通過
|
|
|
1710 |
if($checkResult["passed"]==="false"){
|
|
|
1711 |
|
|
|
1712 |
#設置執正常
|
|
|
1713 |
$result["status"]="true";
|
|
|
1714 |
|
|
|
1715 |
#設置錯誤識別
|
|
|
1716 |
$result["passed"]="false";
|
|
|
1717 |
|
|
|
1718 |
#設置錯誤訊息
|
|
|
1719 |
$result["error"]=$checkResult;
|
|
|
1720 |
|
|
|
1721 |
#函式說明:
|
|
|
1722 |
#取得簡單的錯誤訊息
|
|
|
1723 |
#回傳結果:
|
|
|
1724 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1725 |
#$result["content"],結果.
|
|
|
1726 |
#$result["function"],當前執行的函數
|
|
|
1727 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1728 |
#必填參數:
|
|
|
1729 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1730 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1731 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1732 |
#可省略參數:
|
|
|
1733 |
#無
|
|
|
1734 |
#參考資料:
|
|
|
1735 |
#無.
|
|
|
1736 |
#備註:
|
|
|
1737 |
#無.
|
|
|
1738 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1739 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1740 |
|
|
|
1741 |
#如果執行失敗
|
|
|
1742 |
if($getSimpleError["status"]==="false"){
|
|
|
1743 |
|
|
|
1744 |
#設置執行錯誤訊息
|
|
|
1745 |
$result["error"][]=$getSimpleError;
|
|
|
1746 |
|
|
|
1747 |
#回傳結果
|
|
|
1748 |
return $result;
|
|
|
1749 |
|
|
|
1750 |
}#if end
|
|
|
1751 |
|
|
|
1752 |
#設置 $simpleError
|
|
|
1753 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1754 |
|
|
|
1755 |
#回傳結果
|
|
|
1756 |
return $result;
|
|
|
1757 |
|
|
|
1758 |
}#if end
|
|
|
1759 |
|
|
|
1760 |
#檢查可省略參數
|
|
|
1761 |
#函式說明:
|
|
|
1762 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
1763 |
#回傳結果:
|
|
|
1764 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1765 |
#$result["error"],錯誤訊息陣列.
|
|
|
1766 |
#$result["function"],當前執行的函式名稱.
|
|
|
1767 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
1768 |
#必填參數:
|
|
|
1769 |
#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
1770 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
1771 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
1772 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("mustBeFilledVariableName","mustBeFilledVariableType","canBeEmptyString","canNotBeEmpty","canBeEmpty","skipableVariableCanNotBeEmpty","skipableVariableName","skipableVariableType","skipableVarDefaultValue","arrayCountEqualCheck","disallowAllSkipableVarIsEmpty","disallowAllSkipableVarNotExist","disallowAllSkipableVarIsEmptyArray");
|
|
|
1773 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
1774 |
$argu=&$conf;
|
|
|
1775 |
#可省略參數:
|
|
|
1776 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
1777 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("array","array","string","array","array","array","array","array","array","array","string","string","string");
|
|
|
1778 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
1779 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array(null,null,"true",null,null,null,null,null,null,null,"false","false","false");
|
|
|
1780 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
1781 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
1782 |
|
|
|
1783 |
#如果檢查失敗
|
|
|
1784 |
if($checkResult["status"]=="false"){
|
|
|
1785 |
|
|
|
1786 |
#設置錯誤識別
|
|
|
1787 |
$result["status"]="false";
|
|
|
1788 |
|
|
|
1789 |
#設置錯誤訊息
|
|
|
1790 |
$result["error"]=$checkResult;
|
|
|
1791 |
|
|
|
1792 |
#函式說明:
|
|
|
1793 |
#取得簡單的錯誤訊息
|
|
|
1794 |
#回傳結果:
|
|
|
1795 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1796 |
#$result["content"],結果.
|
|
|
1797 |
#$result["function"],當前執行的函數
|
|
|
1798 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1799 |
#必填參數:
|
|
|
1800 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1801 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1802 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1803 |
#可省略參數:
|
|
|
1804 |
#無
|
|
|
1805 |
#參考資料:
|
|
|
1806 |
#無.
|
|
|
1807 |
#備註:
|
|
|
1808 |
#無.
|
|
|
1809 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1810 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1811 |
|
|
|
1812 |
#如果執行失敗
|
|
|
1813 |
if($getSimpleError["status"]==="false"){
|
|
|
1814 |
|
|
|
1815 |
#設置執行錯誤訊息
|
|
|
1816 |
$result["error"][]=$getSimpleError;
|
|
|
1817 |
|
|
|
1818 |
#回傳結果
|
|
|
1819 |
return $result;
|
|
|
1820 |
|
|
|
1821 |
}#if end
|
|
|
1822 |
|
|
|
1823 |
#設置 $simpleError
|
|
|
1824 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1825 |
|
|
|
1826 |
#回傳結果
|
|
|
1827 |
return $result;
|
|
|
1828 |
|
|
|
1829 |
}#if end
|
|
|
1830 |
|
|
|
1831 |
#如果檢查不通過
|
|
|
1832 |
if($checkResult["passed"]=="false"){
|
|
|
1833 |
|
|
|
1834 |
#設置執正常
|
|
|
1835 |
$result["status"]="true";
|
|
|
1836 |
|
|
|
1837 |
#設置錯誤識別
|
|
|
1838 |
$result["passed"]="false";
|
|
|
1839 |
|
|
|
1840 |
#設置錯誤訊息
|
|
|
1841 |
$result["error"]=$checkResult;
|
|
|
1842 |
|
|
|
1843 |
#函式說明:
|
|
|
1844 |
#取得簡單的錯誤訊息
|
|
|
1845 |
#回傳結果:
|
|
|
1846 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1847 |
#$result["content"],結果.
|
|
|
1848 |
#$result["function"],當前執行的函數
|
|
|
1849 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1850 |
#必填參數:
|
|
|
1851 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1852 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1853 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1854 |
#可省略參數:
|
|
|
1855 |
#無
|
|
|
1856 |
#參考資料:
|
|
|
1857 |
#無.
|
|
|
1858 |
#備註:
|
|
|
1859 |
#無.
|
|
|
1860 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1861 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1862 |
|
|
|
1863 |
#如果執行失敗
|
|
|
1864 |
if($getSimpleError["status"]==="false"){
|
|
|
1865 |
|
|
|
1866 |
#設置執行錯誤訊息
|
|
|
1867 |
$result["error"][]=$getSimpleError;
|
|
|
1868 |
|
|
|
1869 |
#回傳結果
|
|
|
1870 |
return $result;
|
|
|
1871 |
|
|
|
1872 |
}#if end
|
|
|
1873 |
|
|
|
1874 |
#設置 $simpleError
|
|
|
1875 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1876 |
|
|
|
1877 |
#回傳結果
|
|
|
1878 |
return $result;
|
|
|
1879 |
|
|
|
1880 |
}#if end
|
|
|
1881 |
|
|
|
1882 |
#如果有設置 $conf["mustBeFilledVariableName"] 跟 $conf["mustBeFilledVariableType"]
|
|
|
1883 |
if( isset($conf["mustBeFilledVariableName"])===true && isset($conf["mustBeFilledVariableType"])===true ){
|
|
|
1884 |
|
|
|
1885 |
#檢查輸入參數的數量是否不一致
|
|
|
1886 |
if(count($conf["mustBeFilledVariableName"])!==count($conf["mustBeFilledVariableType"])){
|
|
|
1887 |
|
|
|
1888 |
#設置錯誤識別
|
|
|
1889 |
$result["status"]="false";
|
|
|
1890 |
|
|
|
1891 |
#設置錯誤訊息
|
|
|
1892 |
$result["error"][]="參數 \"mustBeFilledVariableName\" 與 \"mustBeFilledVariableType\" 的數量要一致";
|
|
|
1893 |
|
|
|
1894 |
#函式說明:
|
|
|
1895 |
#取得簡單的錯誤訊息
|
|
|
1896 |
#回傳結果:
|
|
|
1897 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1898 |
#$result["content"],結果.
|
|
|
1899 |
#$result["function"],當前執行的函數
|
|
|
1900 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1901 |
#必填參數:
|
|
|
1902 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1903 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1904 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
1905 |
#可省略參數:
|
|
|
1906 |
#無
|
|
|
1907 |
#參考資料:
|
|
|
1908 |
#無.
|
|
|
1909 |
#備註:
|
|
|
1910 |
#無.
|
|
|
1911 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
1912 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
1913 |
|
|
|
1914 |
#如果執行失敗
|
|
|
1915 |
if($getSimpleError["status"]==="false"){
|
|
|
1916 |
|
|
|
1917 |
#設置執行錯誤訊息
|
|
|
1918 |
$result["error"][]=$getSimpleError;
|
|
|
1919 |
|
|
|
1920 |
#回傳結果
|
|
|
1921 |
return $result;
|
|
|
1922 |
|
|
|
1923 |
}#if end
|
|
|
1924 |
|
|
|
1925 |
#設置 $simpleError
|
|
|
1926 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
1927 |
|
|
|
1928 |
#回傳結果
|
|
|
1929 |
return $result;
|
|
|
1930 |
|
|
|
1931 |
}#if end
|
|
|
1932 |
|
|
|
1933 |
#函式說明:
|
|
|
1934 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1935 |
#回傳結果:
|
|
|
1936 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1937 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1938 |
#$result["function"],當前執行的函式名稱.
|
|
|
1939 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1940 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1941 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1942 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1943 |
#必填參數:
|
|
|
1944 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf["varInput"];#要檢查的陣列變數
|
|
|
1945 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=$conf["mustBeFilledVariableName"];#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1946 |
#可省略參數:
|
|
|
1947 |
$conf["variableCheck.isexistMulti"]["variableType"]=$conf["mustBeFilledVariableType"];#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
|
|
1948 |
#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1949 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]=$conf["canBeEmptyString"];
|
|
|
1950 |
|
|
|
1951 |
#如果設定必填參數可以為空字串或集合
|
|
|
1952 |
if($conf["canBeEmptyString"]=="true"){
|
|
|
1953 |
|
|
|
1954 |
#如果有設定要排除的不能為空字串或空集合的變數
|
|
|
1955 |
if(isset($conf["canNotBeEmpty"])){
|
|
|
1956 |
|
|
|
1957 |
#設定其參數
|
|
|
1958 |
$conf["variableCheck.isexistMulti"]["canNotBeEmpty"]=$conf["canNotBeEmpty"];
|
|
|
1959 |
|
|
|
1960 |
}#if end
|
|
|
1961 |
|
|
|
1962 |
}#if end
|
|
|
1963 |
|
|
|
1964 |
#如果設定必填參數不可以為空字串或集合
|
|
|
1965 |
else if($conf["canBeEmptyString"]=="false"){
|
|
|
1966 |
|
|
|
1967 |
#如果有設定要排除的不能為空字串或空集合的變數
|
|
|
1968 |
if(isset($conf["canBeEmpty"])){
|
|
|
1969 |
|
|
|
1970 |
#設定其參數
|
|
|
1971 |
$conf["variableCheck.isexistMulti"]["canBeEmpty"]=$conf["canBeEmpty"];
|
|
|
1972 |
|
|
|
1973 |
}#if end
|
|
|
1974 |
|
|
|
1975 |
}#if end
|
|
|
1976 |
|
|
|
1977 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
1978 |
unset($conf["variableCheck.isexistMulti"]);
|
|
|
1979 |
|
|
|
1980 |
#如果檢查失敗
|
|
|
1981 |
if($checkResult["status"]=="false"){
|
|
|
1982 |
|
|
|
1983 |
#設置錯誤識別
|
|
|
1984 |
$result["status"]="false";
|
|
|
1985 |
|
|
|
1986 |
#設置錯誤訊息
|
|
|
1987 |
$result["error"]=$checkResult;
|
|
|
1988 |
|
|
|
1989 |
#函式說明:
|
|
|
1990 |
#取得簡單的錯誤訊息
|
|
|
1991 |
#回傳結果:
|
|
|
1992 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1993 |
#$result["content"],結果.
|
|
|
1994 |
#$result["function"],當前執行的函數
|
|
|
1995 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
1996 |
#必填參數:
|
|
|
1997 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
1998 |
#$conf["error"],陣列,要處理的變數.
|
|
|
1999 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2000 |
#可省略參數:
|
|
|
2001 |
#無
|
|
|
2002 |
#參考資料:
|
|
|
2003 |
#無.
|
|
|
2004 |
#備註:
|
|
|
2005 |
#無.
|
|
|
2006 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2007 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2008 |
|
|
|
2009 |
#如果執行失敗
|
|
|
2010 |
if($getSimpleError["status"]==="false"){
|
|
|
2011 |
|
|
|
2012 |
#設置執行錯誤訊息
|
|
|
2013 |
$result["error"][]=$getSimpleError;
|
|
|
2014 |
|
|
|
2015 |
#回傳結果
|
|
|
2016 |
return $result;
|
|
|
2017 |
|
|
|
2018 |
}#if end
|
|
|
2019 |
|
|
|
2020 |
#設置 $simpleError
|
|
|
2021 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2022 |
|
|
|
2023 |
#回傳結果
|
|
|
2024 |
return $result;
|
|
|
2025 |
|
|
|
2026 |
}#if end
|
|
|
2027 |
|
|
|
2028 |
#如果檢查不通過
|
|
|
2029 |
if($checkResult["passed"]=="false"){
|
|
|
2030 |
|
|
|
2031 |
#設置執正常
|
|
|
2032 |
$result["status"]="true";
|
|
|
2033 |
|
|
|
2034 |
#設置錯誤識別
|
|
|
2035 |
$result["passed"]="false";
|
|
|
2036 |
|
|
|
2037 |
#設置錯誤訊息
|
|
|
2038 |
$result["error"]=$checkResult;
|
|
|
2039 |
|
|
|
2040 |
#函式說明:
|
|
|
2041 |
#取得簡單的錯誤訊息
|
|
|
2042 |
#回傳結果:
|
|
|
2043 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2044 |
#$result["content"],結果.
|
|
|
2045 |
#$result["function"],當前執行的函數
|
|
|
2046 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2047 |
#必填參數:
|
|
|
2048 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2049 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2050 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2051 |
#可省略參數:
|
|
|
2052 |
#無
|
|
|
2053 |
#參考資料:
|
|
|
2054 |
#無.
|
|
|
2055 |
#備註:
|
|
|
2056 |
#無.
|
|
|
2057 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2058 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2059 |
|
|
|
2060 |
#如果執行失敗
|
|
|
2061 |
if($getSimpleError["status"]==="false"){
|
|
|
2062 |
|
|
|
2063 |
#設置執行錯誤訊息
|
|
|
2064 |
$result["error"][]=$getSimpleError;
|
|
|
2065 |
|
|
|
2066 |
#回傳結果
|
|
|
2067 |
return $result;
|
|
|
2068 |
|
|
|
2069 |
}#if end
|
|
|
2070 |
|
|
|
2071 |
#設置 $simpleError
|
|
|
2072 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2073 |
|
|
|
2074 |
#回傳結果
|
|
|
2075 |
return $result;
|
|
|
2076 |
|
|
|
2077 |
}#if end
|
|
|
2078 |
|
|
|
2079 |
}#if end
|
|
|
2080 |
|
|
|
2081 |
#如果 $conf["skipableVariableName"] 與 $conf["skipableVariableType"] 存在
|
|
|
2082 |
if(isset($conf["skipableVariableName"]) && isset($conf["skipableVariableType"])){
|
|
|
2083 |
|
|
|
2084 |
#如果 $conf["skipableVariableName"] 與 $conf["skipableVariableType"] 的元素數量不一致
|
|
|
2085 |
if(count($conf["skipableVariableName"])!=count($conf["skipableVariableType"])){
|
|
|
2086 |
|
|
|
2087 |
#設置錯誤識別
|
|
|
2088 |
$result["status"]="false";
|
|
|
2089 |
|
|
|
2090 |
#設置錯誤識別
|
|
|
2091 |
$result["passed"]="false";
|
|
|
2092 |
|
|
|
2093 |
#設置錯誤訊息
|
|
|
2094 |
$result["error"][]="\$conf[\"skipableVariableName\"] 與 \$conf[\"skipableVariableType\"] 的元素數量不一致";
|
|
|
2095 |
|
|
|
2096 |
#函式說明:
|
|
|
2097 |
#取得簡單的錯誤訊息
|
|
|
2098 |
#回傳結果:
|
|
|
2099 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2100 |
#$result["content"],結果.
|
|
|
2101 |
#$result["function"],當前執行的函數
|
|
|
2102 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2103 |
#必填參數:
|
|
|
2104 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2105 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2106 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2107 |
#可省略參數:
|
|
|
2108 |
#無
|
|
|
2109 |
#參考資料:
|
|
|
2110 |
#無.
|
|
|
2111 |
#備註:
|
|
|
2112 |
#無.
|
|
|
2113 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2114 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2115 |
|
|
|
2116 |
#如果執行失敗
|
|
|
2117 |
if($getSimpleError["status"]==="false"){
|
|
|
2118 |
|
|
|
2119 |
#設置執行錯誤訊息
|
|
|
2120 |
$result["error"][]=$getSimpleError;
|
|
|
2121 |
|
|
|
2122 |
#回傳結果
|
|
|
2123 |
return $result;
|
|
|
2124 |
|
|
|
2125 |
}#if end
|
|
|
2126 |
|
|
|
2127 |
#設置 $simpleError
|
|
|
2128 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2129 |
|
|
|
2130 |
#回傳結果
|
|
|
2131 |
return $result;
|
|
|
2132 |
|
|
|
2133 |
}#if end
|
|
|
2134 |
|
|
|
2135 |
}#if end
|
|
|
2136 |
|
|
|
2137 |
#如果 $conf["skipableVariableName"] 有設置
|
|
|
2138 |
if(isset($conf["skipableVariableName"]) && isset($conf["skipableVarDefaultValue"])){
|
|
|
2139 |
|
|
|
2140 |
#如果 $conf["skipableVariableName"] 與 $conf["skipableVarDefaultValue"] 的元素數量不一致
|
|
|
2141 |
if(count($conf["skipableVariableName"])!=count($conf["skipableVarDefaultValue"])){
|
|
|
2142 |
|
|
|
2143 |
#設置執正常
|
|
|
2144 |
$result["status"]="true";
|
|
|
2145 |
|
|
|
2146 |
#設置錯誤識別
|
|
|
2147 |
$result["passed"]="false";
|
|
|
2148 |
|
|
|
2149 |
#設置錯誤訊息
|
|
|
2150 |
$result["error"][]="\$conf[\"skipableVariableName\"] 與 \$conf[\"skipableVarDefaultValue\"] 的元素數量不一致";
|
|
|
2151 |
|
|
|
2152 |
#函式說明:
|
|
|
2153 |
#取得簡單的錯誤訊息
|
|
|
2154 |
#回傳結果:
|
|
|
2155 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2156 |
#$result["content"],結果.
|
|
|
2157 |
#$result["function"],當前執行的函數
|
|
|
2158 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2159 |
#必填參數:
|
|
|
2160 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2161 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2162 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2163 |
#可省略參數:
|
|
|
2164 |
#無
|
|
|
2165 |
#參考資料:
|
|
|
2166 |
#無.
|
|
|
2167 |
#備註:
|
|
|
2168 |
#無.
|
|
|
2169 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2170 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2171 |
|
|
|
2172 |
#如果執行失敗
|
|
|
2173 |
if($getSimpleError["status"]==="false"){
|
|
|
2174 |
|
|
|
2175 |
#設置執行錯誤訊息
|
|
|
2176 |
$result["error"][]=$getSimpleError;
|
|
|
2177 |
|
|
|
2178 |
#回傳結果
|
|
|
2179 |
return $result;
|
|
|
2180 |
|
|
|
2181 |
}#if end
|
|
|
2182 |
|
|
|
2183 |
#設置 $simpleError
|
|
|
2184 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2185 |
|
|
|
2186 |
#回傳結果
|
|
|
2187 |
return $result;
|
|
|
2188 |
|
|
|
2189 |
}#if end
|
|
|
2190 |
|
|
|
2191 |
}#if end
|
|
|
2192 |
|
|
|
2193 |
#如果有可省略變數的型態限定
|
|
|
2194 |
if(isset($conf["skipableVariableType"])){
|
|
|
2195 |
|
|
|
2196 |
#如果可省略變數有 string 型別
|
|
|
2197 |
if(in_array("string",$conf["skipableVariableType"])){
|
|
|
2198 |
|
|
|
2199 |
#如果 $conf["disallowAllSkipableVarIsEmpty"] 設置為 "true"
|
|
|
2200 |
if($conf["disallowAllSkipableVarIsEmpty"]==="true"){
|
|
|
2201 |
|
|
|
2202 |
#設置檢查不通過
|
|
|
2203 |
$pass=false;
|
|
|
2204 |
|
|
|
2205 |
#如果沒有指定可省略參數
|
|
|
2206 |
if(!isset($conf["skipableVariableName"])){
|
|
|
2207 |
|
|
|
2208 |
#設置通過檢測
|
|
|
2209 |
$pass=true;
|
|
|
2210 |
|
|
|
2211 |
}#if end
|
|
|
2212 |
|
|
|
2213 |
#反之若可省略參數大於0
|
|
|
2214 |
else if(count($conf["skipableVariableName"])>0){
|
|
|
2215 |
|
|
|
2216 |
#設置是否有設置可省略變數
|
|
|
2217 |
$haveSkipVar=false;
|
|
|
2218 |
|
|
|
2219 |
#針對每個可省略的變數
|
|
|
2220 |
foreach($conf["skipableVariableName"] as $varKey=>$varName){
|
|
|
2221 |
|
|
|
2222 |
#如果該可省略變數有設置
|
|
|
2223 |
if(isset($conf["varInput"][$varName])){
|
|
|
2224 |
|
|
|
2225 |
#設置有設置可省略變數
|
|
|
2226 |
$haveSkipVar=true;
|
|
|
2227 |
|
|
|
2228 |
#如果是字串型態
|
|
|
2229 |
if(gettype($conf["varInput"][$varName])==="string"){
|
|
|
2230 |
|
|
|
2231 |
#如果是空字串
|
|
|
2232 |
if($conf["varInput"][$varName]!==""){
|
|
|
2233 |
|
|
|
2234 |
#設置通過檢測
|
|
|
2235 |
$pass=true;
|
|
|
2236 |
|
|
|
2237 |
#跳過檢查
|
|
|
2238 |
break;
|
|
|
2239 |
|
|
|
2240 |
}#if end
|
|
|
2241 |
|
|
|
2242 |
}#if end
|
|
|
2243 |
|
|
|
2244 |
}#if end
|
|
|
2245 |
|
|
|
2246 |
}#foreach end
|
|
|
2247 |
|
|
|
2248 |
#如果未設置可省略參數
|
|
|
2249 |
if(!$haveSkipVar){
|
|
|
2250 |
|
|
|
2251 |
#設置通過檢測
|
|
|
2252 |
$pass=true;
|
|
|
2253 |
|
|
|
2254 |
}#if end
|
|
|
2255 |
|
|
|
2256 |
}#if end
|
|
|
2257 |
|
|
|
2258 |
#反之
|
|
|
2259 |
else{
|
|
|
2260 |
|
|
|
2261 |
#設置通過檢測
|
|
|
2262 |
$pass=true;
|
|
|
2263 |
|
|
|
2264 |
}#else end
|
|
|
2265 |
|
|
|
2266 |
#如果檢查不通過
|
|
|
2267 |
if(!$pass){
|
|
|
2268 |
|
|
|
2269 |
#設置執行正常
|
|
|
2270 |
$result["status"]="true";
|
|
|
2271 |
|
|
|
2272 |
#設置檢查不通過
|
|
|
2273 |
$result["passed"]="false";
|
|
|
2274 |
|
|
|
2275 |
#設置錯誤訊息
|
|
|
2276 |
$result["warning"][]="可省略參數不都得為空字串";
|
|
|
2277 |
|
|
|
2278 |
#回傳結果
|
|
|
2279 |
return $result;
|
|
|
2280 |
|
|
|
2281 |
}#if end
|
|
|
2282 |
|
|
|
2283 |
}#if end
|
|
|
2284 |
|
|
|
2285 |
}#if end
|
|
|
2286 |
|
|
|
2287 |
#如果可省略變數有 array 型別
|
|
|
2288 |
if(in_array("array",$conf["skipableVariableType"])){
|
|
|
2289 |
|
|
|
2290 |
#如果 $conf["disallowAllSkipableVarIsEmptyArray"] 為 "true"
|
|
|
2291 |
if($conf["disallowAllSkipableVarIsEmptyArray"]==="true"){
|
|
|
2292 |
|
|
|
2293 |
#設置檢查不通過
|
|
|
2294 |
$pass=false;
|
|
|
2295 |
|
|
|
2296 |
#如果沒有指定可省略參數
|
|
|
2297 |
if(!isset($conf["skipableVariableName"])){
|
|
|
2298 |
|
|
|
2299 |
#設置通過檢測
|
|
|
2300 |
$pass=true;
|
|
|
2301 |
|
|
|
2302 |
}#if end
|
|
|
2303 |
|
|
|
2304 |
#反之若可省略參數大於0
|
|
|
2305 |
else if(count($conf["skipableVariableName"])>0){
|
|
|
2306 |
|
|
|
2307 |
#針對每個可省略的變數
|
|
|
2308 |
foreach($conf["skipableVariableName"] as $varKey=>$varName){
|
|
|
2309 |
|
|
|
2310 |
#如果該可省略變數有設置
|
|
|
2311 |
if(isset($conf["varInput"][$varName])){
|
|
|
2312 |
|
|
|
2313 |
#如果是陣列型態
|
|
|
2314 |
if(gettype($conf["varInput"][$varName])==="array"){
|
|
|
2315 |
|
|
|
2316 |
#函式說明:
|
|
|
2317 |
#檢查一陣列變數是否為空陣列
|
|
|
2318 |
#回傳結果:
|
|
|
2319 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2320 |
#$result["content"],css動畫設定的語法
|
|
|
2321 |
#$result["function"],當前執行的函數
|
|
|
2322 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2323 |
#$result["empty"],"true"代表為空陣列,"false"代表不為空陣列.
|
|
|
2324 |
#必填參數:
|
|
|
2325 |
#$conf["var"],陣列變數.
|
|
|
2326 |
$conf["variableCheck::emptyArray"]["var"]=$conf["varInput"][$varName];
|
|
|
2327 |
#備註:
|
|
|
2328 |
#無
|
|
|
2329 |
$emptyArray=variableCheck::emptyArray($conf["variableCheck::emptyArray"]);
|
|
|
2330 |
unset($conf["variableCheck::emptyArray"]);
|
|
|
2331 |
|
|
|
2332 |
#如果檢查失敗
|
|
|
2333 |
if($emptyArray["status"]==="false"){
|
|
|
2334 |
|
|
|
2335 |
#設置執行失敗
|
|
|
2336 |
$result["status"]="false";
|
|
|
2337 |
|
|
|
2338 |
#設置錯誤訊息
|
|
|
2339 |
$result["error"]=$emptyArray;
|
|
|
2340 |
|
|
|
2341 |
#函式說明:
|
|
|
2342 |
#取得簡單的錯誤訊息
|
|
|
2343 |
#回傳結果:
|
|
|
2344 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2345 |
#$result["content"],結果.
|
|
|
2346 |
#$result["function"],當前執行的函數
|
|
|
2347 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2348 |
#必填參數:
|
|
|
2349 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2350 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2351 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2352 |
#可省略參數:
|
|
|
2353 |
#無
|
|
|
2354 |
#參考資料:
|
|
|
2355 |
#無.
|
|
|
2356 |
#備註:
|
|
|
2357 |
#無.
|
|
|
2358 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2359 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2360 |
|
|
|
2361 |
#如果執行失敗
|
|
|
2362 |
if($getSimpleError["status"]==="false"){
|
|
|
2363 |
|
|
|
2364 |
#設置執行錯誤訊息
|
|
|
2365 |
$result["error"][]=$getSimpleError;
|
|
|
2366 |
|
|
|
2367 |
#回傳結果
|
|
|
2368 |
return $result;
|
|
|
2369 |
|
|
|
2370 |
}#if end
|
|
|
2371 |
|
|
|
2372 |
#設置 $simpleError
|
|
|
2373 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2374 |
|
|
|
2375 |
#回傳結果
|
|
|
2376 |
return $result;
|
|
|
2377 |
|
|
|
2378 |
}#if end
|
|
|
2379 |
|
|
|
2380 |
#如果不是空陣列
|
|
|
2381 |
if($emptyArray["empty"]==="false"){
|
|
|
2382 |
|
|
|
2383 |
#設置通過檢測
|
|
|
2384 |
$pass=true;
|
|
|
2385 |
|
|
|
2386 |
#跳過檢查
|
|
|
2387 |
break;
|
|
|
2388 |
|
|
|
2389 |
}#if end
|
|
|
2390 |
|
|
|
2391 |
}#if end
|
|
|
2392 |
|
|
|
2393 |
}#if end
|
|
|
2394 |
|
|
|
2395 |
}#foreach end
|
|
|
2396 |
|
|
|
2397 |
}#if end
|
|
|
2398 |
|
|
|
2399 |
#反之
|
|
|
2400 |
else{
|
|
|
2401 |
|
|
|
2402 |
#設置通過檢測
|
|
|
2403 |
$pass=true;
|
|
|
2404 |
|
|
|
2405 |
}#else end
|
|
|
2406 |
|
|
|
2407 |
#如果檢查不通過
|
|
|
2408 |
if(!$pass){
|
|
|
2409 |
|
|
|
2410 |
#設置執行正常
|
|
|
2411 |
$result["status"]="true";
|
|
|
2412 |
|
|
|
2413 |
#設置檢查不通過
|
|
|
2414 |
$result["passed"]="false";
|
|
|
2415 |
|
|
|
2416 |
#設置錯誤訊息
|
|
|
2417 |
$result["warning"][]="可省略參數不都得為空陣列";
|
|
|
2418 |
|
|
|
2419 |
#回傳結果
|
|
|
2420 |
return $result;
|
|
|
2421 |
|
|
|
2422 |
}#if end
|
|
|
2423 |
|
|
|
2424 |
}#if end
|
|
|
2425 |
|
|
|
2426 |
}#else end
|
|
|
2427 |
|
|
|
2428 |
#如果可省略變數有 any 型別
|
|
|
2429 |
if(in_array("any",$conf["skipableVariableType"])){
|
|
|
2430 |
|
|
|
2431 |
#儲存可以為任意形態的變數
|
|
|
2432 |
$anyTypeVarName=array();
|
|
|
2433 |
|
|
|
2434 |
#針對每個可省略參數的形態
|
|
|
2435 |
foreach($conf["skipableVariableType"] as $varKey=>$varType){
|
|
|
2436 |
|
|
|
2437 |
#如果找到形態為any的變數形態
|
|
|
2438 |
if($varType==="any"){
|
|
|
2439 |
|
|
|
2440 |
#儲存形態為 any 的可省略變數名稱
|
|
|
2441 |
$anyTypeVarName[]=$conf["skipableVariableName"][$varKey];
|
|
|
2442 |
|
|
|
2443 |
}#if end
|
|
|
2444 |
|
|
|
2445 |
}#foreach end
|
|
|
2446 |
|
|
|
2447 |
#針對每個 any type 的可省略變數名稱
|
|
|
2448 |
foreach($anyTypeVarName as $varName){
|
|
|
2449 |
|
|
|
2450 |
#如果該可省略變數存在
|
|
|
2451 |
if(isset($conf["varInput"][$varName])){
|
|
|
2452 |
|
|
|
2453 |
#取得變數的形態
|
|
|
2454 |
$varType=gettype($conf["varInput"][$varName]);
|
|
|
2455 |
|
|
|
2456 |
#判斷變數的形態
|
|
|
2457 |
switch($varType){
|
|
|
2458 |
|
|
|
2459 |
#如果是字串
|
|
|
2460 |
case "string":
|
|
|
2461 |
|
|
|
2462 |
#如果 $conf["disallowAllSkipableVarIsEmpty"] 設置為 "true"
|
|
|
2463 |
if($conf["disallowAllSkipableVarIsEmpty"]==="true"){
|
|
|
2464 |
|
|
|
2465 |
#如果該變數是不被允許的空字串
|
|
|
2466 |
if($conf["varInput"][$varName]===""){
|
|
|
2467 |
|
|
|
2468 |
#設置執行正常
|
|
|
2469 |
$result["status"]="true";
|
|
|
2470 |
|
|
|
2471 |
#設置檢查不通過
|
|
|
2472 |
$result["passed"]="false";
|
|
|
2473 |
|
|
|
2474 |
#設置錯誤訊息
|
|
|
2475 |
$result["warning"][]="可省略參數".$varName."不都得為空陣列";
|
|
|
2476 |
|
|
|
2477 |
#回傳結果
|
|
|
2478 |
return $result;
|
|
|
2479 |
|
|
|
2480 |
}#if end
|
|
|
2481 |
|
|
|
2482 |
}#if end
|
|
|
2483 |
|
|
|
2484 |
#跳出switch
|
|
|
2485 |
break;
|
|
|
2486 |
|
|
|
2487 |
#如果是陣列
|
|
|
2488 |
case "array":
|
|
|
2489 |
|
|
|
2490 |
#如果 $conf["disallowAllSkipableVarIsEmptyArray"] 為 "true"
|
|
|
2491 |
if($conf["disallowAllSkipableVarIsEmptyArray"]==="true"){
|
|
|
2492 |
|
|
|
2493 |
#如果該變數是不被允許的空陣列
|
|
|
2494 |
if($conf["varInput"][$varName]===array()){
|
|
|
2495 |
|
|
|
2496 |
#設置執行正常
|
|
|
2497 |
$result["status"]="true";
|
|
|
2498 |
|
|
|
2499 |
#設置檢查不通過
|
|
|
2500 |
$result["passed"]="false";
|
|
|
2501 |
|
|
|
2502 |
#設置錯誤訊息
|
|
|
2503 |
$result["warning"][]="可省略參數".$varName."不都得為空陣列";
|
|
|
2504 |
|
|
|
2505 |
#回傳結果
|
|
|
2506 |
return $result;
|
|
|
2507 |
|
|
|
2508 |
}#if end
|
|
|
2509 |
|
|
|
2510 |
}#if end
|
|
|
2511 |
|
|
|
2512 |
#跳出switch
|
|
|
2513 |
break;
|
|
|
2514 |
|
|
|
2515 |
default:
|
|
|
2516 |
|
|
|
2517 |
}#switch end
|
|
|
2518 |
|
|
|
2519 |
}#if end
|
|
|
2520 |
|
|
|
2521 |
}#foreach end
|
|
|
2522 |
|
|
|
2523 |
}#if end
|
|
|
2524 |
|
|
|
2525 |
}#if end
|
|
|
2526 |
|
|
|
2527 |
#如果 $conf["skipableVarDefaultValue"] 有設置
|
|
|
2528 |
if(isset($conf["skipableVarDefaultValue"])){
|
|
|
2529 |
|
|
|
2530 |
#檢查 $conf["skipableVariableName"] 陣列中的每個可省略變數名稱
|
|
|
2531 |
for($i=0;$i<count($conf["skipableVariableName"]);$i++){
|
|
|
2532 |
|
|
|
2533 |
#如果 $conf["skipableVarDefaultValue"] 有設置
|
|
|
2534 |
if(isset($conf["skipableVarDefaultValue"])){
|
|
|
2535 |
|
|
|
2536 |
#如果 $conf["skipableVarDefaultValue"][$i] 為字串且不為空字串
|
|
|
2537 |
if(gettype($conf["skipableVarDefaultValue"][$i])==="string" && $conf["skipableVarDefaultValue"][$i]!=""){
|
|
|
2538 |
|
|
|
2539 |
#尋找有無$開頭的字串
|
|
|
2540 |
#函式說明:
|
|
|
2541 |
#取得字首一樣的字串,並回傳其字串。
|
|
|
2542 |
#回傳結果:
|
|
|
2543 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
2544 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
2545 |
#$result["function"],當前執行的函數名稱.
|
|
|
2546 |
#$result["error"],錯誤訊息陣列.
|
|
|
2547 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
2548 |
#必填參數:
|
|
|
2549 |
$conf["search.getMeetConditionsString"]["checkString"]=$conf["skipableVarDefaultValue"][$i];#要檢查的字串
|
|
|
2550 |
$conf["search.getMeetConditionsString"]["frontWord"]="\$";#用來檢查字首應該要有什麼字串
|
|
|
2551 |
#用到的涵式:
|
|
|
2552 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
2553 |
$isVariable=search::getMeetConditionsString($conf["search.getMeetConditionsString"]);
|
|
|
2554 |
unset($conf["search.getMeetConditionsString"]);
|
|
|
2555 |
|
|
|
2556 |
#如果尋找失敗
|
|
|
2557 |
if($isVariable["status"]=="false"){
|
|
|
2558 |
|
|
|
2559 |
#設置錯誤識別
|
|
|
2560 |
$result["status"]="false";
|
|
|
2561 |
|
|
|
2562 |
#設置錯誤訊息
|
|
|
2563 |
$result["error"]=$isVariable;
|
|
|
2564 |
|
|
|
2565 |
#函式說明:
|
|
|
2566 |
#取得簡單的錯誤訊息
|
|
|
2567 |
#回傳結果:
|
|
|
2568 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2569 |
#$result["content"],結果.
|
|
|
2570 |
#$result["function"],當前執行的函數
|
|
|
2571 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2572 |
#必填參數:
|
|
|
2573 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2574 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2575 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2576 |
#可省略參數:
|
|
|
2577 |
#無
|
|
|
2578 |
#參考資料:
|
|
|
2579 |
#無.
|
|
|
2580 |
#備註:
|
|
|
2581 |
#無.
|
|
|
2582 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2583 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2584 |
|
|
|
2585 |
#如果執行失敗
|
|
|
2586 |
if($getSimpleError["status"]==="false"){
|
|
|
2587 |
|
|
|
2588 |
#設置執行錯誤訊息
|
|
|
2589 |
$result["error"][]=$getSimpleError;
|
|
|
2590 |
|
|
|
2591 |
#回傳結果
|
|
|
2592 |
return $result;
|
|
|
2593 |
|
|
|
2594 |
}#if end
|
|
|
2595 |
|
|
|
2596 |
#設置 $simpleError
|
|
|
2597 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2598 |
|
|
|
2599 |
#回傳結果
|
|
|
2600 |
return $result;
|
|
|
2601 |
|
|
|
2602 |
}#if end
|
|
|
2603 |
|
|
|
2604 |
#如果含有 "\$" 開頭
|
|
|
2605 |
if($isVariable["founded"]=="true"){
|
|
|
2606 |
|
|
|
2607 |
#用 " 分割含有 $ 的字串,取得中間那一段
|
|
|
2608 |
#函式說明:
|
|
|
2609 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2610 |
#回傳的參數:
|
|
|
2611 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2612 |
#$result["error"],錯誤訊息陣列
|
|
|
2613 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2614 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2615 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2616 |
#必填參數:
|
|
|
2617 |
$conf["stringProcess.spiltString"]["stringIn"]=$isVariable["returnString"];#要處理的字串。
|
|
|
2618 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="\"";#爲以哪個符號作爲分割
|
|
|
2619 |
#備註:
|
|
|
2620 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
2621 |
$spiltedStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
2622 |
unset($conf["stringProcess.spiltString"]);
|
|
|
2623 |
|
|
|
2624 |
#如果分割失敗
|
|
|
2625 |
if($spiltedStr["status"]=="false"){
|
|
|
2626 |
|
|
|
2627 |
#設置錯誤識別
|
|
|
2628 |
$result["status"]="false";
|
|
|
2629 |
|
|
|
2630 |
#設置錯誤訊息
|
|
|
2631 |
$result["error"]=$spiltedStr;
|
|
|
2632 |
|
|
|
2633 |
#函式說明:
|
|
|
2634 |
#取得簡單的錯誤訊息
|
|
|
2635 |
#回傳結果:
|
|
|
2636 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2637 |
#$result["content"],結果.
|
|
|
2638 |
#$result["function"],當前執行的函數
|
|
|
2639 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2640 |
#必填參數:
|
|
|
2641 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2642 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2643 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2644 |
#可省略參數:
|
|
|
2645 |
#無
|
|
|
2646 |
#參考資料:
|
|
|
2647 |
#無.
|
|
|
2648 |
#備註:
|
|
|
2649 |
#無.
|
|
|
2650 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2651 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2652 |
|
|
|
2653 |
#如果執行失敗
|
|
|
2654 |
if($getSimpleError["status"]==="false"){
|
|
|
2655 |
|
|
|
2656 |
#設置執行錯誤訊息
|
|
|
2657 |
$result["error"][]=$getSimpleError;
|
|
|
2658 |
|
|
|
2659 |
#回傳結果
|
|
|
2660 |
return $result;
|
|
|
2661 |
|
|
|
2662 |
}#if end
|
|
|
2663 |
|
|
|
2664 |
#設置 $simpleError
|
|
|
2665 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2666 |
|
|
|
2667 |
#回傳結果
|
|
|
2668 |
return $result;
|
|
|
2669 |
|
|
|
2670 |
}#if end
|
|
|
2671 |
|
|
|
2672 |
#如果分割出來沒有大於等於三段
|
|
|
2673 |
if($spiltedStr["dataCounts"]<3){
|
|
|
2674 |
|
|
|
2675 |
#設置錯誤識別
|
|
|
2676 |
$result["status"]="false";
|
|
|
2677 |
|
|
|
2678 |
#設置錯誤訊息
|
|
|
2679 |
$result["error"]=$spiltedStr;
|
|
|
2680 |
|
|
|
2681 |
#函式說明:
|
|
|
2682 |
#取得簡單的錯誤訊息
|
|
|
2683 |
#回傳結果:
|
|
|
2684 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2685 |
#$result["content"],結果.
|
|
|
2686 |
#$result["function"],當前執行的函數
|
|
|
2687 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2688 |
#必填參數:
|
|
|
2689 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2690 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2691 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2692 |
#可省略參數:
|
|
|
2693 |
#無
|
|
|
2694 |
#參考資料:
|
|
|
2695 |
#無.
|
|
|
2696 |
#備註:
|
|
|
2697 |
#無.
|
|
|
2698 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2699 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2700 |
|
|
|
2701 |
#如果執行失敗
|
|
|
2702 |
if($getSimpleError["status"]==="false"){
|
|
|
2703 |
|
|
|
2704 |
#設置執行錯誤訊息
|
|
|
2705 |
$result["error"][]=$getSimpleError;
|
|
|
2706 |
|
|
|
2707 |
#回傳結果
|
|
|
2708 |
return $result;
|
|
|
2709 |
|
|
|
2710 |
}#if end
|
|
|
2711 |
|
|
|
2712 |
#設置 $simpleError
|
|
|
2713 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2714 |
|
|
|
2715 |
#回傳結果
|
|
|
2716 |
return $result;
|
|
|
2717 |
|
|
|
2718 |
}#if end
|
|
|
2719 |
|
|
|
2720 |
#函式說明:
|
|
|
2721 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2722 |
#回傳結果:
|
|
|
2723 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2724 |
#$result["error"],錯誤訊息陣列.
|
|
|
2725 |
#$result["function"],當前執行的函式名稱.
|
|
|
2726 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2727 |
#必填參數:
|
|
|
2728 |
#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2729 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf["varInput"];
|
|
|
2730 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2731 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array($conf["skipableVariableName"][$i]);
|
|
|
2732 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
2733 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array($conf["skipableVariableType"][$i]);
|
|
|
2734 |
|
|
|
2735 |
#如果要採用的預設值變數存在
|
|
|
2736 |
if(isset($conf["varInput"][$spiltedStr["dataArray"][1]])){
|
|
|
2737 |
|
|
|
2738 |
#代表該元素的預設值為在檢查參數時自動產生的,因此要透過動態變數取得預設值
|
|
|
2739 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array($conf["varInput"][$spiltedStr["dataArray"][1]]);
|
|
|
2740 |
|
|
|
2741 |
#如果變數後面需要串接內容
|
|
|
2742 |
if(isset($spiltedStr["dataArray"][3])){
|
|
|
2743 |
|
|
|
2744 |
#串接後面的內容
|
|
|
2745 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][0]=$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"][0].$spiltedStr["dataArray"][3];
|
|
|
2746 |
|
|
|
2747 |
}#if end
|
|
|
2748 |
|
|
|
2749 |
}#if end
|
|
|
2750 |
|
|
|
2751 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
2752 |
$argu=&$conf["varInput"];
|
|
|
2753 |
#可省略參數:
|
|
|
2754 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
2755 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
2756 |
|
|
|
2757 |
#如果檢查失敗
|
|
|
2758 |
if($checkResult["status"]=="false"){
|
|
|
2759 |
|
|
|
2760 |
#設置錯誤識別
|
|
|
2761 |
$result["status"]="false";
|
|
|
2762 |
|
|
|
2763 |
#設置錯誤訊息
|
|
|
2764 |
$result["error"]=$checkResult;
|
|
|
2765 |
|
|
|
2766 |
#函式說明:
|
|
|
2767 |
#取得簡單的錯誤訊息
|
|
|
2768 |
#回傳結果:
|
|
|
2769 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2770 |
#$result["content"],結果.
|
|
|
2771 |
#$result["function"],當前執行的函數
|
|
|
2772 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2773 |
#必填參數:
|
|
|
2774 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2775 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2776 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2777 |
#可省略參數:
|
|
|
2778 |
#無
|
|
|
2779 |
#參考資料:
|
|
|
2780 |
#無.
|
|
|
2781 |
#備註:
|
|
|
2782 |
#無.
|
|
|
2783 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2784 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2785 |
|
|
|
2786 |
#如果執行失敗
|
|
|
2787 |
if($getSimpleError["status"]==="false"){
|
|
|
2788 |
|
|
|
2789 |
#設置執行錯誤訊息
|
|
|
2790 |
$result["error"][]=$getSimpleError;
|
|
|
2791 |
|
|
|
2792 |
#回傳結果
|
|
|
2793 |
return $result;
|
|
|
2794 |
|
|
|
2795 |
}#if end
|
|
|
2796 |
|
|
|
2797 |
#設置 $simpleError
|
|
|
2798 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2799 |
|
|
|
2800 |
#回傳結果
|
|
|
2801 |
return $result;
|
|
|
2802 |
|
|
|
2803 |
}#if end
|
|
|
2804 |
|
|
|
2805 |
#如果檢查不通過
|
|
|
2806 |
if($checkResult["passed"]=="false"){
|
|
|
2807 |
|
|
|
2808 |
#設置錯誤識別
|
|
|
2809 |
$result["status"]="true";
|
|
|
2810 |
|
|
|
2811 |
#設置錯誤識別
|
|
|
2812 |
$result["passed"]="false";
|
|
|
2813 |
|
|
|
2814 |
#設置錯誤訊息
|
|
|
2815 |
$result["error"]=$checkResult;
|
|
|
2816 |
|
|
|
2817 |
#函式說明:
|
|
|
2818 |
#取得簡單的錯誤訊息
|
|
|
2819 |
#回傳結果:
|
|
|
2820 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2821 |
#$result["content"],結果.
|
|
|
2822 |
#$result["function"],當前執行的函數
|
|
|
2823 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2824 |
#必填參數:
|
|
|
2825 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2826 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2827 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2828 |
#可省略參數:
|
|
|
2829 |
#無
|
|
|
2830 |
#參考資料:
|
|
|
2831 |
#無.
|
|
|
2832 |
#備註:
|
|
|
2833 |
#無.
|
|
|
2834 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2835 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2836 |
|
|
|
2837 |
#如果執行失敗
|
|
|
2838 |
if($getSimpleError["status"]==="false"){
|
|
|
2839 |
|
|
|
2840 |
#設置執行錯誤訊息
|
|
|
2841 |
$result["error"][]=$getSimpleError;
|
|
|
2842 |
|
|
|
2843 |
#回傳結果
|
|
|
2844 |
return $result;
|
|
|
2845 |
|
|
|
2846 |
}#if end
|
|
|
2847 |
|
|
|
2848 |
#設置 $simpleError
|
|
|
2849 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2850 |
|
|
|
2851 |
#回傳結果
|
|
|
2852 |
return $result;
|
|
|
2853 |
|
|
|
2854 |
}#if end
|
|
|
2855 |
|
|
|
2856 |
}#if end
|
|
|
2857 |
|
|
|
2858 |
#反之 預設值沒有含有 "$"
|
|
|
2859 |
else{
|
|
|
2860 |
|
|
|
2861 |
#函式說明:
|
|
|
2862 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2863 |
#回傳結果:
|
|
|
2864 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2865 |
#$result["error"],錯誤訊息陣列.
|
|
|
2866 |
#$result["function"],當前執行的函式名稱.
|
|
|
2867 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2868 |
#必填參數:
|
|
|
2869 |
#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2870 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf["varInput"];
|
|
|
2871 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2872 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array($conf["skipableVariableName"][$i]);
|
|
|
2873 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
2874 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array($conf["skipableVariableType"][$i]);
|
|
|
2875 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
2876 |
$argu=&$conf["varInput"];
|
|
|
2877 |
#可省略參數:
|
|
|
2878 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array($conf["skipableVarDefaultValue"][$i]);
|
|
|
2879 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
2880 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
2881 |
|
|
|
2882 |
#如果檢查失敗
|
|
|
2883 |
if($checkResult["status"]=="false"){
|
|
|
2884 |
|
|
|
2885 |
#設置錯誤識別
|
|
|
2886 |
$result["status"]="false";
|
|
|
2887 |
|
|
|
2888 |
#設置錯誤訊息
|
|
|
2889 |
$result["error"]=$checkResult;
|
|
|
2890 |
|
|
|
2891 |
#函式說明:
|
|
|
2892 |
#取得簡單的錯誤訊息
|
|
|
2893 |
#回傳結果:
|
|
|
2894 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2895 |
#$result["content"],結果.
|
|
|
2896 |
#$result["function"],當前執行的函數
|
|
|
2897 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2898 |
#必填參數:
|
|
|
2899 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2900 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2901 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2902 |
#可省略參數:
|
|
|
2903 |
#無
|
|
|
2904 |
#參考資料:
|
|
|
2905 |
#無.
|
|
|
2906 |
#備註:
|
|
|
2907 |
#無.
|
|
|
2908 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2909 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2910 |
|
|
|
2911 |
#如果執行失敗
|
|
|
2912 |
if($getSimpleError["status"]==="false"){
|
|
|
2913 |
|
|
|
2914 |
#設置執行錯誤訊息
|
|
|
2915 |
$result["error"][]=$getSimpleError;
|
|
|
2916 |
|
|
|
2917 |
#回傳結果
|
|
|
2918 |
return $result;
|
|
|
2919 |
|
|
|
2920 |
}#if end
|
|
|
2921 |
|
|
|
2922 |
#設置 $simpleError
|
|
|
2923 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2924 |
|
|
|
2925 |
#回傳結果
|
|
|
2926 |
return $result;
|
|
|
2927 |
|
|
|
2928 |
}#if end
|
|
|
2929 |
|
|
|
2930 |
#如果檢查不通過
|
|
|
2931 |
if($checkResult["passed"]=="false"){
|
|
|
2932 |
|
|
|
2933 |
#設置執正常
|
|
|
2934 |
$result["status"]="true";
|
|
|
2935 |
|
|
|
2936 |
#設置錯誤識別
|
|
|
2937 |
$result["passed"]="false";
|
|
|
2938 |
|
|
|
2939 |
#設置錯誤訊息
|
|
|
2940 |
$result["error"]=$checkResult;
|
|
|
2941 |
|
|
|
2942 |
#函式說明:
|
|
|
2943 |
#取得簡單的錯誤訊息
|
|
|
2944 |
#回傳結果:
|
|
|
2945 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2946 |
#$result["content"],結果.
|
|
|
2947 |
#$result["function"],當前執行的函數
|
|
|
2948 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
2949 |
#必填參數:
|
|
|
2950 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
2951 |
#$conf["error"],陣列,要處理的變數.
|
|
|
2952 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
2953 |
#可省略參數:
|
|
|
2954 |
#無
|
|
|
2955 |
#參考資料:
|
|
|
2956 |
#無.
|
|
|
2957 |
#備註:
|
|
|
2958 |
#無.
|
|
|
2959 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
2960 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
2961 |
|
|
|
2962 |
#如果執行失敗
|
|
|
2963 |
if($getSimpleError["status"]==="false"){
|
|
|
2964 |
|
|
|
2965 |
#設置執行錯誤訊息
|
|
|
2966 |
$result["error"][]=$getSimpleError;
|
|
|
2967 |
|
|
|
2968 |
#回傳結果
|
|
|
2969 |
return $result;
|
|
|
2970 |
|
|
|
2971 |
}#if end
|
|
|
2972 |
|
|
|
2973 |
#設置 $simpleError
|
|
|
2974 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
2975 |
|
|
|
2976 |
#回傳結果
|
|
|
2977 |
return $result;
|
|
|
2978 |
|
|
|
2979 |
}#if end
|
|
|
2980 |
|
|
|
2981 |
}#else end
|
|
|
2982 |
|
|
|
2983 |
}#if end
|
|
|
2984 |
|
|
|
2985 |
#反之預設值非字串
|
|
|
2986 |
else{
|
|
|
2987 |
|
|
|
2988 |
#函式說明:
|
|
|
2989 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2990 |
#回傳結果:
|
|
|
2991 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2992 |
#$result["error"],錯誤訊息陣列.
|
|
|
2993 |
#$result["function"],當前執行的函式名稱.
|
|
|
2994 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2995 |
#必填參數:
|
|
|
2996 |
#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2997 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf["varInput"];
|
|
|
2998 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2999 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array($conf["skipableVariableName"][$i]);
|
|
|
3000 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
3001 |
$argu=&$conf["varInput"];
|
|
|
3002 |
#可省略參數:
|
|
|
3003 |
|
|
|
3004 |
#如果有設定 $conf["skipableVariableType"]
|
|
|
3005 |
if(isset($conf["skipableVariableType"])){
|
|
|
3006 |
|
|
|
3007 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
3008 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array($conf["skipableVariableType"][$i]);
|
|
|
3009 |
|
|
|
3010 |
}#if end
|
|
|
3011 |
|
|
|
3012 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,null代表不指定.
|
|
|
3013 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array($conf["skipableVarDefaultValue"][$i]);
|
|
|
3014 |
#var_dump($conf);
|
|
|
3015 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
3016 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
3017 |
|
|
|
3018 |
#如果檢查失敗
|
|
|
3019 |
if($checkResult["status"]=="false"){
|
|
|
3020 |
|
|
|
3021 |
#設置執行失敗
|
|
|
3022 |
$result["status"]="false";
|
|
|
3023 |
|
|
|
3024 |
#設置錯誤訊息
|
|
|
3025 |
$result["error"]=$checkResult;
|
|
|
3026 |
|
|
|
3027 |
#函式說明:
|
|
|
3028 |
#取得簡單的錯誤訊息
|
|
|
3029 |
#回傳結果:
|
|
|
3030 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3031 |
#$result["content"],結果.
|
|
|
3032 |
#$result["function"],當前執行的函數
|
|
|
3033 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3034 |
#必填參數:
|
|
|
3035 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3036 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3037 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3038 |
#可省略參數:
|
|
|
3039 |
#無
|
|
|
3040 |
#參考資料:
|
|
|
3041 |
#無.
|
|
|
3042 |
#備註:
|
|
|
3043 |
#無.
|
|
|
3044 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3045 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3046 |
|
|
|
3047 |
#如果執行失敗
|
|
|
3048 |
if($getSimpleError["status"]==="false"){
|
|
|
3049 |
|
|
|
3050 |
#設置執行錯誤訊息
|
|
|
3051 |
$result["error"][]=$getSimpleError;
|
|
|
3052 |
|
|
|
3053 |
#回傳結果
|
|
|
3054 |
return $result;
|
|
|
3055 |
|
|
|
3056 |
}#if end
|
|
|
3057 |
|
|
|
3058 |
#設置 $simpleError
|
|
|
3059 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3060 |
|
|
|
3061 |
#回傳結果
|
|
|
3062 |
return $result;
|
|
|
3063 |
|
|
|
3064 |
}#if end
|
|
|
3065 |
|
|
|
3066 |
#如果檢查不通過
|
|
|
3067 |
if($checkResult["passed"]=="false"){
|
|
|
3068 |
|
|
|
3069 |
#設置執正常
|
|
|
3070 |
$result["status"]="true";
|
|
|
3071 |
|
|
|
3072 |
#設置錯誤識別
|
|
|
3073 |
$result["passed"]="false";
|
|
|
3074 |
|
|
|
3075 |
#設置錯誤訊息
|
|
|
3076 |
$result["error"]=$checkResult;
|
|
|
3077 |
|
|
|
3078 |
#函式說明:
|
|
|
3079 |
#取得簡單的錯誤訊息
|
|
|
3080 |
#回傳結果:
|
|
|
3081 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3082 |
#$result["content"],結果.
|
|
|
3083 |
#$result["function"],當前執行的函數
|
|
|
3084 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3085 |
#必填參數:
|
|
|
3086 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3087 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3088 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3089 |
#可省略參數:
|
|
|
3090 |
#無
|
|
|
3091 |
#參考資料:
|
|
|
3092 |
#無.
|
|
|
3093 |
#備註:
|
|
|
3094 |
#無.
|
|
|
3095 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3096 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3097 |
|
|
|
3098 |
#如果執行失敗
|
|
|
3099 |
if($getSimpleError["status"]==="false"){
|
|
|
3100 |
|
|
|
3101 |
#設置執行錯誤訊息
|
|
|
3102 |
$result["error"][]=$getSimpleError;
|
|
|
3103 |
|
|
|
3104 |
#回傳結果
|
|
|
3105 |
return $result;
|
|
|
3106 |
|
|
|
3107 |
}#if end
|
|
|
3108 |
|
|
|
3109 |
#設置 $simpleError
|
|
|
3110 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3111 |
|
|
|
3112 |
#回傳結果
|
|
|
3113 |
return $result;
|
|
|
3114 |
|
|
|
3115 |
}#if end
|
|
|
3116 |
|
|
|
3117 |
}#else end
|
|
|
3118 |
|
|
|
3119 |
}#if end
|
|
|
3120 |
|
|
|
3121 |
#反之沒有設定預設值
|
|
|
3122 |
else{
|
|
|
3123 |
|
|
|
3124 |
#函式說明:
|
|
|
3125 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
3126 |
#回傳結果:
|
|
|
3127 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3128 |
#$result["error"],錯誤訊息陣列.
|
|
|
3129 |
#$result["function"],當前執行的函式名稱.
|
|
|
3130 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
3131 |
#必填參數:
|
|
|
3132 |
#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
3133 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf["varInput"];
|
|
|
3134 |
#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
3135 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array($conf["skipableVariableName"][$i]);
|
|
|
3136 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
3137 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array($conf["skipableVariableType"][$i]);
|
|
|
3138 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
3139 |
$argu=&$conf["varInput"];
|
|
|
3140 |
#可省略參數:
|
|
|
3141 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array($conf["skipableVarDefaultValue"][$i]);
|
|
|
3142 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
3143 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
|
|
3144 |
|
|
|
3145 |
#如果檢查失敗
|
|
|
3146 |
if($checkResult["status"]=="false"){
|
|
|
3147 |
|
|
|
3148 |
#設置錯誤識別
|
|
|
3149 |
$result["status"]="false";
|
|
|
3150 |
|
|
|
3151 |
#設置錯誤訊息
|
|
|
3152 |
$result["error"]=$checkResult;
|
|
|
3153 |
|
|
|
3154 |
#函式說明:
|
|
|
3155 |
#取得簡單的錯誤訊息
|
|
|
3156 |
#回傳結果:
|
|
|
3157 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3158 |
#$result["content"],結果.
|
|
|
3159 |
#$result["function"],當前執行的函數
|
|
|
3160 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3161 |
#必填參數:
|
|
|
3162 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3163 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3164 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3165 |
#可省略參數:
|
|
|
3166 |
#無
|
|
|
3167 |
#參考資料:
|
|
|
3168 |
#無.
|
|
|
3169 |
#備註:
|
|
|
3170 |
#無.
|
|
|
3171 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3172 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3173 |
|
|
|
3174 |
#如果執行失敗
|
|
|
3175 |
if($getSimpleError["status"]==="false"){
|
|
|
3176 |
|
|
|
3177 |
#設置執行錯誤訊息
|
|
|
3178 |
$result["error"][]=$getSimpleError;
|
|
|
3179 |
|
|
|
3180 |
#回傳結果
|
|
|
3181 |
return $result;
|
|
|
3182 |
|
|
|
3183 |
}#if end
|
|
|
3184 |
|
|
|
3185 |
#設置 $simpleError
|
|
|
3186 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3187 |
|
|
|
3188 |
#回傳結果
|
|
|
3189 |
return $result;
|
|
|
3190 |
|
|
|
3191 |
}#if end
|
|
|
3192 |
|
|
|
3193 |
#如果檢查不通過
|
|
|
3194 |
if($checkResult["passed"]=="false"){
|
|
|
3195 |
|
|
|
3196 |
#設置執正常
|
|
|
3197 |
$result["status"]="true";
|
|
|
3198 |
|
|
|
3199 |
#設置錯誤識別
|
|
|
3200 |
$result["passed"]="false";
|
|
|
3201 |
|
|
|
3202 |
#設置錯誤訊息
|
|
|
3203 |
$result["error"]=$checkResult;
|
|
|
3204 |
|
|
|
3205 |
#函式說明:
|
|
|
3206 |
#取得簡單的錯誤訊息
|
|
|
3207 |
#回傳結果:
|
|
|
3208 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3209 |
#$result["content"],結果.
|
|
|
3210 |
#$result["function"],當前執行的函數
|
|
|
3211 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3212 |
#必填參數:
|
|
|
3213 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3214 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3215 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3216 |
#可省略參數:
|
|
|
3217 |
#無
|
|
|
3218 |
#參考資料:
|
|
|
3219 |
#無.
|
|
|
3220 |
#備註:
|
|
|
3221 |
#無.
|
|
|
3222 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3223 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3224 |
|
|
|
3225 |
#如果執行失敗
|
|
|
3226 |
if($getSimpleError["status"]==="false"){
|
|
|
3227 |
|
|
|
3228 |
#設置執行錯誤訊息
|
|
|
3229 |
$result["error"][]=$getSimpleError;
|
|
|
3230 |
|
|
|
3231 |
#回傳結果
|
|
|
3232 |
return $result;
|
|
|
3233 |
|
|
|
3234 |
}#if end
|
|
|
3235 |
|
|
|
3236 |
#設置 $simpleError
|
|
|
3237 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3238 |
|
|
|
3239 |
#回傳結果
|
|
|
3240 |
return $result;
|
|
|
3241 |
|
|
|
3242 |
}#if end
|
|
|
3243 |
|
|
|
3244 |
}#else end
|
|
|
3245 |
|
|
|
3246 |
}#for end
|
|
|
3247 |
|
|
|
3248 |
}#if end
|
|
|
3249 |
|
|
|
3250 |
#如果 $conf["arrayCountEqualCheck"] 存在
|
|
|
3251 |
if(isset($conf["arrayCountEqualCheck"])){
|
|
|
3252 |
|
|
|
3253 |
#$conf["arrayCountEqualCheck"]有幾組元素就執行幾次
|
|
|
3254 |
for($i=0;$i<count($conf["arrayCountEqualCheck"]);$i++){
|
|
|
3255 |
|
|
|
3256 |
#初始化暫存元素數量的陣列
|
|
|
3257 |
$tempEqualCount=array();
|
|
|
3258 |
|
|
|
3259 |
#該組有幾個元素就執行幾次
|
|
|
3260 |
for($j=0;$j<count($conf["arrayCountEqualCheck"][$i]);$j++){
|
|
|
3261 |
|
|
|
3262 |
#如果要判斷元素數量是否一致的變數陣列存在
|
|
|
3263 |
if(isset($conf["varInput"][$conf["arrayCountEqualCheck"][$i][$j]])){
|
|
|
3264 |
|
|
|
3265 |
#儲存該組該變數的元素數量
|
|
|
3266 |
$tempEqualCount[]=count($conf["varInput"][$conf["arrayCountEqualCheck"][$i][$j]]);
|
|
|
3267 |
|
|
|
3268 |
}#if end
|
|
|
3269 |
|
|
|
3270 |
}#for end
|
|
|
3271 |
|
|
|
3272 |
#如果該組只有一個元素數量資料
|
|
|
3273 |
if(count($tempEqualCount)==0){
|
|
|
3274 |
|
|
|
3275 |
#跳出迴圈
|
|
|
3276 |
break;
|
|
|
3277 |
|
|
|
3278 |
}#if end
|
|
|
3279 |
|
|
|
3280 |
#看 $tempEqualCount 中的元素計數是否都一樣
|
|
|
3281 |
#$tempEqualCount 有幾個元素就執行幾次
|
|
|
3282 |
for($j=1;$j<count($tempEqualCount);$j++){
|
|
|
3283 |
|
|
|
3284 |
#如果跟第一個變數的元素數量不一樣
|
|
|
3285 |
if($tempEqualCount[0]!=$tempEqualCount[$j]){
|
|
|
3286 |
|
|
|
3287 |
#設置執正常
|
|
|
3288 |
$result["status"]="true";
|
|
|
3289 |
|
|
|
3290 |
#設置錯誤識別
|
|
|
3291 |
$result["passed"]="false";
|
|
|
3292 |
|
|
|
3293 |
#設置錯誤訊息
|
|
|
3294 |
$result["error"][]="key為".$conf["arrayCountEqualCheck"][$i][0]."與".$conf["arrayCountEqualCheck"][$i][$j]."的參數其元數數量不一致";
|
|
|
3295 |
|
|
|
3296 |
#設置錯誤訊息
|
|
|
3297 |
$result["error"][]=array("key為".$conf["arrayCountEqualCheck"][$i][0]."的參數",$conf["varInput"][$conf["arrayCountEqualCheck"][$i][0]]);
|
|
|
3298 |
|
|
|
3299 |
#設置錯誤訊息
|
|
|
3300 |
$result["error"][]=array("key為".$conf["arrayCountEqualCheck"][$i][$j]."的參數",$conf["varInput"][$conf["arrayCountEqualCheck"][$i][$j]]);
|
|
|
3301 |
|
|
|
3302 |
#函式說明:
|
|
|
3303 |
#取得簡單的錯誤訊息
|
|
|
3304 |
#回傳結果:
|
|
|
3305 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3306 |
#$result["content"],結果.
|
|
|
3307 |
#$result["function"],當前執行的函數
|
|
|
3308 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3309 |
#必填參數:
|
|
|
3310 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3311 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3312 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3313 |
#可省略參數:
|
|
|
3314 |
#無
|
|
|
3315 |
#參考資料:
|
|
|
3316 |
#無.
|
|
|
3317 |
#備註:
|
|
|
3318 |
#無.
|
|
|
3319 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3320 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3321 |
|
|
|
3322 |
#如果執行失敗
|
|
|
3323 |
if($getSimpleError["status"]==="false"){
|
|
|
3324 |
|
|
|
3325 |
#設置執行錯誤訊息
|
|
|
3326 |
$result["error"][]=$getSimpleError;
|
|
|
3327 |
|
|
|
3328 |
#回傳結果
|
|
|
3329 |
return $result;
|
|
|
3330 |
|
|
|
3331 |
}#if end
|
|
|
3332 |
|
|
|
3333 |
#設置 $simpleError
|
|
|
3334 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3335 |
|
|
|
3336 |
#回傳結果
|
|
|
3337 |
return $result;
|
|
|
3338 |
|
|
|
3339 |
}#if end
|
|
|
3340 |
|
|
|
3341 |
}#for end
|
|
|
3342 |
|
|
|
3343 |
}#for end
|
|
|
3344 |
|
|
|
3345 |
}#if end
|
|
|
3346 |
|
|
|
3347 |
#初始化儲存所有參數名稱的陣列
|
|
|
3348 |
$arguArray=array();
|
|
|
3349 |
|
|
|
3350 |
#如果有要必填的參數名稱
|
|
|
3351 |
if(isset($conf["mustBeFilledVariableName"])){
|
|
|
3352 |
|
|
|
3353 |
#記錄必填的參數
|
|
|
3354 |
$arguArray=$conf["mustBeFilledVariableName"];
|
|
|
3355 |
|
|
|
3356 |
}#if end
|
|
|
3357 |
|
|
|
3358 |
#若有可省略的參數
|
|
|
3359 |
if(isset($conf["skipableVariableName"])){
|
|
|
3360 |
|
|
|
3361 |
#有幾個可省略參數就執行幾次
|
|
|
3362 |
for($i=0;$i<count($conf["skipableVariableName"]);$i++){
|
|
|
3363 |
|
|
|
3364 |
#記錄參數
|
|
|
3365 |
$arguArray[]=$conf["skipableVariableName"][$i];
|
|
|
3366 |
|
|
|
3367 |
}#for end
|
|
|
3368 |
|
|
|
3369 |
}#if end
|
|
|
3370 |
|
|
|
3371 |
#如果有可省略變數的any形態變數設定
|
|
|
3372 |
if(isset($anyTypeVarName)){
|
|
|
3373 |
|
|
|
3374 |
#針對每個可省略的any形態變數
|
|
|
3375 |
foreach($anyTypeVarName as $varName){
|
|
|
3376 |
|
|
|
3377 |
#記錄參數
|
|
|
3378 |
$arguArray[]=$varName;
|
|
|
3379 |
|
|
|
3380 |
}#foreach end
|
|
|
3381 |
|
|
|
3382 |
}#if end
|
|
|
3383 |
|
|
|
3384 |
#初始化儲存已經輸入的參數名稱陣列
|
|
|
3385 |
$inputVarArray=array();
|
|
|
3386 |
|
|
|
3387 |
#移除不要的參考陣列
|
|
|
3388 |
unset($conf["varInput"][$conf["referenceVarKey"]]);
|
|
|
3389 |
|
|
|
3390 |
#有幾個輸入的參數就執行幾次
|
|
|
3391 |
foreach($conf["varInput"] as $key=>$value ){
|
|
|
3392 |
|
|
|
3393 |
#儲存參數的名稱
|
|
|
3394 |
$inputVarArray[]=$key;
|
|
|
3395 |
|
|
|
3396 |
}#foreach end
|
|
|
3397 |
|
|
|
3398 |
#有幾個輸入的參數就執行幾次
|
|
|
3399 |
for($i=0;$i<count($inputVarArray);$i++){
|
|
|
3400 |
|
|
|
3401 |
#初始化是否有找到對應的必填或可省參數
|
|
|
3402 |
$matched="false";
|
|
|
3403 |
|
|
|
3404 |
#檢查該輸入的參數是否應該存在
|
|
|
3405 |
for($j=0;$j<count($arguArray);$j++){
|
|
|
3406 |
|
|
|
3407 |
#如果該輸入的參數屬於應該要有的參數
|
|
|
3408 |
if($inputVarArray[$i]==$arguArray[$j]){
|
|
|
3409 |
|
|
|
3410 |
#設置有找到對應的必填或可省參數
|
|
|
3411 |
$matched="true";
|
|
|
3412 |
|
|
|
3413 |
}#if end
|
|
|
3414 |
|
|
|
3415 |
}#for end
|
|
|
3416 |
|
|
|
3417 |
#如果對照了所有必填與可省略參數都沒有找到一樣的參數名稱
|
|
|
3418 |
if($matched=="false"){
|
|
|
3419 |
|
|
|
3420 |
#記錄目前輸入的參數名稱陣列
|
|
|
3421 |
$result["argu"]=$inputVarArray;
|
|
|
3422 |
|
|
|
3423 |
#記錄合法可用的參數名稱陣列.
|
|
|
3424 |
$result["legalVarName"]=$arguArray;
|
|
|
3425 |
|
|
|
3426 |
#記錄不應該存在的參數名稱
|
|
|
3427 |
$result["notNeedVar"][]=$inputVarArray[$i];
|
|
|
3428 |
|
|
|
3429 |
}#if end
|
|
|
3430 |
|
|
|
3431 |
}#for end
|
|
|
3432 |
|
|
|
3433 |
#如果有不應該存在的參數名稱
|
|
|
3434 |
if(isset($result["notNeedVar"])){
|
|
|
3435 |
|
|
|
3436 |
#設置錯誤識別
|
|
|
3437 |
$result["status"]="true";
|
|
|
3438 |
|
|
|
3439 |
#設置檢查不通過
|
|
|
3440 |
$result["passed"]="false";
|
|
|
3441 |
|
|
|
3442 |
#設置錯誤訊息
|
|
|
3443 |
$result["error"]="發現「".count($result["notNeedVar"])."」個多餘的參數";
|
|
|
3444 |
|
|
|
3445 |
#函式說明:
|
|
|
3446 |
#取得簡單的錯誤訊息
|
|
|
3447 |
#回傳結果:
|
|
|
3448 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3449 |
#$result["content"],結果.
|
|
|
3450 |
#$result["function"],當前執行的函數
|
|
|
3451 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3452 |
#必填參數:
|
|
|
3453 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3454 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3455 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3456 |
#可省略參數:
|
|
|
3457 |
#無
|
|
|
3458 |
#參考資料:
|
|
|
3459 |
#無.
|
|
|
3460 |
#備註:
|
|
|
3461 |
#無.
|
|
|
3462 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3463 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3464 |
|
|
|
3465 |
#如果執行失敗
|
|
|
3466 |
if($getSimpleError["status"]==="false"){
|
|
|
3467 |
|
|
|
3468 |
#設置執行錯誤訊息
|
|
|
3469 |
$result["error"][]=$getSimpleError;
|
|
|
3470 |
|
|
|
3471 |
#回傳結果
|
|
|
3472 |
return $result;
|
|
|
3473 |
|
|
|
3474 |
}#if end
|
|
|
3475 |
|
|
|
3476 |
#設置 $simpleError
|
|
|
3477 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3478 |
|
|
|
3479 |
#回傳結果
|
|
|
3480 |
return $result;
|
|
|
3481 |
|
|
|
3482 |
}#if end
|
|
|
3483 |
|
|
|
3484 |
#初始化儲存沒有符合規定的參數訊息
|
|
|
3485 |
$result["shouldNotBeEmpty"]=array();
|
|
|
3486 |
|
|
|
3487 |
#如果有設定 $conf["skipableVariableCanNotBeEmpty"]
|
|
|
3488 |
if(isset($conf["skipableVariableCanNotBeEmpty"])){
|
|
|
3489 |
|
|
|
3490 |
#針對每個不能為空值跟空集合的變數名稱
|
|
|
3491 |
foreach($conf["skipableVariableCanNotBeEmpty"] as $varName){
|
|
|
3492 |
|
|
|
3493 |
#如果可省略變數 $varName 存在
|
|
|
3494 |
if(isset($conf["varInput"][$varName])){
|
|
|
3495 |
|
|
|
3496 |
#如果其為 空字串 或 空陣列
|
|
|
3497 |
if($conf["varInput"][$varName]==""){
|
|
|
3498 |
|
|
|
3499 |
#記錄沒有符合規定的參數訊息
|
|
|
3500 |
$result["shouldNotBeEmpty"][]="參數「".$varName."」不得為空字串";
|
|
|
3501 |
|
|
|
3502 |
}#if end
|
|
|
3503 |
|
|
|
3504 |
#反之如果為陣列
|
|
|
3505 |
else if(gettype($conf["varInput"][$varName])==="array"){
|
|
|
3506 |
|
|
|
3507 |
#如果為空陣列
|
|
|
3508 |
if(count($conf["varInput"][$varName])===0){
|
|
|
3509 |
|
|
|
3510 |
#記錄沒有符合規定的參數訊息
|
|
|
3511 |
$result["shouldNotBeEmpty"][]="參數「".$varName."」不得為空集合";
|
|
|
3512 |
|
|
|
3513 |
}#if end
|
|
|
3514 |
|
|
|
3515 |
}#else end
|
|
|
3516 |
|
|
|
3517 |
}#if end
|
|
|
3518 |
|
|
|
3519 |
}#foreach end
|
|
|
3520 |
|
|
|
3521 |
#如果 $result["shouldNotBeEmpty"] 存在元素
|
|
|
3522 |
if(count($result["shouldNotBeEmpty"])>0){
|
|
|
3523 |
|
|
|
3524 |
#設置錯誤識別
|
|
|
3525 |
$result["status"]="true";
|
|
|
3526 |
|
|
|
3527 |
#設置檢查不通過
|
|
|
3528 |
$result["passed"]="false";
|
|
|
3529 |
|
|
|
3530 |
#函式說明:
|
|
|
3531 |
#取得簡單的錯誤訊息
|
|
|
3532 |
#回傳結果:
|
|
|
3533 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3534 |
#$result["content"],結果.
|
|
|
3535 |
#$result["function"],當前執行的函數
|
|
|
3536 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3537 |
#必填參數:
|
|
|
3538 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3539 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3540 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3541 |
#可省略參數:
|
|
|
3542 |
#無
|
|
|
3543 |
#參考資料:
|
|
|
3544 |
#無.
|
|
|
3545 |
#備註:
|
|
|
3546 |
#無.
|
|
|
3547 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3548 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3549 |
|
|
|
3550 |
#如果執行失敗
|
|
|
3551 |
if($getSimpleError["status"]==="false"){
|
|
|
3552 |
|
|
|
3553 |
#設置執行錯誤訊息
|
|
|
3554 |
$result["error"][]=$getSimpleError;
|
|
|
3555 |
|
|
|
3556 |
#回傳結果
|
|
|
3557 |
return $result;
|
|
|
3558 |
|
|
|
3559 |
}#if end
|
|
|
3560 |
|
|
|
3561 |
#設置 $simpleError
|
|
|
3562 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3563 |
|
|
|
3564 |
#回傳結果
|
|
|
3565 |
return $result;
|
|
|
3566 |
|
|
|
3567 |
}#if end
|
|
|
3568 |
|
|
|
3569 |
}#if end
|
|
|
3570 |
|
|
|
3571 |
#如果有設定可省略參數且不允許所有可省略變數都不存在
|
|
|
3572 |
if( isset($conf["skipableVariableName"]) && ($conf["disallowAllSkipableVarNotExist"]==="true") ){
|
|
|
3573 |
|
|
|
3574 |
#函式說明:
|
|
|
3575 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
3576 |
#回傳結果:
|
|
|
3577 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
3578 |
#$result["function"],當前執行的函數名稱.
|
|
|
3579 |
#$result["error"],錯誤訊息.
|
|
|
3580 |
#$result["argu"],使用的參數.
|
|
|
3581 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
3582 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
3583 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
3584 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
3585 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
3586 |
#必填參數:
|
|
|
3587 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
3588 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=$conf["skipableVariableName"];
|
|
|
3589 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
3590 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=array_keys($conf["varInput"]);
|
|
|
3591 |
#可省略參數:
|
|
|
3592 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
3593 |
#$conf["completeEqual"]="true";
|
|
|
3594 |
#參考資料:
|
|
|
3595 |
#無.
|
|
|
3596 |
#備註:
|
|
|
3597 |
#無.
|
|
|
3598 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
3599 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
3600 |
|
|
|
3601 |
#如果執行失敗
|
|
|
3602 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
|
|
3603 |
|
|
|
3604 |
#設置錯誤識別
|
|
|
3605 |
$result["status"]="false";
|
|
|
3606 |
|
|
|
3607 |
#設置檢查不通過
|
|
|
3608 |
$result["passed"]="false";
|
|
|
3609 |
|
|
|
3610 |
#設置執行錯誤訊息
|
|
|
3611 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
3612 |
|
|
|
3613 |
#函式說明:
|
|
|
3614 |
#取得簡單的錯誤訊息
|
|
|
3615 |
#回傳結果:
|
|
|
3616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3617 |
#$result["content"],結果.
|
|
|
3618 |
#$result["function"],當前執行的函數
|
|
|
3619 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3620 |
#必填參數:
|
|
|
3621 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3622 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3623 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3624 |
#可省略參數:
|
|
|
3625 |
#無
|
|
|
3626 |
#參考資料:
|
|
|
3627 |
#無.
|
|
|
3628 |
#備註:
|
|
|
3629 |
#無.
|
|
|
3630 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3631 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3632 |
|
|
|
3633 |
#如果執行失敗
|
|
|
3634 |
if($getSimpleError["status"]==="false"){
|
|
|
3635 |
|
|
|
3636 |
#設置執行錯誤訊息
|
|
|
3637 |
$result["error"][]=$getSimpleError;
|
|
|
3638 |
|
|
|
3639 |
#回傳結果
|
|
|
3640 |
return $result;
|
|
|
3641 |
|
|
|
3642 |
}#if end
|
|
|
3643 |
|
|
|
3644 |
#設置 $simpleError
|
|
|
3645 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3646 |
|
|
|
3647 |
#回傳結果
|
|
|
3648 |
return $result;
|
|
|
3649 |
|
|
|
3650 |
}#if end
|
|
|
3651 |
|
|
|
3652 |
#如果沒有找到至少一個可省略參數存在
|
|
|
3653 |
if(count($findManyKeyWordsFromManyString["foundedTrueKey"])===0){
|
|
|
3654 |
|
|
|
3655 |
#設置執行正常
|
|
|
3656 |
$result["status"]="true";
|
|
|
3657 |
|
|
|
3658 |
#設置檢查不通過
|
|
|
3659 |
$result["passed"]="false";
|
|
|
3660 |
|
|
|
3661 |
#設置執行錯誤訊息
|
|
|
3662 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
3663 |
|
|
|
3664 |
#函式說明:
|
|
|
3665 |
#取得簡單的錯誤訊息
|
|
|
3666 |
#回傳結果:
|
|
|
3667 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3668 |
#$result["content"],結果.
|
|
|
3669 |
#$result["function"],當前執行的函數
|
|
|
3670 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3671 |
#必填參數:
|
|
|
3672 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
3673 |
#$conf["error"],陣列,要處理的變數.
|
|
|
3674 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
3675 |
#可省略參數:
|
|
|
3676 |
#無
|
|
|
3677 |
#參考資料:
|
|
|
3678 |
#無.
|
|
|
3679 |
#備註:
|
|
|
3680 |
#無.
|
|
|
3681 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
3682 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
3683 |
|
|
|
3684 |
#如果執行失敗
|
|
|
3685 |
if($getSimpleError["status"]==="false"){
|
|
|
3686 |
|
|
|
3687 |
#設置執行錯誤訊息
|
|
|
3688 |
$result["error"][]=$getSimpleError;
|
|
|
3689 |
|
|
|
3690 |
#回傳結果
|
|
|
3691 |
return $result;
|
|
|
3692 |
|
|
|
3693 |
}#if end
|
|
|
3694 |
|
|
|
3695 |
#設置 $simpleError
|
|
|
3696 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
3697 |
|
|
|
3698 |
#回傳結果
|
|
|
3699 |
return $result;
|
|
|
3700 |
|
|
|
3701 |
}#if end
|
|
|
3702 |
|
|
|
3703 |
}#if end
|
|
|
3704 |
|
|
|
3705 |
#設置執行正常
|
|
|
3706 |
$result["status"]="true";
|
|
|
3707 |
|
|
|
3708 |
#設置錯誤識別
|
|
|
3709 |
$result["passed"]="true";
|
|
|
3710 |
|
|
|
3711 |
#回傳結果
|
|
|
3712 |
return $result;
|
|
|
3713 |
|
|
|
3714 |
}#function checkArguments end
|
|
|
3715 |
|
|
|
3716 |
/*
|
|
|
3717 |
#函式說明:
|
|
|
3718 |
#檢查一陣列變數是否為空陣列
|
|
|
3719 |
#回傳結果:
|
|
|
3720 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3721 |
#$result["content"],結果陣列.
|
|
|
3722 |
#$result["function"],當前執行的函數
|
|
|
3723 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3724 |
#$result["empty"],"true"代表為空陣列,"false"代表不為空陣列.
|
|
|
3725 |
#必填參數:
|
|
|
3726 |
#$conf["var"],陣列變數.
|
|
|
3727 |
$conf["var"]=;
|
|
|
3728 |
#可省略參數:
|
|
|
3729 |
#無.
|
|
|
3730 |
#參考資料:
|
|
|
3731 |
#無.
|
|
|
3732 |
#備註:
|
|
|
3733 |
#無.
|
|
|
3734 |
*/
|
|
|
3735 |
public static function emptyArray(&$conf){
|
|
|
3736 |
|
|
|
3737 |
#初始化要回傳的結果
|
|
|
3738 |
$result=array();
|
|
|
3739 |
|
|
|
3740 |
#取得當前執行的函數名稱
|
|
|
3741 |
$result["function"]=__FUNCTION__;
|
|
|
3742 |
|
|
|
3743 |
#如果沒有參數
|
|
|
3744 |
if(func_num_args()==0){
|
|
|
3745 |
|
|
|
3746 |
#設置執行失敗
|
|
|
3747 |
$result["status"]="false";
|
|
|
3748 |
|
|
|
3749 |
#設置執行錯誤訊息
|
|
|
3750 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3751 |
|
|
|
3752 |
#回傳結果
|
|
|
3753 |
return $result;
|
|
|
3754 |
|
|
|
3755 |
}#if end
|
|
|
3756 |
|
|
|
3757 |
#取得參數
|
|
|
3758 |
$result["argu"]=$conf;
|
|
|
3759 |
|
|
|
3760 |
#如果 $conf 不為陣列
|
|
|
3761 |
if(gettype($conf)!=="array"){
|
|
|
3762 |
|
|
|
3763 |
#設置執行失敗
|
|
|
3764 |
$result["status"]="false";
|
|
|
3765 |
|
|
|
3766 |
#設置執行錯誤訊息
|
|
|
3767 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3768 |
|
|
|
3769 |
#如果傳入的參數為 null
|
|
|
3770 |
if($conf===null){
|
|
|
3771 |
|
|
|
3772 |
#設置執行錯誤訊息
|
|
|
3773 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3774 |
|
|
|
3775 |
}#if end
|
|
|
3776 |
|
|
|
3777 |
#回傳結果
|
|
|
3778 |
return $result;
|
|
|
3779 |
|
|
|
3780 |
}#if end
|
|
|
3781 |
|
|
|
3782 |
#檢查參數
|
|
|
3783 |
#函式說明:
|
|
|
3784 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
3785 |
#回傳結果:
|
|
|
3786 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3787 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3788 |
#$result["function"],當前執行的函式名稱.
|
|
|
3789 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3790 |
#$result["warning"],警告訊息
|
|
|
3791 |
#$result["content"][$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3792 |
#$result["content"][$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3793 |
#$result["content"][$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3794 |
#必填參數:
|
|
|
3795 |
$conf["variableCheck::isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
3796 |
$conf["variableCheck::isexistMulti"]["variableCheck"]=array("var");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
3797 |
#可省略參數:
|
|
|
3798 |
$conf["variableCheck::isexistMulti"]["variableType"]=array("array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); ,null代表沒有指定變數形態.
|
|
|
3799 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置.
|
|
|
3800 |
#$conf["cnaBeEmpty"],陣列,可以為空字串或集合的變數,僅當$conf["canBeEmptyString"]為"false"時生效.
|
|
|
3801 |
#$conf["cnaBeEmpty"]=array();
|
|
|
3802 |
#$conf["cnaNotBeEmpty"],陣列,不可以為空字串或集合的變數,僅當$conf["canBeEmptyString"]為"true"時生效.
|
|
|
3803 |
#$conf["cnaNotBeEmpty"]=array();
|
|
|
3804 |
$isexistMulti=variableCheck::isexistMulti($conf["variableCheck::isexistMulti"]);
|
|
|
3805 |
unset($conf["variableCheck::isexistMulti"]);
|
|
|
3806 |
|
|
|
3807 |
#如果檢查變數失敗
|
|
|
3808 |
if($isexistMulti["status"]==="false"){
|
|
|
3809 |
|
|
|
3810 |
#設置執行失敗
|
|
|
3811 |
$result["status"]="false";
|
|
|
3812 |
|
|
|
3813 |
#設置執行錯誤訊息
|
|
|
3814 |
$result["error"]=$isexistMulti;
|
|
|
3815 |
|
|
|
3816 |
#回傳結果
|
|
|
3817 |
return $result;
|
|
|
3818 |
|
|
|
3819 |
}#if end
|
|
|
3820 |
|
|
|
3821 |
#如果檢查變數不通過
|
|
|
3822 |
if($isexistMulti["passed"]==="false"){
|
|
|
3823 |
|
|
|
3824 |
#設置執行失敗
|
|
|
3825 |
$result["status"]="false";
|
|
|
3826 |
|
|
|
3827 |
#設置執行錯誤訊息
|
|
|
3828 |
$result["error"]=$isexistMulti;
|
|
|
3829 |
|
|
|
3830 |
#回傳結果
|
|
|
3831 |
return $result;
|
|
|
3832 |
|
|
|
3833 |
}#if end
|
|
|
3834 |
|
|
|
3835 |
#如果裡面有內容
|
|
|
3836 |
if(count($conf["var"])!==0){
|
|
|
3837 |
|
|
|
3838 |
#針對每個內容
|
|
|
3839 |
foreach($conf["var"] as $var){
|
|
|
3840 |
|
|
|
3841 |
#如果內容不是陣列
|
|
|
3842 |
if(gettype($var)!=="array"){
|
|
|
3843 |
|
|
|
3844 |
#設置執行失敗
|
|
|
3845 |
$result["status"]="true";
|
|
|
3846 |
|
|
|
3847 |
#設置不為空陣列
|
|
|
3848 |
$result["empty"]="false";
|
|
|
3849 |
|
|
|
3850 |
#回傳結果
|
|
|
3851 |
return $result;
|
|
|
3852 |
|
|
|
3853 |
}#if end
|
|
|
3854 |
|
|
|
3855 |
#反之是陣列
|
|
|
3856 |
else{
|
|
|
3857 |
|
|
|
3858 |
#呼叫自己
|
|
|
3859 |
$conf["variableCheck::emptyArray"]["var"]=$var;
|
|
|
3860 |
$emptyArray=variableCheck::emptyArray($conf["variableCheck::emptyArray"]);
|
|
|
3861 |
unset($conf["variableCheck::emptyArray"]);
|
|
|
3862 |
|
|
|
3863 |
#如果執行失敗
|
|
|
3864 |
if($emptyArray["status"]==="false"){
|
|
|
3865 |
|
|
|
3866 |
#設置執行失敗
|
|
|
3867 |
$result["status"]="false";
|
|
|
3868 |
|
|
|
3869 |
#設置執行錯誤訊息
|
|
|
3870 |
$result["error"]=$emptyArray;
|
|
|
3871 |
|
|
|
3872 |
#回傳結果
|
|
|
3873 |
return $result;
|
|
|
3874 |
|
|
|
3875 |
}#if end
|
|
|
3876 |
|
|
|
3877 |
#如果不是空陣列
|
|
|
3878 |
if($emptyArray["empty"]==="false"){
|
|
|
3879 |
|
|
|
3880 |
#設置執行失敗
|
|
|
3881 |
$result["status"]="true";
|
|
|
3882 |
|
|
|
3883 |
#設置不為空陣列
|
|
|
3884 |
$result["empty"]="false";
|
|
|
3885 |
|
|
|
3886 |
#回傳結果
|
|
|
3887 |
return $result;
|
|
|
3888 |
|
|
|
3889 |
}#if end
|
|
|
3890 |
|
|
|
3891 |
}#else end
|
|
|
3892 |
|
|
|
3893 |
}#foreach end
|
|
|
3894 |
|
|
|
3895 |
#設置執行正常
|
|
|
3896 |
$result["status"]="true";
|
|
|
3897 |
|
|
|
3898 |
#設置為空陣列
|
|
|
3899 |
$result["empty"]="true";
|
|
|
3900 |
|
|
|
3901 |
#回傳結果
|
|
|
3902 |
return $result;
|
|
|
3903 |
|
|
|
3904 |
|
|
|
3905 |
}#if end
|
|
|
3906 |
|
|
|
3907 |
#反之為空陣列
|
|
|
3908 |
else{
|
|
|
3909 |
|
|
|
3910 |
#設置執行正常
|
|
|
3911 |
$result["status"]="true";
|
|
|
3912 |
|
|
|
3913 |
#設置為空陣列
|
|
|
3914 |
$result["empty"]="true";
|
|
|
3915 |
|
|
|
3916 |
#回傳結果
|
|
|
3917 |
return $result;
|
|
|
3918 |
|
|
|
3919 |
}#else end
|
|
|
3920 |
|
|
|
3921 |
}#function emptyArray end
|
|
|
3922 |
|
|
|
3923 |
/*
|
|
|
3924 |
#函式說明:
|
|
|
3925 |
#回傳變數的解析結果.
|
|
|
3926 |
#回傳結果:
|
|
|
3927 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3928 |
#$result["content"],變數的解析結果.
|
|
|
3929 |
#$result["function"],當前執行的函數
|
|
|
3930 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
3931 |
#必填參數:
|
|
|
3932 |
#$conf["var"],any,任意內容,通常為變數.
|
|
|
3933 |
$conf["var"]=;
|
|
|
3934 |
#可省略參數:
|
|
|
3935 |
#無.
|
|
|
3936 |
#參考資料:
|
|
|
3937 |
#無.
|
|
|
3938 |
#備註:
|
|
|
3939 |
#無.
|
|
|
3940 |
*/
|
|
|
3941 |
public static function toSource(&$conf){
|
|
|
3942 |
|
|
|
3943 |
#初始化要回傳的內容
|
|
|
3944 |
$result=array();
|
|
|
3945 |
|
|
|
3946 |
#取得當前執行的函數名稱
|
|
|
3947 |
$result["function"]=__FUNCTION__;
|
|
|
3948 |
|
|
|
3949 |
#如果 $conf 不為陣列
|
|
|
3950 |
if(gettype($conf)!="array"){
|
|
|
3951 |
|
|
|
3952 |
#設置執行失敗
|
|
|
3953 |
$result["status"]="false";
|
|
|
3954 |
|
|
|
3955 |
#設置執行錯誤訊息
|
|
|
3956 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3957 |
|
|
|
3958 |
#如果傳入的參數為 null
|
|
|
3959 |
if($conf==null){
|
|
|
3960 |
|
|
|
3961 |
#設置執行錯誤訊息
|
|
|
3962 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3963 |
|
|
|
3964 |
}#if end
|
|
|
3965 |
|
|
|
3966 |
#回傳結果
|
|
|
3967 |
return $result;
|
|
|
3968 |
|
|
|
3969 |
}#if end
|
|
|
3970 |
|
|
|
3971 |
#檢查參數
|
|
|
3972 |
#函式說明:
|
|
|
3973 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3974 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3975 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3976 |
#$result["function"],當前執行的函式名稱.
|
|
|
3977 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3978 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3979 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3980 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3981 |
#必填寫的參數:
|
|
|
3982 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3983 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
3984 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3985 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("var");
|
|
|
3986 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
3987 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array(null);
|
|
|
3988 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3989 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
3990 |
#可以省略的參數:
|
|
|
3991 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
3992 |
#$conf["canBeEmptyString"]="false";
|
|
|
3993 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3994 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("varPassed");
|
|
|
3995 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3996 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"]=array(null);
|
|
|
3997 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3998 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
3999 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
4000 |
unset($conf["variableCheck.checkArguments"]);
|
|
|
4001 |
|
|
|
4002 |
#如果 檢查參數 失敗
|
|
|
4003 |
if($checkArguments["status"]==="false"){
|
|
|
4004 |
|
|
|
4005 |
#設置執行不正常
|
|
|
4006 |
$result["status"]="false";
|
|
|
4007 |
|
|
|
4008 |
#設置執行錯誤
|
|
|
4009 |
$result["error"]=$checkArguments;
|
|
|
4010 |
|
|
|
4011 |
#回傳節果
|
|
|
4012 |
return $result;
|
|
|
4013 |
|
|
|
4014 |
}#if end
|
|
|
4015 |
|
|
|
4016 |
#如果 檢查參數 不通過
|
|
|
4017 |
if($checkArguments["passed"]==="false"){
|
|
|
4018 |
|
|
|
4019 |
#設置執行不正常
|
|
|
4020 |
$result["status"]="false";
|
|
|
4021 |
|
|
|
4022 |
#設置執行錯誤
|
|
|
4023 |
$result["error"]=$checkArguments;
|
|
|
4024 |
|
|
|
4025 |
#回傳節果
|
|
|
4026 |
return $result;
|
|
|
4027 |
|
|
|
4028 |
}#if end
|
|
|
4029 |
|
|
|
4030 |
#函式說明:
|
|
|
4031 |
#記錄程式輸出的結果.
|
|
|
4032 |
#回傳結果:
|
|
|
4033 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
4034 |
#$result["error"],錯誤訊息.
|
|
|
4035 |
#$result["content"],程式的輸出.
|
|
|
4036 |
#$result["function"],當前執行的涵式
|
|
|
4037 |
#必填參數:
|
|
|
4038 |
#$conf["code2run"],字串陣列,爲要運行的程式內容,每個元素代表一段php程式.內容不必含有php tag,但結尾必須為「;」.
|
|
|
4039 |
$conf["record::getOutput"]["code2run"]=array("var_dump(\$varPassed[0]);");
|
|
|
4040 |
#可省略參數:
|
|
|
4041 |
#可省略參數:
|
|
|
4042 |
#$conf["varPassed"],陣列,為要使用到的變數,在code2run參數裡面"\$varPassed[n]"代表第n+1個變數.
|
|
|
4043 |
$conf["record::getOutput"]["varPassed"]=array($conf["var"]);
|
|
|
4044 |
#參考資料:
|
|
|
4045 |
#無.
|
|
|
4046 |
#備註:
|
|
|
4047 |
#無.
|
|
|
4048 |
$getOutput=record::getOutput($conf["record::getOutput"]);
|
|
|
4049 |
unset($conf["record::getOutput"]);
|
|
|
4050 |
|
|
|
4051 |
#如果執行失敗
|
|
|
4052 |
if($getOutput["status"]==="false"){
|
|
|
4053 |
|
|
|
4054 |
#設置錯誤識別
|
|
|
4055 |
$result["status"]="false";
|
|
|
4056 |
|
|
|
4057 |
#設置錯誤訊息
|
|
|
4058 |
$result["error"]=$getOutput;
|
|
|
4059 |
|
|
|
4060 |
#回傳結果
|
|
|
4061 |
return $result;
|
|
|
4062 |
|
|
|
4063 |
}#if end
|
|
|
4064 |
|
|
|
4065 |
#取得輸出
|
|
|
4066 |
$result["content"]=$getOutput["content"];
|
|
|
4067 |
|
|
|
4068 |
#設置執行正常
|
|
|
4069 |
$result["status"]="true";
|
|
|
4070 |
|
|
|
4071 |
#回傳結果
|
|
|
4072 |
return $result;
|
|
|
4073 |
|
|
|
4074 |
}#functino toSource end
|
|
|
4075 |
|
|
|
4076 |
/*
|
|
|
4077 |
#函式說明:
|
|
|
4078 |
#隱藏元素中可能含有機密的內容.
|
|
|
4079 |
#回傳結果:
|
|
|
4080 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4081 |
#$result["content"],隱藏內容後的結果.
|
|
|
4082 |
#$result["function"],當前執行的函數
|
|
|
4083 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
4084 |
#必填參數:
|
|
|
4085 |
#$conf["params"],陣列,要處理的變數.
|
|
|
4086 |
$conf["params"]=;
|
|
|
4087 |
#可省略參數:
|
|
|
4088 |
#$conf["keyWords"],字串陣列,針對params中每一個的key,若擁有該陣列中任一元素的數值(關鍵字),則要將其內容隱藏,預設為array("password","key","secret").
|
|
|
4089 |
#$conf["keyWords"]=array("password","key","secret","Secret");
|
|
|
4090 |
#$conf["changeTo"],字串,將要隱藏的參數內容置換為什麼字串內容,預設為"[classified content]".
|
|
|
4091 |
#$conf["changeTo"]="[classified content]";
|
|
|
4092 |
#參考資料:
|
|
|
4093 |
#無.
|
|
|
4094 |
#備註:
|
|
|
4095 |
#目前不支援物件.
|
|
|
4096 |
*/
|
|
|
4097 |
public static function hideParams(&$conf){
|
|
|
4098 |
|
|
|
4099 |
#取得當前執行的函式
|
|
|
4100 |
$result["function"]=__FUNCTION__;
|
|
|
4101 |
|
|
|
4102 |
#取得使用的參數
|
|
|
4103 |
$result["argu"]=$conf;
|
|
|
4104 |
|
|
|
4105 |
#函式說明:
|
|
|
4106 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
4107 |
#回傳結果:
|
|
|
4108 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4109 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4110 |
#$result["function"],當前執行的函式名稱.
|
|
|
4111 |
#$result["argu"],設置給予的參數.
|
|
|
4112 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4113 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4114 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4115 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4116 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4117 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4118 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4119 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4120 |
#必填參數:
|
|
|
4121 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4122 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4123 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4124 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4125 |
#可省略參數:
|
|
|
4126 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4127 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("params");
|
|
|
4128 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4129 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
4130 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4131 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4132 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4133 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4134 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4135 |
#$conf["canBeEmpty"]=array();
|
|
|
4136 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4137 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("hideSecret");
|
|
|
4138 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4139 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("keyWords","changedTo");
|
|
|
4140 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4141 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
|
|
|
4142 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4143 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array("password","key","secret","Secret"),"[classified content]");
|
|
|
4144 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4145 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4146 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4147 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4148 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4149 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4150 |
#參考資料:
|
|
|
4151 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4152 |
#備註:
|
|
|
4153 |
#無.
|
|
|
4154 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4155 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4156 |
|
|
|
4157 |
#若執行失敗
|
|
|
4158 |
if($checkArguments["status"]==="false"){
|
|
|
4159 |
|
|
|
4160 |
#設置執行失敗
|
|
|
4161 |
$result["status"]="false";
|
|
|
4162 |
|
|
|
4163 |
#設置錯誤訊息
|
|
|
4164 |
$result["error"]=$checkArguments;
|
|
|
4165 |
|
|
|
4166 |
#回傳內容
|
|
|
4167 |
return $reuslt;
|
|
|
4168 |
|
|
|
4169 |
}#if end
|
|
|
4170 |
|
|
|
4171 |
#若檢查不通過
|
|
|
4172 |
if($checkArguments["passed"]==="false"){
|
|
|
4173 |
|
|
|
4174 |
#設置執行失敗
|
|
|
4175 |
$result["status"]="false";
|
|
|
4176 |
|
|
|
4177 |
#設置錯誤訊息
|
|
|
4178 |
$result["error"]=$checkArguments;
|
|
|
4179 |
|
|
|
4180 |
#回傳內容
|
|
|
4181 |
return $result;
|
|
|
4182 |
|
|
|
4183 |
}#if end
|
|
|
4184 |
|
|
|
4185 |
#初始化待處理的陣列變數
|
|
|
4186 |
$unprocessedArray=array(&$conf["params"]);
|
|
|
4187 |
|
|
|
4188 |
#針對陣列中每個元素
|
|
|
4189 |
while(isset($unprocessedArray[0])){
|
|
|
4190 |
|
|
|
4191 |
/*
|
|
|
4192 |
#debug
|
|
|
4193 |
echo "<p>";
|
|
|
4194 |
var_dump($unprocessedArray);
|
|
|
4195 |
*/
|
|
|
4196 |
|
|
|
4197 |
#取得當前元素
|
|
|
4198 |
$element=&$unprocessedArray[0];
|
|
|
4199 |
|
|
|
4200 |
/*
|
|
|
4201 |
#debug
|
|
|
4202 |
echo "<br>";
|
|
|
4203 |
var_dump(gettype($element));
|
|
|
4204 |
*/
|
|
|
4205 |
|
|
|
4206 |
#如果元素為陣列
|
|
|
4207 |
if(gettype($element)==="array"){
|
|
|
4208 |
|
|
|
4209 |
#針對每個變數
|
|
|
4210 |
foreach($element as $arrayKey=>$arrayVal){
|
|
|
4211 |
|
|
|
4212 |
/*
|
|
|
4213 |
#debug
|
|
|
4214 |
echo "<p>";
|
|
|
4215 |
echo "foreach in \$element, key=".$arrayKey."<br>";
|
|
|
4216 |
echo "content of \$element:".print_r($element,true);
|
|
|
4217 |
|
|
|
4218 |
#debug
|
|
|
4219 |
echo "<p>";
|
|
|
4220 |
echo "check key:".$arrayKey;
|
|
|
4221 |
*/
|
|
|
4222 |
|
|
|
4223 |
#函式說明:
|
|
|
4224 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
4225 |
#回傳結果:
|
|
|
4226 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗.
|
|
|
4227 |
#$result["error"],錯誤訊息.
|
|
|
4228 |
#$result["function"],當前執行的函數名稱.
|
|
|
4229 |
#$result["founded"],是否有找到的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字.
|
|
|
4230 |
#$result["foundedKeyWords"],找到的關鍵字.
|
|
|
4231 |
#$result["foundedAll"],是否有找到全部的關鍵字,"true"代表有;"false"代表沒有.
|
|
|
4232 |
#$result["argu"],使用的參數.
|
|
|
4233 |
#必填參數:
|
|
|
4234 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
4235 |
$conf["search::findManyKeyWords"]["keyWords"]=$conf["keyWords"];
|
|
|
4236 |
#$conf["string"],字串,要被搜尋的字串內容.
|
|
|
4237 |
$conf["search::findManyKeyWords"]["string"]=$arrayKey;
|
|
|
4238 |
#可省略參數:
|
|
|
4239 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合.
|
|
|
4240 |
#$conf["completeEqual"]="true";
|
|
|
4241 |
#參考資料:
|
|
|
4242 |
#無.
|
|
|
4243 |
#備註:
|
|
|
4244 |
#無.
|
|
|
4245 |
$findManyKeyWords=search::findManyKeyWords($conf["search::findManyKeyWords"]);
|
|
|
4246 |
unset($conf["search::findManyKeyWords"]);
|
|
|
4247 |
|
|
|
4248 |
/*
|
|
|
4249 |
#debug
|
|
|
4250 |
echo "<p>";
|
|
|
4251 |
echo "content of \$findManyKeyWords:<br>";
|
|
|
4252 |
var_dump($findManyKeyWords);
|
|
|
4253 |
*/
|
|
|
4254 |
|
|
|
4255 |
#若執行失敗
|
|
|
4256 |
if($findManyKeyWords["status"]==="false"){
|
|
|
4257 |
|
|
|
4258 |
#設置執行失敗
|
|
|
4259 |
$result["status"]="false";
|
|
|
4260 |
|
|
|
4261 |
#設置錯誤訊息
|
|
|
4262 |
$result["error"]=$findManyKeyWords;
|
|
|
4263 |
|
|
|
4264 |
#回傳內容
|
|
|
4265 |
return $reuslt;
|
|
|
4266 |
|
|
|
4267 |
}#if end
|
|
|
4268 |
|
|
|
4269 |
#若有符合的關鍵字
|
|
|
4270 |
if($findManyKeyWords["founded"]==="true"){
|
|
|
4271 |
|
|
|
4272 |
/*
|
|
|
4273 |
#deubg
|
|
|
4274 |
echo "<p>";
|
|
|
4275 |
echo "置換 key 為 ".$arrayKey." 者的內容為 ".$conf["changedTo"];
|
|
|
4276 |
*/
|
|
|
4277 |
|
|
|
4278 |
#替換其內容
|
|
|
4279 |
$element[$arrayKey]=$conf["changedTo"];
|
|
|
4280 |
|
|
|
4281 |
/*
|
|
|
4282 |
#debug
|
|
|
4283 |
echo "<p>";
|
|
|
4284 |
echo "替換其內容後 為 ".print_r($element,true);
|
|
|
4285 |
*/
|
|
|
4286 |
|
|
|
4287 |
#針對下個元素
|
|
|
4288 |
continue;
|
|
|
4289 |
|
|
|
4290 |
}#if end
|
|
|
4291 |
|
|
|
4292 |
#如果數值為陣列
|
|
|
4293 |
if(gettype($arrayVal)==="array"){
|
|
|
4294 |
|
|
|
4295 |
/*
|
|
|
4296 |
#deubg
|
|
|
4297 |
echo "<p>";
|
|
|
4298 |
echo "新增待處理的陣列 其 key 為 ".$arrayKey;
|
|
|
4299 |
*/
|
|
|
4300 |
|
|
|
4301 |
#儲存到待處理的陣列中
|
|
|
4302 |
$unprocessedArray[]=&$element[$arrayKey];
|
|
|
4303 |
|
|
|
4304 |
/*
|
|
|
4305 |
#debug
|
|
|
4306 |
echo "<p>";
|
|
|
4307 |
echo "新增待處理的陣列後 其 內容 為 ".print_r($unprocessedArray,true);
|
|
|
4308 |
*/
|
|
|
4309 |
|
|
|
4310 |
}#if end
|
|
|
4311 |
|
|
|
4312 |
}#foreach end
|
|
|
4313 |
|
|
|
4314 |
}#if end
|
|
|
4315 |
|
|
|
4316 |
/*
|
|
|
4317 |
#debug
|
|
|
4318 |
echo "<br>";
|
|
|
4319 |
echo "before array_shift, count of \$unprocessedArray:".count($unprocessedArray);
|
|
|
4320 |
echo "<br>";
|
|
|
4321 |
var_dump($unprocessedArray);
|
|
|
4322 |
*/
|
|
|
4323 |
|
|
|
4324 |
#將第一個元素移除
|
|
|
4325 |
array_shift($unprocessedArray);
|
|
|
4326 |
|
|
|
4327 |
/*
|
|
|
4328 |
#debug
|
|
|
4329 |
echo "<br>";
|
|
|
4330 |
echo "after array_shift, count of \$unprocessedArray:".count($unprocessedArray);
|
|
|
4331 |
echo "<br>";
|
|
|
4332 |
var_dump($unprocessedArray);
|
|
|
4333 |
echo "<hr>";
|
|
|
4334 |
*/
|
|
|
4335 |
|
|
|
4336 |
}#while end
|
|
|
4337 |
|
|
|
4338 |
#設置回傳內容
|
|
|
4339 |
$result["content"]=$conf["params"];
|
|
|
4340 |
|
|
|
4341 |
#設置執行正常
|
|
|
4342 |
$result["status"]="true";
|
|
|
4343 |
|
|
|
4344 |
#回傳結果
|
|
|
4345 |
return $result;
|
|
|
4346 |
|
|
|
4347 |
}#function hideParams end
|
|
|
4348 |
|
|
|
4349 |
/*
|
|
|
4350 |
#函式說明:
|
|
|
4351 |
#取得簡單的錯誤訊息
|
|
|
4352 |
#回傳結果:
|
|
|
4353 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4354 |
#$result["content"],結果.
|
|
|
4355 |
#$result["function"],當前執行的函數
|
|
|
4356 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
4357 |
#必填參數:
|
|
|
4358 |
#$conf["error"],陣列,要處理的變數.
|
|
|
4359 |
$conf["error"]=array();
|
|
|
4360 |
#可省略參數:
|
|
|
4361 |
#無
|
|
|
4362 |
#參考資料:
|
|
|
4363 |
#無.
|
|
|
4364 |
#備註:
|
|
|
4365 |
#無.
|
|
|
4366 |
*/
|
|
|
4367 |
public static function getSimpleError(&$conf){
|
|
|
4368 |
|
|
|
4369 |
#var_dump($conf);
|
|
|
4370 |
|
|
|
4371 |
#初始化要回傳的結果
|
|
|
4372 |
$result=array();
|
|
|
4373 |
|
|
|
4374 |
#取得當前執行的函數名稱
|
|
|
4375 |
$result["function"]=__FUNCTION__;
|
|
|
4376 |
|
|
|
4377 |
#如果沒有參數
|
|
|
4378 |
if(func_num_args()==0){
|
|
|
4379 |
|
|
|
4380 |
#設置執行失敗
|
|
|
4381 |
$result["status"]="false";
|
|
|
4382 |
|
|
|
4383 |
#設置執行錯誤訊息
|
|
|
4384 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
4385 |
|
|
|
4386 |
#無窮迴圈
|
|
|
4387 |
while(true){
|
|
|
4388 |
|
|
|
4389 |
#遞迴執行
|
|
|
4390 |
$conf["self::getSimpleError"]["error"]=$result;
|
|
|
4391 |
$simpleError=self::getSimpleError($conf["self::getSimpleError"]);
|
|
|
4392 |
unset($conf["self::getSimpleError"]);
|
|
|
4393 |
|
|
|
4394 |
#如果執行失敗
|
|
|
4395 |
if($simpleError["status"]==="false"){
|
|
|
4396 |
|
|
|
4397 |
#設置執行失敗
|
|
|
4398 |
$result["status"]="false";
|
|
|
4399 |
|
|
|
4400 |
#設置執行錯誤訊息
|
|
|
4401 |
$result["error"]=$simpleError;
|
|
|
4402 |
|
|
|
4403 |
#下一輪
|
|
|
4404 |
continue;
|
|
|
4405 |
|
|
|
4406 |
}#if end
|
|
|
4407 |
|
|
|
4408 |
#結束 while
|
|
|
4409 |
break;
|
|
|
4410 |
|
|
|
4411 |
}#while end
|
|
|
4412 |
|
|
|
4413 |
return $result;
|
|
|
4414 |
|
|
|
4415 |
}#if end
|
|
|
4416 |
|
|
|
4417 |
#取得參數
|
|
|
4418 |
$result["argu"]=$conf;
|
|
|
4419 |
|
|
|
4420 |
#如果 $conf 不為陣列
|
|
|
4421 |
if(gettype($conf)!=="array"){
|
|
|
4422 |
|
|
|
4423 |
#設置執行失敗
|
|
|
4424 |
$result["status"]="false";
|
|
|
4425 |
|
|
|
4426 |
#設置執行錯誤訊息
|
|
|
4427 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4428 |
|
|
|
4429 |
#如果傳入的參數為 null
|
|
|
4430 |
if(is_null($conf)){
|
|
|
4431 |
|
|
|
4432 |
#設置執行錯誤訊息
|
|
|
4433 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4434 |
|
|
|
4435 |
}#if end
|
|
|
4436 |
|
|
|
4437 |
#無窮迴圈
|
|
|
4438 |
while(true){
|
|
|
4439 |
|
|
|
4440 |
#遞迴執行
|
|
|
4441 |
$conf["self::getSimpleError"]["error"]=$result;
|
|
|
4442 |
$simpleError=self::getSimpleError($conf["self::getSimpleError"]);
|
|
|
4443 |
unset($conf["self::getSimpleError"]);
|
|
|
4444 |
|
|
|
4445 |
#如果執行失敗
|
|
|
4446 |
if($simpleError["status"]==="false"){
|
|
|
4447 |
|
|
|
4448 |
#設置執行失敗
|
|
|
4449 |
$result["status"]="false";
|
|
|
4450 |
|
|
|
4451 |
#設置執行錯誤訊息
|
|
|
4452 |
$result["error"]=$simpleError;
|
|
|
4453 |
|
|
|
4454 |
#下一輪
|
|
|
4455 |
continue;
|
|
|
4456 |
|
|
|
4457 |
}#if end
|
|
|
4458 |
|
|
|
4459 |
#結束 while
|
|
|
4460 |
break;
|
|
|
4461 |
|
|
|
4462 |
}#while end
|
|
|
4463 |
|
|
|
4464 |
#回傳結果
|
|
|
4465 |
return $result;
|
|
|
4466 |
|
|
|
4467 |
}#if end
|
|
|
4468 |
|
|
|
4469 |
#函式說明:
|
|
|
4470 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
4471 |
#回傳結果:
|
|
|
4472 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4473 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4474 |
#$result["function"],當前執行的函式名稱.
|
|
|
4475 |
#$result["argu"],設置給予的參數.
|
|
|
4476 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4477 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4478 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4479 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4480 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4481 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4482 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4483 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4484 |
#必填參數:
|
|
|
4485 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4486 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4487 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4488 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4489 |
#可省略參數:
|
|
|
4490 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4491 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("error");
|
|
|
4492 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4493 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
4494 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4495 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4496 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4497 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("gw_primary_ids");
|
|
|
4498 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4499 |
#$conf["canBeEmpty"]=array();
|
|
|
4500 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4501 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4502 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4503 |
#$conf["skipableVariableName"]=array();
|
|
|
4504 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4505 |
#$conf["skipableVariableType"]=array();
|
|
|
4506 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4507 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4508 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4509 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4510 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4511 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4512 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4513 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4514 |
#參考資料:
|
|
|
4515 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4516 |
#備註:
|
|
|
4517 |
#無.
|
|
|
4518 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4519 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4520 |
|
|
|
4521 |
#如果執行失敗
|
|
|
4522 |
if($checkArguments["status"]==="false"){
|
|
|
4523 |
|
|
|
4524 |
#設置執行失敗
|
|
|
4525 |
$result["status"]="false";
|
|
|
4526 |
|
|
|
4527 |
#設置執行錯誤訊息
|
|
|
4528 |
$result["error"]=$checkArguments;
|
|
|
4529 |
|
|
|
4530 |
#無窮迴圈
|
|
|
4531 |
while(true){
|
|
|
4532 |
|
|
|
4533 |
#遞迴執行
|
|
|
4534 |
$conf["self::getSimpleError"]["error"]=$result;
|
|
|
4535 |
$simpleError=self::getSimpleError($conf["self::getSimpleError"]);
|
|
|
4536 |
unset($conf["self::getSimpleError"]);
|
|
|
4537 |
|
|
|
4538 |
#如果執行失敗
|
|
|
4539 |
if($simpleError["status"]==="false"){
|
|
|
4540 |
|
|
|
4541 |
#設置執行失敗
|
|
|
4542 |
$result["status"]="false";
|
|
|
4543 |
|
|
|
4544 |
#設置執行錯誤訊息
|
|
|
4545 |
$result["error"]=$simpleError;
|
|
|
4546 |
|
|
|
4547 |
#下一輪
|
|
|
4548 |
continue;
|
|
|
4549 |
|
|
|
4550 |
}#if end
|
|
|
4551 |
|
|
|
4552 |
#如果檢查不通過
|
|
|
4553 |
if($simpleError["passed"]==="false"){
|
|
|
4554 |
|
|
|
4555 |
#設置執行失敗
|
|
|
4556 |
$result["status"]="false";
|
|
|
4557 |
|
|
|
4558 |
#設置執行錯誤訊息
|
|
|
4559 |
$result["error"]=$simpleError;
|
|
|
4560 |
|
|
|
4561 |
#下一輪
|
|
|
4562 |
continue;
|
|
|
4563 |
|
|
|
4564 |
}#if end
|
|
|
4565 |
|
|
|
4566 |
#結束 while
|
|
|
4567 |
break;
|
|
|
4568 |
|
|
|
4569 |
}#while end
|
|
|
4570 |
|
|
|
4571 |
#取得 simpleError
|
|
|
4572 |
$result["simpleError"]=$simpleError["content"];
|
|
|
4573 |
|
|
|
4574 |
#回傳結果
|
|
|
4575 |
return $result;
|
|
|
4576 |
|
|
|
4577 |
}#if end
|
|
|
4578 |
|
|
|
4579 |
#如果執行失敗
|
|
|
4580 |
if($checkArguments["passed"]==="false"){
|
|
|
4581 |
|
|
|
4582 |
#設置執行失敗
|
|
|
4583 |
$result["status"]="false";
|
|
|
4584 |
|
|
|
4585 |
#設置執行錯誤訊息
|
|
|
4586 |
$result["error"]=$checkArguments;
|
|
|
4587 |
|
|
|
4588 |
#無窮迴圈
|
|
|
4589 |
while(true){
|
|
|
4590 |
|
|
|
4591 |
#遞迴執行
|
|
|
4592 |
$conf["self::getSimpleError"]["error"]=$result;
|
|
|
4593 |
$simpleError=self::getSimpleError($conf["self::getSimpleError"]);
|
|
|
4594 |
unset($conf["self::getSimpleError"]);
|
|
|
4595 |
|
|
|
4596 |
#如果執行失敗
|
|
|
4597 |
if($simpleError["status"]==="false"){
|
|
|
4598 |
|
|
|
4599 |
#設置執行失敗
|
|
|
4600 |
$result["status"]="false";
|
|
|
4601 |
|
|
|
4602 |
#設置執行錯誤訊息
|
|
|
4603 |
$result["error"]=$simpleError;
|
|
|
4604 |
|
|
|
4605 |
#下一輪
|
|
|
4606 |
continue;
|
|
|
4607 |
|
|
|
4608 |
}#if end
|
|
|
4609 |
|
|
|
4610 |
#如果檢查不通過
|
|
|
4611 |
if($simpleError["passed"]==="false"){
|
|
|
4612 |
|
|
|
4613 |
#設置執行失敗
|
|
|
4614 |
$result["status"]="false";
|
|
|
4615 |
|
|
|
4616 |
#設置執行錯誤訊息
|
|
|
4617 |
$result["error"]=$simpleError;
|
|
|
4618 |
|
|
|
4619 |
#下一輪
|
|
|
4620 |
continue;
|
|
|
4621 |
|
|
|
4622 |
}#if end
|
|
|
4623 |
|
|
|
4624 |
#結束 while
|
|
|
4625 |
break;
|
|
|
4626 |
|
|
|
4627 |
}#while end
|
|
|
4628 |
|
|
|
4629 |
#取得 simpleError
|
|
|
4630 |
$result["simpleError"]=$simpleError["content"];
|
|
|
4631 |
|
|
|
4632 |
#回傳結果
|
|
|
4633 |
return $result;
|
|
|
4634 |
|
|
|
4635 |
}#if end
|
|
|
4636 |
|
|
|
4637 |
#var_dump($result);
|
|
|
4638 |
|
|
|
4639 |
#初始化簡單的錯誤
|
|
|
4640 |
$result["content"]=&$conf["error"];
|
|
|
4641 |
|
|
|
4642 |
#如果底下有 error 元素
|
|
|
4643 |
while(isset($result["content"]["error"])){
|
|
|
4644 |
|
|
|
4645 |
#var_dump($result["content"]["error"]);
|
|
|
4646 |
|
|
|
4647 |
#取得其位置
|
|
|
4648 |
$result["content"]=&$result["content"]["error"];
|
|
|
4649 |
|
|
|
4650 |
}#while end
|
|
|
4651 |
|
|
|
4652 |
#初始化新的結果
|
|
|
4653 |
$newContentStr="";
|
|
|
4654 |
|
|
|
4655 |
#如果 content 不是字串
|
|
|
4656 |
if(gettype($result["content"])!=="string"){
|
|
|
4657 |
|
|
|
4658 |
#var_dump($result["content"]);
|
|
|
4659 |
|
|
|
4660 |
#針對每個錯誤訊息
|
|
|
4661 |
foreach($result["content"] as $errorLine){
|
|
|
4662 |
|
|
|
4663 |
#如果不是字串
|
|
|
4664 |
if(gettype($errorLine)!=="string"){
|
|
|
4665 |
|
|
|
4666 |
#將陣列轉換成字串
|
|
|
4667 |
$errorLine=print_r($errorLine,true);
|
|
|
4668 |
|
|
|
4669 |
}#if end
|
|
|
4670 |
|
|
|
4671 |
#串接結果
|
|
|
4672 |
$newContentStr=$newContentStr.$errorLine.PHP_EOL;
|
|
|
4673 |
|
|
|
4674 |
}#foreache end
|
|
|
4675 |
|
|
|
4676 |
}#if end
|
|
|
4677 |
|
|
|
4678 |
#設置結果內容
|
|
|
4679 |
$result["content"]=$newContentStr;
|
|
|
4680 |
|
|
|
4681 |
#設置執行正常
|
|
|
4682 |
$result["status"]=true;
|
|
|
4683 |
|
|
|
4684 |
#回傳結果
|
|
|
4685 |
return $result;
|
|
|
4686 |
|
|
|
4687 |
}#function getSimpleError end
|
|
|
4688 |
|
|
|
4689 |
/*
|
|
|
4690 |
#函式說明:
|
|
|
4691 |
#檢查字串是否符合指定格式
|
|
|
4692 |
#回傳結果:
|
|
|
4693 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4694 |
#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.
|
|
|
4695 |
#$result["content"],詳細結果訊息陣列,若passed為"false"則會有該內容.
|
|
|
4696 |
#$result["newInputArgu"],剩下尚未檢驗格式的input.
|
|
|
4697 |
#$result["function"],當前執行的函數.
|
|
|
4698 |
#$result["error"],涵式錯誤訊息陣列.
|
|
|
4699 |
#必填參數:
|
|
|
4700 |
#$conf["input"],字串,要檢查格式的字串.
|
|
|
4701 |
$conf["input"]="";
|
|
|
4702 |
#可省略參數:
|
|
|
4703 |
#$conf["equalWith"],字串,輸入字串是否等於該參數內容.
|
|
|
4704 |
#$conf["equalWith"]="";
|
|
|
4705 |
#$conf["startWith"],字串,開頭要是什麼字串內容.
|
|
|
4706 |
#$conf["startWith"]="";
|
|
|
4707 |
#$conf["endWith"],字串,結尾要是什麼字串內容.
|
|
|
4708 |
#$conf["endWith"]="";
|
|
|
4709 |
#$conf["centerWith"],字串,非開頭(預設無,若有指定startWith參數,則為該參數內容)跟結尾(預設無,若有指定endWith參數,則為該參數內容)的內容中要有什麼字串.
|
|
|
4710 |
#$conf["centerWith"]="";
|
|
|
4711 |
#$conf["length"],字串整數,字串的長度要多少(bytes).
|
|
|
4712 |
#$conf["length"]="";
|
|
|
4713 |
#$conf["lengthGrapheme"],字串整數,字串的長度要多少字位(grapheme).
|
|
|
4714 |
#$conf["lengthGrapheme"]="";
|
|
|
4715 |
#$conf["section"],字串陣列,元素數量代表,輸入字串的格式可以區分成多少段.每個元素為本函式的參數陣列剔除input跟section參數.
|
|
|
4716 |
#$conf["section"]=array();
|
|
|
4717 |
#參考資料:
|
|
|
4718 |
#grapheme_strlen=>https://www.php.net/manual/en/function.grapheme-strlen.php
|
|
|
4719 |
#grapheme/字位/可以書寫的最小單位=>https://zh.wikipedia.org/zh-tw/%E5%AD%97%E4%BD%8D
|
|
|
4720 |
#grapheme_substr=>https://www.php.net/manual/en/function.grapheme-substr.php
|
|
|
4721 |
#備註:
|
|
|
4722 |
#無.
|
|
|
4723 |
*/
|
|
|
4724 |
public static function checkStringFormat(&$conf){
|
|
|
4725 |
|
|
|
4726 |
#初始化要回傳的內容
|
|
|
4727 |
$result=array();
|
|
|
4728 |
|
|
|
4729 |
#取得當前執行的函數名稱
|
|
|
4730 |
$result["function"]=__FUNCTION__;
|
|
|
4731 |
|
|
|
4732 |
#如果 $conf 不為陣列
|
|
|
4733 |
if(gettype($conf)!="array"){
|
|
|
4734 |
|
|
|
4735 |
#設置執行失敗
|
|
|
4736 |
$result["status"]="false";
|
|
|
4737 |
|
|
|
4738 |
#設置執行錯誤訊息
|
|
|
4739 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4740 |
|
|
|
4741 |
#如果傳入的參數為 null
|
|
|
4742 |
if($conf==null){
|
|
|
4743 |
|
|
|
4744 |
#設置執行錯誤訊息
|
|
|
4745 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4746 |
|
|
|
4747 |
}#if end
|
|
|
4748 |
|
|
|
4749 |
#回傳結果
|
|
|
4750 |
return $result;
|
|
|
4751 |
|
|
|
4752 |
}#if end
|
|
|
4753 |
|
|
|
4754 |
#取得參數
|
|
|
4755 |
$result["argu"]=$conf;
|
|
|
4756 |
|
|
|
4757 |
#函式說明:
|
|
|
4758 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
4759 |
#回傳結果:
|
|
|
4760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4761 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
4762 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
4763 |
#$result["function"],當前執行的函式名稱.
|
|
|
4764 |
#$result["argu"],設置給予的參數.
|
|
|
4765 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4766 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4767 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4768 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4769 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4770 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4771 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4772 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4773 |
#必填參數:
|
|
|
4774 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4775 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4776 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4777 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4778 |
#可省略參數:
|
|
|
4779 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4780 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
4781 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4782 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4783 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4784 |
#$conf["variadble::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4785 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4786 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4787 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4788 |
#$conf["canBeEmpty"]=array();
|
|
|
4789 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4790 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("equalWith","startWith","centerWith","endWith","length","lengthGrapheme","section");
|
|
|
4791 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4792 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("equalWith","startWith","centerWith","endWith","length","lengthGrapheme","section");
|
|
|
4793 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4794 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","array");
|
|
|
4795 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4796 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4797 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4798 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4799 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4800 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4801 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
4802 |
$conf["variableCheck::checkArguments"]["disallowAllSkipableVarNotExist"]="true";
|
|
|
4803 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4804 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4805 |
#參考資料:
|
|
|
4806 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4807 |
#備註:
|
|
|
4808 |
#無.
|
|
|
4809 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4810 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4811 |
|
|
|
4812 |
#如果檢查失敗
|
|
|
4813 |
if($checkArguments["status"]==="false"){
|
|
|
4814 |
|
|
|
4815 |
#設置錯誤識別
|
|
|
4816 |
$result["status"]="false";
|
|
|
4817 |
|
|
|
4818 |
#設置錯誤訊息
|
|
|
4819 |
$result["error"]=$checkArguments;
|
|
|
4820 |
|
|
|
4821 |
#回傳結果
|
|
|
4822 |
return $result;
|
|
|
4823 |
|
|
|
4824 |
}#if end
|
|
|
4825 |
|
|
|
4826 |
#如果檢查不通過
|
|
|
4827 |
if($checkArguments["passed"]==="false"){
|
|
|
4828 |
|
|
|
4829 |
#設置錯誤識別
|
|
|
4830 |
$result["status"]="false";
|
|
|
4831 |
|
|
|
4832 |
#設置錯誤訊息
|
|
|
4833 |
$result["error"]=$checkArguments;
|
|
|
4834 |
|
|
|
4835 |
#回傳結果
|
|
|
4836 |
return $result;
|
|
|
4837 |
|
|
|
4838 |
}#if end
|
|
|
4839 |
|
|
|
4840 |
#預設剩下未檢查格式的input為空字串
|
|
|
4841 |
$result["newInputArgu"]="";
|
|
|
4842 |
|
|
|
4843 |
#如果存在分段的格式設定
|
|
|
4844 |
if(isset($conf["section"])){
|
|
|
4845 |
|
|
|
4846 |
#預設都是尚未檢驗的字串
|
|
|
4847 |
$newInputArgu=$conf["input"];
|
|
|
4848 |
|
|
|
4849 |
#針對每段
|
|
|
4850 |
foreach($conf["section"] as $index => $sec){
|
|
|
4851 |
|
|
|
4852 |
#更新input參數
|
|
|
4853 |
$sec["input"]=$newInputArgu;
|
|
|
4854 |
|
|
|
4855 |
#處理該section
|
|
|
4856 |
#函式說明:
|
|
|
4857 |
#檢查字串是否符合指定格式
|
|
|
4858 |
#回傳結果:
|
|
|
4859 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4860 |
#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.
|
|
|
4861 |
#$result["content"],詳細結果訊息陣列,若passed為"false"則會有該內容.
|
|
|
4862 |
#$result["newInputArgu"],剩下尚未檢驗格式的input.
|
|
|
4863 |
#$result["function"],當前執行的函數.
|
|
|
4864 |
#$result["error"],涵式錯誤訊息陣列.
|
|
|
4865 |
#必填參數:
|
|
|
4866 |
#$conf["input"],字串,要檢查格式的字串.
|
|
|
4867 |
#$conf["variableCheck::checkStringFormat"]["input"]=$newInputArgu;
|
|
|
4868 |
#可省略參數:
|
|
|
4869 |
#$conf["equalWith"],字串,輸入字串是否等於該參數內容.
|
|
|
4870 |
#$conf["equalWith"]="";
|
|
|
4871 |
#$conf["startWith"],字串,開頭要是什麼字串內容.
|
|
|
4872 |
#$conf["startWith"]="";
|
|
|
4873 |
#$conf["endWith"],字串,結尾要是什麼字串內容.
|
|
|
4874 |
#$conf["endWith"]="";
|
|
|
4875 |
#$conf["centerWith"],字串,非開頭(預設無,若有指定startWith參數,則為該參數內容)跟結尾(預設無,若有指定endWith參數,則為該參數內容)的內容中要有什麼字串.
|
|
|
4876 |
#$conf["centerWith"]="";
|
|
|
4877 |
#$conf["length"],字串整數,字串的長度要多少(bytes).
|
|
|
4878 |
#$conf["length"]="";
|
|
|
4879 |
#$conf["lengthGrapheme"],字串整數,字串的長度要多少字位(grapheme).
|
|
|
4880 |
#$conf["lengthGrapheme"]="";
|
|
|
4881 |
#$conf["variableCheck::checkStringFormat"]["section"]=$nextSectionArgu;
|
|
|
4882 |
#參考資料:
|
|
|
4883 |
#grapheme_strlen=>https://www.php.net/manual/en/function.grapheme-strlen.php
|
|
|
4884 |
#grapheme/字位/可以書寫的最小單位=>https://zh.wikipedia.org/zh-tw/%E5%AD%97%E4%BD%8D
|
|
|
4885 |
#備註:
|
|
|
4886 |
#無.
|
|
|
4887 |
$conf["variableCheck::checkStringFormat"]=$sec;
|
|
|
4888 |
$checkStringFormat=variableCheck::checkStringFormat($conf["variableCheck::checkStringFormat"]);
|
|
|
4889 |
unset($conf["variableCheck::checkStringFormat"]);
|
|
|
4890 |
|
|
|
4891 |
#如果執行失敗
|
|
|
4892 |
if($checkStringFormat["status"]=="false"){
|
|
|
4893 |
|
|
|
4894 |
#設置錯誤識別
|
|
|
4895 |
$result["status"]="false";
|
|
|
4896 |
|
|
|
4897 |
#設置錯誤訊息
|
|
|
4898 |
$result["error"]=$checkStringFormat;
|
|
|
4899 |
|
|
|
4900 |
#回傳結果
|
|
|
4901 |
return $result;
|
|
|
4902 |
|
|
|
4903 |
}#if end
|
|
|
4904 |
|
|
|
4905 |
#如果不通過
|
|
|
4906 |
if($checkStringFormat["passed"]=="false"){
|
|
|
4907 |
|
|
|
4908 |
#回傳結果
|
|
|
4909 |
return $checkStringFormat;
|
|
|
4910 |
|
|
|
4911 |
}#if end
|
|
|
4912 |
|
|
|
4913 |
#取得新的input參數
|
|
|
4914 |
$newInputArgu=$checkStringFormat["newInputArgu"];
|
|
|
4915 |
|
|
|
4916 |
}#foreach end
|
|
|
4917 |
|
|
|
4918 |
}#if end
|
|
|
4919 |
|
|
|
4920 |
#到這邊代表不存在分段的格式設定
|
|
|
4921 |
|
|
|
4922 |
#初始化關鍵字
|
|
|
4923 |
$keywords=array();
|
|
|
4924 |
|
|
|
4925 |
#如果有 startWith
|
|
|
4926 |
if(isset($conf["startWith"])){
|
|
|
4927 |
|
|
|
4928 |
#設置關鍵字
|
|
|
4929 |
$keywords[]=$conf["startWith"];
|
|
|
4930 |
|
|
|
4931 |
}#if end
|
|
|
4932 |
|
|
|
4933 |
#如果有 centerWith
|
|
|
4934 |
if(isset($conf["centerWith"])){
|
|
|
4935 |
|
|
|
4936 |
#設置關鍵字
|
|
|
4937 |
$keywords[]=$conf["centerWith"];
|
|
|
4938 |
|
|
|
4939 |
}#if end
|
|
|
4940 |
|
|
|
4941 |
#如果有 endWith
|
|
|
4942 |
if(isset($conf["endWith"])){
|
|
|
4943 |
|
|
|
4944 |
#設置關鍵字
|
|
|
4945 |
$keywords[]=$conf["endWith"];
|
|
|
4946 |
|
|
|
4947 |
}#if end
|
|
|
4948 |
|
|
|
4949 |
#如果存在關鍵字
|
|
|
4950 |
if(!empty($keywords)){
|
|
|
4951 |
|
|
|
4952 |
#若有指定bytes長度
|
|
|
4953 |
if(isset($conf["length"])){
|
|
|
4954 |
|
|
|
4955 |
#取得輸入的字串長度
|
|
|
4956 |
$length=strlen($conf["input"]);
|
|
|
4957 |
|
|
|
4958 |
#如果長度不足
|
|
|
4959 |
if($length<(int)$conf["length"]){
|
|
|
4960 |
|
|
|
4961 |
#設置執行正常
|
|
|
4962 |
$result["status"]="true";
|
|
|
4963 |
|
|
|
4964 |
#設置檢查不通過
|
|
|
4965 |
$result["passed"]="false";
|
|
|
4966 |
|
|
|
4967 |
#設置詳細結果訊息陣列.
|
|
|
4968 |
$result["content"][]="input參數(".$conf["input"].")的bytes長度(".$length.")小於length參數(".$conf["length"].")";
|
|
|
4969 |
|
|
|
4970 |
#回傳結果
|
|
|
4971 |
return $result;
|
|
|
4972 |
|
|
|
4973 |
}#if end
|
|
|
4974 |
|
|
|
4975 |
#函式說明:
|
|
|
4976 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
4977 |
#回傳結果:
|
|
|
4978 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4979 |
#$result["error"],錯誤訊息陣列.
|
|
|
4980 |
#$result["function"],當前執行的函數名稱.
|
|
|
4981 |
#$result["content"],分割好的內容陣列.
|
|
|
4982 |
#$result["length"],unicode字串的長度.
|
|
|
4983 |
#必填參數:
|
|
|
4984 |
#$conf["str"],字串",要分割的字串.
|
|
|
4985 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["input"];
|
|
|
4986 |
#可省略參數:
|
|
|
4987 |
#$conf["length"],整數,分割的長度.
|
|
|
4988 |
#$conf["stringProcess::str_split_unicode"]["length"]=(int)$conf["length"];
|
|
|
4989 |
#參考資料:
|
|
|
4990 |
#http://php.net/manual/en/function.str-split.php
|
|
|
4991 |
#備註:
|
|
|
4992 |
#無.
|
|
|
4993 |
$str_split_unicode=stringProcess::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
4994 |
unset($conf["stringProcess::str_split_unicode"]);
|
|
|
4995 |
|
|
|
4996 |
#如果執行失敗
|
|
|
4997 |
if($str_split_unicode["status"]==="false"){
|
|
|
4998 |
|
|
|
4999 |
#設置執行失敗
|
|
|
5000 |
$result["status"]="false";
|
|
|
5001 |
|
|
|
5002 |
#設置執行錯誤訊息
|
|
|
5003 |
$result["error"]=$str_split_unicode;
|
|
|
5004 |
|
|
|
5005 |
#回傳結果
|
|
|
5006 |
return $result;
|
|
|
5007 |
|
|
|
5008 |
}#if end
|
|
|
5009 |
|
|
|
5010 |
#初始化給search::findKeyWordsPosition的input參數
|
|
|
5011 |
$newInputArguForFindKeyWordsPosition="";
|
|
|
5012 |
|
|
|
5013 |
#初始化給variableCheck::checkStringFormat的input參數
|
|
|
5014 |
$newInputArgu="";
|
|
|
5015 |
|
|
|
5016 |
#針對剩下的每個bytes
|
|
|
5017 |
foreach($str_split_unicode["content"] as $index=>$splitedStr){
|
|
|
5018 |
|
|
|
5019 |
#屬於findKeyWordsPosition的input參數
|
|
|
5020 |
if($index<(int)$conf["length"]){
|
|
|
5021 |
|
|
|
5022 |
#串接新的input參數bytes
|
|
|
5023 |
$newInputArguForFindKeyWordsPosition=$newInputArguForFindKeyWordsPosition.$splitedStr;
|
|
|
5024 |
|
|
|
5025 |
}#if end
|
|
|
5026 |
|
|
|
5027 |
#反之
|
|
|
5028 |
else{
|
|
|
5029 |
|
|
|
5030 |
#串接新的input參數bytes
|
|
|
5031 |
$newInputArgu=$newInputArgu.$splitedStr;
|
|
|
5032 |
|
|
|
5033 |
}#else end
|
|
|
5034 |
|
|
|
5035 |
}#foreach end
|
|
|
5036 |
|
|
|
5037 |
}#if end
|
|
|
5038 |
|
|
|
5039 |
#反之不存在指定bytes長度
|
|
|
5040 |
|
|
|
5041 |
#但有指定字位長度
|
|
|
5042 |
else if(isset($conf["lengthGrapheme"])){
|
|
|
5043 |
|
|
|
5044 |
#取得輸入的字位長度
|
|
|
5045 |
$grapheme_strlen=grapheme_strlen($conf["input"]);
|
|
|
5046 |
|
|
|
5047 |
#如果長度不足
|
|
|
5048 |
if($grapheme_strlen>(int)$conf["lengthGrapheme"]){
|
|
|
5049 |
|
|
|
5050 |
#設置執行正常
|
|
|
5051 |
$result["status"]="true";
|
|
|
5052 |
|
|
|
5053 |
#設置檢查不通過
|
|
|
5054 |
$result["passed"]="false";
|
|
|
5055 |
|
|
|
5056 |
#設置詳細結果訊息陣列.
|
|
|
5057 |
$result["content"][]="input參數(".$conf["input"].")的字位長度(".$grapheme_strlen.")小於lengthGrapheme參數(".$conf["lengthGrapheme"].")";
|
|
|
5058 |
|
|
|
5059 |
#回傳結果
|
|
|
5060 |
return $result;
|
|
|
5061 |
|
|
|
5062 |
}#if end
|
|
|
5063 |
|
|
|
5064 |
#初始化給search::findKeyWordsPosition的input參數
|
|
|
5065 |
$arguForFindKeyWordsPosition=grapheme_substr($conf["input"],0,$conf["lengthGrapheme"]);
|
|
|
5066 |
|
|
|
5067 |
#初始化給variableCheck::checkStringFormat的input參數
|
|
|
5068 |
$newInputArgu=grapheme_substr($conf["input"],$conf["lengthGrapheme"]);
|
|
|
5069 |
|
|
|
5070 |
}#if end
|
|
|
5071 |
|
|
|
5072 |
#函式說明:
|
|
|
5073 |
#取得關鍵字在字串的哪個位置(字首,字尾,中間)
|
|
|
5074 |
#回傳結果:
|
|
|
5075 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
5076 |
#$result["error"],錯誤訊息陣列.
|
|
|
5077 |
#$result["function"],當前執行的函數名稱.
|
|
|
5078 |
#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
|
|
|
5079 |
#$result["argu"],傳入的參數.
|
|
|
5080 |
#$result["head"][i],第i個關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
5081 |
#$result["tail"][i],第i個關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
5082 |
#$result["center"][i],第i個關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
5083 |
#$result["indexS"][i],第i個關鍵字在被搜尋字串的哪個位置開始.
|
|
|
5084 |
#$result["indexE"][i],第i個關鍵字在被搜尋字串的哪個位置結束.
|
|
|
5085 |
#必填參數:
|
|
|
5086 |
|
|
|
5087 |
#如果存在 newInputArguForFindKeyWordsPosition,就用之.
|
|
|
5088 |
if(isset($newInputArguForFindKeyWordsPosition)){
|
|
|
5089 |
|
|
|
5090 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
5091 |
$conf["search::findKeyWordsPosition"]["inputStr"]=$newInputArguForFindKeyWordsPosition;
|
|
|
5092 |
|
|
|
5093 |
}#if end
|
|
|
5094 |
|
|
|
5095 |
#反之用原始輸入字串
|
|
|
5096 |
else{
|
|
|
5097 |
|
|
|
5098 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
5099 |
$conf["search::findKeyWordsPosition"]["inputStr"]=$conf["input"];
|
|
|
5100 |
|
|
|
5101 |
}#else end
|
|
|
5102 |
|
|
|
5103 |
#$conf["keyWords"],字串陣列,要搜尋的多個關鍵字
|
|
|
5104 |
$conf["search::findKeyWordsPosition"]["keyWords"]=$keywords;
|
|
|
5105 |
#可省略參數:
|
|
|
5106 |
#無.
|
|
|
5107 |
#參考資料:
|
|
|
5108 |
#http://php.net/manual/en/function.strpos.php
|
|
|
5109 |
#備註:
|
|
|
5110 |
#無.
|
|
|
5111 |
$findKeyWordsPosition=search::findKeyWordsPosition($conf["search::findKeyWordsPosition"]);
|
|
|
5112 |
unset($conf["search::findKeyWordsPosition"]);
|
|
|
5113 |
|
|
|
5114 |
#如果執行失敗
|
|
|
5115 |
if($findKeyWordsPosition["status"]==="false"){
|
|
|
5116 |
|
|
|
5117 |
#設置錯誤識別
|
|
|
5118 |
$result["status"]="false";
|
|
|
5119 |
|
|
|
5120 |
#設置錯誤訊息
|
|
|
5121 |
$result["error"]=$findKeyWordsPosition;
|
|
|
5122 |
|
|
|
5123 |
#回傳結果
|
|
|
5124 |
return $result;
|
|
|
5125 |
|
|
|
5126 |
}#if end
|
|
|
5127 |
|
|
|
5128 |
#如果三個參數 startWith、centerWith、endWith 都在
|
|
|
5129 |
if( isset($conf["startWith"]) && isset($conf["centerWith"]) && isset($conf["endWith"]) ){
|
|
|
5130 |
|
|
|
5131 |
#如果其中一個關鍵字沒找到
|
|
|
5132 |
if( $findKeyWordsPosition["head"][0]!=="true" || $findKeyWordsPosition["center"][1]!=="true" || $findKeyWordsPosition["tail"][2]!=="true" ){
|
|
|
5133 |
|
|
|
5134 |
#設置執行正常
|
|
|
5135 |
$result["status"]="true";
|
|
|
5136 |
|
|
|
5137 |
#設置檢查不通過
|
|
|
5138 |
$result["passed"]="false";
|
|
|
5139 |
|
|
|
5140 |
#設置簡易資訊
|
|
|
5141 |
$result["content"][]="input參數(".$conf["input"].")不完全符合startWith參數(".$conf["startWith"].")、centerWith參數(".$conf["centerWith"].")、endWith參數(".$conf["endWith"].")的條件";
|
|
|
5142 |
|
|
|
5143 |
#設置詳細資訊
|
|
|
5144 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5145 |
|
|
|
5146 |
#回傳結果
|
|
|
5147 |
return $result;
|
|
|
5148 |
|
|
|
5149 |
}#if end
|
|
|
5150 |
|
|
|
5151 |
#設置新的input參數
|
|
|
5152 |
$result["newInputArgu"]="";
|
|
|
5153 |
|
|
|
5154 |
}#if end
|
|
|
5155 |
|
|
|
5156 |
#反之只有 startWith、centerWith 兩個參數
|
|
|
5157 |
else if( isset($conf["startWith"]) && isset($conf["centerWith"]) ){
|
|
|
5158 |
|
|
|
5159 |
#如果其中一個關鍵字沒找到
|
|
|
5160 |
if( $findKeyWordsPosition["head"][0]!=="true" || $findKeyWordsPosition["center"][1]!=="true" ){
|
|
|
5161 |
|
|
|
5162 |
#設置執行正常
|
|
|
5163 |
$result["status"]="true";
|
|
|
5164 |
|
|
|
5165 |
#設置檢查不通過
|
|
|
5166 |
$result["passed"]="false";
|
|
|
5167 |
|
|
|
5168 |
#設置簡易資訊
|
|
|
5169 |
$result["content"][]="input參數(".$conf["input"].")不完全符合startWith參數(".$conf["startWith"].")、centerWith參數(".$conf["centerWith"].")的條件";
|
|
|
5170 |
|
|
|
5171 |
#設置詳細資訊
|
|
|
5172 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5173 |
|
|
|
5174 |
#回傳結果
|
|
|
5175 |
return $result;
|
|
|
5176 |
|
|
|
5177 |
}#if end
|
|
|
5178 |
|
|
|
5179 |
#函式說明:
|
|
|
5180 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
5181 |
#回傳結果:
|
|
|
5182 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5183 |
#$result["error"],錯誤訊息陣列.
|
|
|
5184 |
#$result["function"],當前執行的函數名稱.
|
|
|
5185 |
#$result["content"],分割好的內容陣列.
|
|
|
5186 |
#$result["length"],unicode字串的長度.
|
|
|
5187 |
#必填參數:
|
|
|
5188 |
#$conf["str"],字串",要分割的字串.
|
|
|
5189 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["input"];
|
|
|
5190 |
#可省略參數:
|
|
|
5191 |
#$conf["length"],整數,分割的長度.
|
|
|
5192 |
$conf["stringProcess::str_split_unicode"]["length"]=$findKeyWordsPosition["indexE"][1];
|
|
|
5193 |
#參考資料:
|
|
|
5194 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5195 |
#備註:
|
|
|
5196 |
#無.
|
|
|
5197 |
$str_split_unicode=stringProcess::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
5198 |
unset($conf["stringProcess::str_split_unicode"]);
|
|
|
5199 |
|
|
|
5200 |
#如果執行失敗
|
|
|
5201 |
if($str_split_unicode["status"]==="false"){
|
|
|
5202 |
|
|
|
5203 |
#設置執行失敗
|
|
|
5204 |
$result["status"]="false";
|
|
|
5205 |
|
|
|
5206 |
#設置執行錯誤訊息
|
|
|
5207 |
$result["error"]=$str_split_unicode;
|
|
|
5208 |
|
|
|
5209 |
#回傳結果
|
|
|
5210 |
return $result;
|
|
|
5211 |
|
|
|
5212 |
}#if end
|
|
|
5213 |
|
|
|
5214 |
#針對剩下的每個bytes
|
|
|
5215 |
foreach($str_split_unicode["content"] as $splitedStr){
|
|
|
5216 |
|
|
|
5217 |
#串接新的input參數bytes
|
|
|
5218 |
$result["newInputArgu"]=$result["newInputArgu"].$splitedStr;
|
|
|
5219 |
|
|
|
5220 |
}#foreach end
|
|
|
5221 |
|
|
|
5222 |
}#if end
|
|
|
5223 |
|
|
|
5224 |
#反之只有 startWith、endWith 兩個參數
|
|
|
5225 |
else if( isset($conf["startWith"]) && isset($conf["endWith"]) ){
|
|
|
5226 |
|
|
|
5227 |
#如果其中一個關鍵字沒找到
|
|
|
5228 |
if( $findKeyWordsPosition["head"][0]!=="true" || $findKeyWordsPosition["tail"][1]!=="true" ){
|
|
|
5229 |
|
|
|
5230 |
#設置執行正常
|
|
|
5231 |
$result["status"]="true";
|
|
|
5232 |
|
|
|
5233 |
#設置檢查不通過
|
|
|
5234 |
$result["passed"]="false";
|
|
|
5235 |
|
|
|
5236 |
#設置簡易資訊
|
|
|
5237 |
$result["content"][]="input參數(".$conf["input"].")不完全符合startWith參數(".$conf["startWith"].")、endWith參數(".$conf["endWith"].")的條件";
|
|
|
5238 |
|
|
|
5239 |
#設置詳細資訊
|
|
|
5240 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5241 |
|
|
|
5242 |
#回傳結果
|
|
|
5243 |
return $result;
|
|
|
5244 |
|
|
|
5245 |
}#if end
|
|
|
5246 |
|
|
|
5247 |
#設置新的input參數
|
|
|
5248 |
$result["newInputArgu"]="";
|
|
|
5249 |
|
|
|
5250 |
}#if end
|
|
|
5251 |
|
|
|
5252 |
#反之只有 centerWith、endWith 兩個參數
|
|
|
5253 |
else if( isset($conf["centerWith"]) && isset($conf["endWith"]) ){
|
|
|
5254 |
|
|
|
5255 |
#如果其中一個關鍵字沒找到
|
|
|
5256 |
if( $findKeyWordsPosition["center"][0]!=="true" || $findKeyWordsPosition["tail"][1]!=="true" ){
|
|
|
5257 |
|
|
|
5258 |
#設置執行正常
|
|
|
5259 |
$result["status"]="true";
|
|
|
5260 |
|
|
|
5261 |
#設置檢查不通過
|
|
|
5262 |
$result["passed"]="false";
|
|
|
5263 |
|
|
|
5264 |
#設置簡易資訊
|
|
|
5265 |
$result["content"][]="input參數(".$conf["input"].")不完全符合centerWith參數(".$conf["centerWith"].")、endWith參數(".$conf["endWith"].")的條件";
|
|
|
5266 |
|
|
|
5267 |
#設置詳細資訊
|
|
|
5268 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5269 |
|
|
|
5270 |
#回傳結果
|
|
|
5271 |
return $result;
|
|
|
5272 |
|
|
|
5273 |
}#if end
|
|
|
5274 |
|
|
|
5275 |
#設置新的input參數
|
|
|
5276 |
$result["newInputArgu"]="";
|
|
|
5277 |
|
|
|
5278 |
}#if end
|
|
|
5279 |
|
|
|
5280 |
#反之只有 startWith 參數
|
|
|
5281 |
else if(isset($conf["startWith"])){
|
|
|
5282 |
|
|
|
5283 |
#如果其中一個關鍵字沒找到
|
|
|
5284 |
if( $findKeyWordsPosition["head"][0]!=="true" ){
|
|
|
5285 |
|
|
|
5286 |
#設置執行正常
|
|
|
5287 |
$result["status"]="true";
|
|
|
5288 |
|
|
|
5289 |
#設置檢查不通過
|
|
|
5290 |
$result["passed"]="false";
|
|
|
5291 |
|
|
|
5292 |
#設置簡易資訊
|
|
|
5293 |
$result["content"][]="input參數(".$conf["input"].")不符合startWith參數(".$conf["startWith"].")的條件";
|
|
|
5294 |
|
|
|
5295 |
#設置詳細資訊
|
|
|
5296 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5297 |
|
|
|
5298 |
#回傳結果
|
|
|
5299 |
return $result;
|
|
|
5300 |
|
|
|
5301 |
}#if end
|
|
|
5302 |
|
|
|
5303 |
#函式說明:
|
|
|
5304 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
5305 |
#回傳結果:
|
|
|
5306 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5307 |
#$result["error"],錯誤訊息陣列.
|
|
|
5308 |
#$result["function"],當前執行的函數名稱.
|
|
|
5309 |
#$result["content"],分割好的內容陣列.
|
|
|
5310 |
#$result["length"],unicode字串的長度.
|
|
|
5311 |
#必填參數:
|
|
|
5312 |
#$conf["str"],字串",要分割的字串.
|
|
|
5313 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["input"];
|
|
|
5314 |
#可省略參數:
|
|
|
5315 |
#$conf["length"],整數,分割的長度.
|
|
|
5316 |
$conf["stringProcess::str_split_unicode"]["length"]=$findKeyWordsPosition["indexE"][0];
|
|
|
5317 |
#參考資料:
|
|
|
5318 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5319 |
#備註:
|
|
|
5320 |
#無.
|
|
|
5321 |
$str_split_unicode=stringProcess::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
5322 |
unset($conf["stringProcess::str_split_unicode"]);
|
|
|
5323 |
|
|
|
5324 |
#如果執行失敗
|
|
|
5325 |
if($str_split_unicode["status"]==="false"){
|
|
|
5326 |
|
|
|
5327 |
#設置執行失敗
|
|
|
5328 |
$result["status"]="false";
|
|
|
5329 |
|
|
|
5330 |
#設置執行錯誤訊息
|
|
|
5331 |
$result["error"]=$str_split_unicode;
|
|
|
5332 |
|
|
|
5333 |
#回傳結果
|
|
|
5334 |
return $result;
|
|
|
5335 |
|
|
|
5336 |
}#if end
|
|
|
5337 |
|
|
|
5338 |
#針對剩下的每個bytes
|
|
|
5339 |
foreach($str_split_unicode["content"] as $splitedStr){
|
|
|
5340 |
|
|
|
5341 |
#串接新的input參數bytes
|
|
|
5342 |
$result["newInputArgu"]=$result["newInputArgu"].$splitedStr;
|
|
|
5343 |
|
|
|
5344 |
}#foreach end
|
|
|
5345 |
|
|
|
5346 |
}#if end
|
|
|
5347 |
|
|
|
5348 |
#反之只有 centerWith 參數
|
|
|
5349 |
else if(isset($conf["centerWith"])){
|
|
|
5350 |
|
|
|
5351 |
#如果其中一個關鍵字沒找到
|
|
|
5352 |
if( $findKeyWordsPosition["center"][0]!=="true" ){
|
|
|
5353 |
|
|
|
5354 |
#設置執行正常
|
|
|
5355 |
$result["status"]="true";
|
|
|
5356 |
|
|
|
5357 |
#設置檢查不通過
|
|
|
5358 |
$result["passed"]="false";
|
|
|
5359 |
|
|
|
5360 |
#設置簡易資訊
|
|
|
5361 |
$result["content"][]="input參數(".$conf["input"].")不符合centertWith參數(".$conf["centertWith"].")的條件";
|
|
|
5362 |
|
|
|
5363 |
#設置詳細資訊
|
|
|
5364 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5365 |
|
|
|
5366 |
#回傳結果
|
|
|
5367 |
return $result;
|
|
|
5368 |
|
|
|
5369 |
}#if end
|
|
|
5370 |
|
|
|
5371 |
#函式說明:
|
|
|
5372 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
5373 |
#回傳結果:
|
|
|
5374 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5375 |
#$result["error"],錯誤訊息陣列.
|
|
|
5376 |
#$result["function"],當前執行的函數名稱.
|
|
|
5377 |
#$result["content"],分割好的內容陣列.
|
|
|
5378 |
#$result["length"],unicode字串的長度.
|
|
|
5379 |
#必填參數:
|
|
|
5380 |
#$conf["str"],字串",要分割的字串.
|
|
|
5381 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["input"];
|
|
|
5382 |
#可省略參數:
|
|
|
5383 |
#$conf["length"],整數,分割的長度.
|
|
|
5384 |
$conf["stringProcess::str_split_unicode"]["length"]=$findKeyWordsPosition["indexE"][0];
|
|
|
5385 |
#參考資料:
|
|
|
5386 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5387 |
#備註:
|
|
|
5388 |
#無.
|
|
|
5389 |
$str_split_unicode=stringProcess::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
5390 |
unset($conf["stringProcess::str_split_unicode"]);
|
|
|
5391 |
|
|
|
5392 |
#如果執行失敗
|
|
|
5393 |
if($str_split_unicode["status"]==="false"){
|
|
|
5394 |
|
|
|
5395 |
#設置執行失敗
|
|
|
5396 |
$result["status"]="false";
|
|
|
5397 |
|
|
|
5398 |
#設置執行錯誤訊息
|
|
|
5399 |
$result["error"]=$str_split_unicode;
|
|
|
5400 |
|
|
|
5401 |
#回傳結果
|
|
|
5402 |
return $result;
|
|
|
5403 |
|
|
|
5404 |
}#if end
|
|
|
5405 |
|
|
|
5406 |
#針對剩下的每個bytes
|
|
|
5407 |
foreach($str_split_unicode["content"] as $splitedStr){
|
|
|
5408 |
|
|
|
5409 |
#串接新的input參數bytes
|
|
|
5410 |
$result["newInputArgu"]=$result["newInputArgu"].$splitedStr;
|
|
|
5411 |
|
|
|
5412 |
}#foreach end
|
|
|
5413 |
|
|
|
5414 |
}#if end
|
|
|
5415 |
|
|
|
5416 |
#反之只有 endWith 參數
|
|
|
5417 |
else if(isset($conf["endWith"])){
|
|
|
5418 |
|
|
|
5419 |
#如果其中一個關鍵字沒找到
|
|
|
5420 |
if( $findKeyWordsPosition["tail"][0]!=="true" ){
|
|
|
5421 |
|
|
|
5422 |
#設置執行正常
|
|
|
5423 |
$result["status"]="true";
|
|
|
5424 |
|
|
|
5425 |
#設置檢查不通過
|
|
|
5426 |
$result["passed"]="false";
|
|
|
5427 |
|
|
|
5428 |
#設置簡易資訊
|
|
|
5429 |
$result["content"][]="input參數(".$conf["input"].")不符合endWith參數(".$conf["endWith"].")的條件";
|
|
|
5430 |
|
|
|
5431 |
#設置詳細資訊
|
|
|
5432 |
$result["content"][]=$findKeyWordsPosition;
|
|
|
5433 |
|
|
|
5434 |
#回傳結果
|
|
|
5435 |
return $result;
|
|
|
5436 |
|
|
|
5437 |
}#if end
|
|
|
5438 |
|
|
|
5439 |
#設置新的input參數
|
|
|
5440 |
$result["newInputArgu"]="";
|
|
|
5441 |
|
|
|
5442 |
}#if end
|
|
|
5443 |
|
|
|
5444 |
#反之不可能發生的地方
|
|
|
5445 |
else{
|
|
|
5446 |
|
|
|
5447 |
#設置錯誤識別
|
|
|
5448 |
$result["status"]="false";
|
|
|
5449 |
|
|
|
5450 |
#設置錯誤訊息
|
|
|
5451 |
$result["error"][]="非預期的錯誤";
|
|
|
5452 |
|
|
|
5453 |
#設置錯誤訊息
|
|
|
5454 |
$result["error"][]=$findKeyWordsPosition;
|
|
|
5455 |
|
|
|
5456 |
#回傳結果
|
|
|
5457 |
return $result;
|
|
|
5458 |
|
|
|
5459 |
}#else end
|
|
|
5460 |
|
|
|
5461 |
#如果存在
|
|
|
5462 |
if(isset($newInputArgu)){
|
|
|
5463 |
|
|
|
5464 |
#更新之
|
|
|
5465 |
$result["newInputArgu"]=$newInputArgu;
|
|
|
5466 |
|
|
|
5467 |
}#if end
|
|
|
5468 |
|
|
|
5469 |
}#if end
|
|
|
5470 |
|
|
|
5471 |
#反之,沒有關鍵字
|
|
|
5472 |
else{
|
|
|
5473 |
|
|
|
5474 |
#若有指定bytes長度
|
|
|
5475 |
if(isset($conf["length"])){
|
|
|
5476 |
|
|
|
5477 |
#取得輸入的字位長度
|
|
|
5478 |
$length=length($conf["input"]);
|
|
|
5479 |
|
|
|
5480 |
#如果不相等
|
|
|
5481 |
if($length!==(int)$conf["length"]){
|
|
|
5482 |
|
|
|
5483 |
#設置執行正常
|
|
|
5484 |
$result["status"]="true";
|
|
|
5485 |
|
|
|
5486 |
#設置檢查不通過
|
|
|
5487 |
$result["passed"]="false";
|
|
|
5488 |
|
|
|
5489 |
#設置詳細結果訊息陣列.
|
|
|
5490 |
$result["content"][]="input參數(".$conf["input"].")的bytes長度(".$length.")與length參數(".$conf["length"].")不相等";
|
|
|
5491 |
|
|
|
5492 |
#回傳結果
|
|
|
5493 |
return $result;
|
|
|
5494 |
|
|
|
5495 |
}#if end
|
|
|
5496 |
|
|
|
5497 |
#函式說明:
|
|
|
5498 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
5499 |
#回傳結果:
|
|
|
5500 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5501 |
#$result["error"],錯誤訊息陣列.
|
|
|
5502 |
#$result["function"],當前執行的函數名稱.
|
|
|
5503 |
#$result["content"],分割好的內容陣列.
|
|
|
5504 |
#$result["length"],unicode字串的長度.
|
|
|
5505 |
#必填參數:
|
|
|
5506 |
#$conf["str"],字串",要分割的字串.
|
|
|
5507 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["input"];
|
|
|
5508 |
#可省略參數:
|
|
|
5509 |
#$conf["length"],整數,分割的長度.
|
|
|
5510 |
$conf["stringProcess::str_split_unicode"]["length"]=(int)$conf["input"];
|
|
|
5511 |
#參考資料:
|
|
|
5512 |
#http://php.net/manual/en/function.str-split.php
|
|
|
5513 |
#備註:
|
|
|
5514 |
#無.
|
|
|
5515 |
$str_split_unicode=stringProcess::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
5516 |
unset($conf["stringProcess::str_split_unicode"]);
|
|
|
5517 |
|
|
|
5518 |
#如果執行失敗
|
|
|
5519 |
if($str_split_unicode["status"]==="false"){
|
|
|
5520 |
|
|
|
5521 |
#設置執行失敗
|
|
|
5522 |
$result["status"]="false";
|
|
|
5523 |
|
|
|
5524 |
#設置執行錯誤訊息
|
|
|
5525 |
$result["error"]=$str_split_unicode;
|
|
|
5526 |
|
|
|
5527 |
#回傳結果
|
|
|
5528 |
return $result;
|
|
|
5529 |
|
|
|
5530 |
}#if end
|
|
|
5531 |
|
|
|
5532 |
#針對剩下的每個bytes
|
|
|
5533 |
foreach($str_split_unicode["content"] as $splitedStr){
|
|
|
5534 |
|
|
|
5535 |
#串接新的input參數bytes
|
|
|
5536 |
$result["newInputArgu"]=$result["newInputArgu"].$splitedStr;
|
|
|
5537 |
|
|
|
5538 |
}#foreach end
|
|
|
5539 |
|
|
|
5540 |
}#if end
|
|
|
5541 |
|
|
|
5542 |
#反之不存在指定bytes長度
|
|
|
5543 |
|
|
|
5544 |
#但有指定字位長度
|
|
|
5545 |
else if(isset($conf["lengthGrapheme"])){
|
|
|
5546 |
|
|
|
5547 |
#取得輸入的字位長度
|
|
|
5548 |
$grapheme_strlen=grapheme_strlen($conf["input"]);
|
|
|
5549 |
|
|
|
5550 |
#如果不相等
|
|
|
5551 |
if($grapheme_strlen!==(int)$conf["lengthGrapheme"]){
|
|
|
5552 |
|
|
|
5553 |
#設置執行正常
|
|
|
5554 |
$result["status"]="true";
|
|
|
5555 |
|
|
|
5556 |
#設置檢查不通過
|
|
|
5557 |
$result["passed"]="false";
|
|
|
5558 |
|
|
|
5559 |
#設置詳細結果訊息陣列.
|
|
|
5560 |
$result["content"][]="input參數(".$conf["input"].")的字位長度(".$grapheme_strlen.")與lengthGrapheme參數(".$conf["lengthGrapheme"].")不相等";
|
|
|
5561 |
|
|
|
5562 |
#回傳結果
|
|
|
5563 |
return $result;
|
|
|
5564 |
|
|
|
5565 |
}#if end
|
|
|
5566 |
|
|
|
5567 |
#取得新的input參數
|
|
|
5568 |
$result["newInputArgu"]=grapheme_substr($conf["input"],0,$conf["lengthGrapheme"]);
|
|
|
5569 |
|
|
|
5570 |
}#if end
|
|
|
5571 |
|
|
|
5572 |
#反之不存在指定字位長度
|
|
|
5573 |
|
|
|
5574 |
#但有指定 equalWith
|
|
|
5575 |
else if(isset($conf["equalWith"])){
|
|
|
5576 |
|
|
|
5577 |
#如果不相等
|
|
|
5578 |
if($conf["input"]!==$conf["equalWith"]){
|
|
|
5579 |
|
|
|
5580 |
#設置執行正常
|
|
|
5581 |
$result["status"]="true";
|
|
|
5582 |
|
|
|
5583 |
#設置檢查不通過
|
|
|
5584 |
$result["passed"]="false";
|
|
|
5585 |
|
|
|
5586 |
#設置詳細結果訊息陣列.
|
|
|
5587 |
$result["content"][]="input參數(".$conf["input"].")與equalWith參數(".$conf["equalWith"].")不相等";
|
|
|
5588 |
|
|
|
5589 |
#回傳結果
|
|
|
5590 |
return $result;
|
|
|
5591 |
|
|
|
5592 |
}#if end
|
|
|
5593 |
|
|
|
5594 |
}#if end
|
|
|
5595 |
|
|
|
5596 |
}#else(沒有關鍵字) end
|
|
|
5597 |
|
|
|
5598 |
#設置執行正常
|
|
|
5599 |
$result["status"]="true";
|
|
|
5600 |
|
|
|
5601 |
#設置檢查通過
|
|
|
5602 |
$result["passed"]="true";
|
|
|
5603 |
|
|
|
5604 |
#回傳結果
|
|
|
5605 |
return $result;
|
|
|
5606 |
|
|
|
5607 |
}#checkStringFormat end
|
|
|
5608 |
|
|
|
5609 |
/*
|
|
|
5610 |
#函式說明:
|
|
|
5611 |
#檢查字串是否符合 RFC 3339/ISO-8601 格式
|
|
|
5612 |
#回傳結果:
|
|
|
5613 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5614 |
#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.
|
|
|
5615 |
#$result["argu"],使用的參數.
|
|
|
5616 |
#$result["function"],當前執行的函數.
|
|
|
5617 |
#$result["error"],涵式錯誤訊息陣列.
|
|
|
5618 |
#必填參數:
|
|
|
5619 |
#$conf["input"],字串,要檢查格式的字串.
|
|
|
5620 |
$conf["input"]="";
|
|
|
5621 |
#可省略參數:
|
|
|
5622 |
#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"true",代表要;反之為"false".
|
|
|
5623 |
#$conf["UTC"]="true";
|
|
|
5624 |
#參考資料:
|
|
|
5625 |
#ISO 8601-2:2019=>https://www.rfc-editor.org/info/rfc3339
|
|
|
5626 |
#rfc3339=>https://www.rfc-editor.org/rfc/rfc3339
|
|
|
5627 |
#備註:
|
|
|
5628 |
#無.
|
|
|
5629 |
*/
|
|
|
5630 |
public static function checkRFC3339(&$conf){
|
|
|
5631 |
|
|
|
5632 |
#初始化要回傳的結果
|
|
|
5633 |
$result=array();
|
|
|
5634 |
|
|
|
5635 |
#設置當其函數名稱
|
|
|
5636 |
$result["function"]=__FUNCTION__;
|
|
|
5637 |
|
|
|
5638 |
#如果 $conf 不為陣列
|
|
|
5639 |
if(gettype($conf)!="array"){
|
|
|
5640 |
|
|
|
5641 |
#設置執行失敗
|
|
|
5642 |
$result["status"]="false";
|
|
|
5643 |
|
|
|
5644 |
#設置執行錯誤訊息
|
|
|
5645 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5646 |
|
|
|
5647 |
#如果傳入的參數為 null
|
|
|
5648 |
if($conf==null){
|
|
|
5649 |
|
|
|
5650 |
#設置執行錯誤訊息
|
|
|
5651 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5652 |
|
|
|
5653 |
}#if end
|
|
|
5654 |
|
|
|
5655 |
#回傳結果
|
|
|
5656 |
return $result;
|
|
|
5657 |
|
|
|
5658 |
}#if end
|
|
|
5659 |
|
|
|
5660 |
#取得使用的參數
|
|
|
5661 |
$result["argu"]=$conf;
|
|
|
5662 |
|
|
|
5663 |
#檢查參數
|
|
|
5664 |
#函式說明:
|
|
|
5665 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5666 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5667 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5668 |
#$result["function"],當前執行的函式名稱.
|
|
|
5669 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5670 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5671 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5672 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5673 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5674 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5675 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5676 |
#必填寫的參數:
|
|
|
5677 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5678 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5679 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5680 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
5681 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
5682 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5683 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5684 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5685 |
#可以省略的參數:
|
|
|
5686 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
5687 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("UTC");
|
|
|
5688 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
5689 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5690 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5691 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("UTC");
|
|
|
5692 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5693 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
5694 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5695 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
5696 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5697 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5698 |
#參考資料來源:
|
|
|
5699 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5700 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5701 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5702 |
|
|
|
5703 |
#如果檢查失敗
|
|
|
5704 |
if($checkResult["status"]==="false"){
|
|
|
5705 |
|
|
|
5706 |
#設置執行失敗的訊息
|
|
|
5707 |
$result["status"]="false";
|
|
|
5708 |
|
|
|
5709 |
#設置錯誤訊息
|
|
|
5710 |
$result["error"]=$checkResult;
|
|
|
5711 |
|
|
|
5712 |
#回傳結果
|
|
|
5713 |
return $result;
|
|
|
5714 |
|
|
|
5715 |
}#if end
|
|
|
5716 |
|
|
|
5717 |
#如果檢查不通過
|
|
|
5718 |
if($checkResult["passed"]==="false"){
|
|
|
5719 |
|
|
|
5720 |
#設置執行失敗的訊息
|
|
|
5721 |
$result["status"]="false";
|
|
|
5722 |
|
|
|
5723 |
#設置錯誤訊息
|
|
|
5724 |
$result["error"]=$checkResult;
|
|
|
5725 |
|
|
|
5726 |
#回傳結果
|
|
|
5727 |
return $result;
|
|
|
5728 |
|
|
|
5729 |
}#if end
|
|
|
5730 |
|
|
|
5731 |
#函式說明:
|
|
|
5732 |
#計算時間點距離1970/01/01多少秒,亦即unixtime.
|
|
|
5733 |
#回傳結果:
|
|
|
5734 |
#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
|
|
|
5735 |
#$result["error"],錯誤訊息陣列.
|
|
|
5736 |
#$result["content"],時間點距離1970/01/01的多少秒.
|
|
|
5737 |
#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
|
|
|
5738 |
#必填參數:
|
|
|
5739 |
#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
|
|
|
5740 |
$conf["time::caculateTimeAmount"]["dateAndTime"]=$conf["input"];
|
|
|
5741 |
#可省略參數:
|
|
|
5742 |
#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
|
|
|
5743 |
$conf["time::caculateTimeAmount"]["UTC"]=$conf["UTC"];
|
|
|
5744 |
#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
|
|
|
5745 |
$conf["time::caculateTimeAmount"]["replace0"]="false";
|
|
|
5746 |
#參考資料:
|
|
|
5747 |
#無.
|
|
|
5748 |
#備註:
|
|
|
5749 |
#無.
|
|
|
5750 |
$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
|
|
|
5751 |
unset($conf["time::caculateTimeAmount"]);
|
|
|
5752 |
|
|
|
5753 |
#如果檢查失敗
|
|
|
5754 |
if($caculateTimeAmount["status"]==="false"){
|
|
|
5755 |
|
|
|
5756 |
#設置執行正常的識別
|
|
|
5757 |
$result["status"]="true";
|
|
|
5758 |
|
|
|
5759 |
#設置檢查不通過
|
|
|
5760 |
$result["passed"]="false";
|
|
|
5761 |
|
|
|
5762 |
#設置回饋的訊息
|
|
|
5763 |
$result["content"]=$caculateTimeAmount;
|
|
|
5764 |
|
|
|
5765 |
#回傳結果
|
|
|
5766 |
return $result;
|
|
|
5767 |
|
|
|
5768 |
}#if end
|
|
|
5769 |
|
|
|
5770 |
#設置執行正常的識別
|
|
|
5771 |
$result["status"]="true";
|
|
|
5772 |
|
|
|
5773 |
#設置檢查通過
|
|
|
5774 |
$result["passed"]="true";
|
|
|
5775 |
|
|
|
5776 |
#回傳結果
|
|
|
5777 |
return $result;
|
|
|
5778 |
|
|
|
5779 |
}#function checkRFC3339 end
|
|
|
5780 |
|
|
|
5781 |
/*
|
|
|
5782 |
#函式說明:
|
|
|
5783 |
#處理各種錯誤與例外.
|
|
|
5784 |
#回傳結果:
|
|
|
5785 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5786 |
#$result["argu"],使用的參數.
|
|
|
5787 |
#$result["function"],當前執行的函數.
|
|
|
5788 |
#$result["error"],涵式錯誤訊息陣列.
|
|
|
5789 |
#必填參數:
|
|
|
5790 |
#無.
|
|
|
5791 |
#可省略參數:
|
|
|
5792 |
#$conf["allowCodition"],陣列,滿足什麼條件的錯誤跟例外要繼續執行而不中斷.
|
|
|
5793 |
#$conf["allowCodition"]=array();
|
|
|
5794 |
#$conf["debug"],字串,"true"代表遇到不允許繼續執行的例外時要輸出debug資訊;預設為"false";
|
|
|
5795 |
#$conf["debug"]="false";
|
|
|
5796 |
#$conf["format"],字串,遇到不允許的錯誤時,要用什麼格式呈現,預設為"html",其他選擇有"cmd".
|
|
|
5797 |
#$conf["format"]="html";
|
|
|
5798 |
#參考資料:
|
|
|
5799 |
#無.
|
|
|
5800 |
#備註:
|
|
|
5801 |
#由於是使用 set_exception_handler 因此程式會結束執行.
|
|
|
5802 |
*/
|
|
|
5803 |
public static function setErrorHandler(&$conf=array()){
|
|
|
5804 |
|
|
|
5805 |
#初始化要回傳的結果
|
|
|
5806 |
$result=array();
|
|
|
5807 |
|
|
|
5808 |
#取得當前執行的函數名稱
|
|
|
5809 |
$result["function"]=__FUNCTION__;
|
|
|
5810 |
|
|
|
5811 |
#取得參數
|
|
|
5812 |
$result["argu"]=$conf;
|
|
|
5813 |
|
|
|
5814 |
#如果 $conf 不為陣列
|
|
|
5815 |
if(gettype($conf)!="array"){
|
|
|
5816 |
|
|
|
5817 |
#設置執行失敗
|
|
|
5818 |
$result["status"]="false";
|
|
|
5819 |
|
|
|
5820 |
#設置執行錯誤訊息
|
|
|
5821 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5822 |
|
|
|
5823 |
#如果傳入的參數為 null
|
|
|
5824 |
if(is_null($conf)){
|
|
|
5825 |
|
|
|
5826 |
#設置執行錯誤訊息
|
|
|
5827 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5828 |
|
|
|
5829 |
}#if end
|
|
|
5830 |
|
|
|
5831 |
#回傳結果
|
|
|
5832 |
return $result;
|
|
|
5833 |
|
|
|
5834 |
}#if end
|
|
|
5835 |
|
|
|
5836 |
#檢查參數
|
|
|
5837 |
#函式說明:
|
|
|
5838 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5839 |
#回傳結果:
|
|
|
5840 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5841 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5842 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5843 |
#$result["function"],當前執行的函式名稱.
|
|
|
5844 |
#$result["argu"],設置給予的參數.
|
|
|
5845 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5846 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5847 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5848 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5849 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5850 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5851 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5852 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5853 |
#必填參數:
|
|
|
5854 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5855 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5856 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5857 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5858 |
#可省略參數:
|
|
|
5859 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5860 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stream","data");
|
|
|
5861 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5862 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("resource","array");
|
|
|
5863 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5864 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5865 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5866 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("stream");
|
|
|
5867 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5868 |
#$conf["canBeEmpty"]=array();
|
|
|
5869 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5870 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("msgEndType","autoClose");
|
|
|
5871 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5872 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("allowCodition","debug","format");
|
|
|
5873 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5874 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
|
|
|
5875 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5876 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","html");
|
|
|
5877 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5878 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5879 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5880 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5881 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
5882 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
5883 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5884 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5885 |
#參考資料:
|
|
|
5886 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5887 |
#備註:
|
|
|
5888 |
#無.
|
|
|
5889 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5890 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5891 |
|
|
|
5892 |
#如果執行失敗
|
|
|
5893 |
if($checkArguments["status"]==="false"){
|
|
|
5894 |
|
|
|
5895 |
#設置執行失敗
|
|
|
5896 |
$result["status"]="false";
|
|
|
5897 |
|
|
|
5898 |
#設置錯誤資訊
|
|
|
5899 |
$result["error"]=$checkArguments;
|
|
|
5900 |
|
|
|
5901 |
#回傳結果
|
|
|
5902 |
return $result;
|
|
|
5903 |
|
|
|
5904 |
}#if end
|
|
|
5905 |
|
|
|
5906 |
#如果檢查不通過
|
|
|
5907 |
if($checkArguments["passed"]==="false"){
|
|
|
5908 |
|
|
|
5909 |
#設置執行失敗
|
|
|
5910 |
$result["status"]="false";
|
|
|
5911 |
|
|
|
5912 |
#設置錯誤資訊
|
|
|
5913 |
$result["error"]=$checkArguments;
|
|
|
5914 |
|
|
|
5915 |
#回傳結果
|
|
|
5916 |
return $result;
|
|
|
5917 |
|
|
|
5918 |
}#if end
|
|
|
5919 |
|
|
|
5920 |
#設置給本函式使用的 conf
|
|
|
5921 |
self::$setErrorHandlerConf=$conf;
|
|
|
5922 |
|
|
|
5923 |
#處理會導致程式無法執行的錯誤
|
|
|
5924 |
set_error_handler(function($errno, $errstr, $errfile, $errline){
|
|
|
5925 |
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
|
|
|
5926 |
});
|
|
|
5927 |
|
|
|
5928 |
#處理非導致程式無法執行的錯誤
|
|
|
5929 |
#參考資料:
|
|
|
5930 |
#http://php.net/manual/en/class.exception.php
|
|
|
5931 |
set_exception_handler(function($exception){
|
|
|
5932 |
|
|
|
5933 |
#debug
|
|
|
5934 |
#var_dump($exception);return true;
|
|
|
5935 |
|
|
|
5936 |
#無窮迴圈
|
|
|
5937 |
while(true){
|
|
|
5938 |
|
|
|
5939 |
#取得給本函式使用的 conf
|
|
|
5940 |
$conf=\qbpwcf\variableCheck::$setErrorHandlerConf;
|
|
|
5941 |
|
|
|
5942 |
#debug
|
|
|
5943 |
#var_dump(__LINE__,$conf);
|
|
|
5944 |
|
|
|
5945 |
#初始化儲存錯誤訊息
|
|
|
5946 |
$info=array();
|
|
|
5947 |
|
|
|
5948 |
#取得描述
|
|
|
5949 |
$info["msg"]="Uncaught exception: ".$exception->getMessage();
|
|
|
5950 |
|
|
|
5951 |
#取得出錯檔案
|
|
|
5952 |
$info["file"]="File: ".$exception->getFile();
|
|
|
5953 |
|
|
|
5954 |
#取得出錯行數
|
|
|
5955 |
$info["line"]="Line: ".$exception->getLine();
|
|
|
5956 |
|
|
|
5957 |
#取得錯誤代碼
|
|
|
5958 |
$info["code"]="The exception code is: ".$exception->getCode();
|
|
|
5959 |
|
|
|
5960 |
#函式說明:
|
|
|
5961 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
5962 |
#回傳結果:
|
|
|
5963 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
5964 |
#$result["function"],當前執行的函數名稱.
|
|
|
5965 |
#$result["error"],錯誤訊息.
|
|
|
5966 |
#$result["argu"],使用的參數.
|
|
|
5967 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
5968 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
5969 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
5970 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
5971 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
5972 |
#必填參數:
|
|
|
5973 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
5974 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=$conf["allowCodition"];
|
|
|
5975 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
5976 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$info;
|
|
|
5977 |
#可省略參數:
|
|
|
5978 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
5979 |
#$conf["completeEqual"]="true";
|
|
|
5980 |
#參考資料:
|
|
|
5981 |
#無.
|
|
|
5982 |
#備註:
|
|
|
5983 |
#無.
|
|
|
5984 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
5985 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
5986 |
|
|
|
5987 |
#如果執行失敗
|
|
|
5988 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
|
|
5989 |
|
|
|
5990 |
#設置執行失敗
|
|
|
5991 |
$result["status"]="false";
|
|
|
5992 |
|
|
|
5993 |
#設置錯誤資訊
|
|
|
5994 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
5995 |
|
|
|
5996 |
#debug
|
|
|
5997 |
var_dump(__LINE__,$result);
|
|
|
5998 |
|
|
|
5999 |
#結束執行,回傳代碼1給shell
|
|
|
6000 |
exit(1);
|
|
|
6001 |
|
|
|
6002 |
}#if end
|
|
|
6003 |
|
|
|
6004 |
#如果有符合可以繼續執行的條件
|
|
|
6005 |
if(count($findManyKeyWordsFromManyString["foundedTrueKey"])>0){
|
|
|
6006 |
|
|
|
6007 |
#debug
|
|
|
6008 |
var_dump(__LINE__,$findManyKeyWordsFromManyString);
|
|
|
6009 |
|
|
|
6010 |
#結束while
|
|
|
6011 |
break;
|
|
|
6012 |
|
|
|
6013 |
}#if end
|
|
|
6014 |
|
|
|
6015 |
#如果有要debug
|
|
|
6016 |
if($conf["debug"]==="true"){
|
|
|
6017 |
|
|
|
6018 |
#判斷要呈現的方式
|
|
|
6019 |
switch($conf["format"]){
|
|
|
6020 |
|
|
|
6021 |
#如果是 html
|
|
|
6022 |
case "html":
|
|
|
6023 |
|
|
|
6024 |
#呈現錯誤訊息
|
|
|
6025 |
echo "<p>".PHP_EOL;
|
|
|
6026 |
echo "Uncaught exception: ".$exception->getMessage()."<br>".PHP_EOL;
|
|
|
6027 |
echo "File: ".$exception->getFile()."<br>".PHP_EOL;
|
|
|
6028 |
echo "Line: ".$exception->getLine()."<br>".PHP_EOL;
|
|
|
6029 |
echo "Trace: ".print_r($exception->getTrace(),true)."<br>".PHP_EOL;
|
|
|
6030 |
echo "The exception code is: ".$exception->getCode()."<br>".PHP_EOL;
|
|
|
6031 |
|
|
|
6032 |
#跳出 switch
|
|
|
6033 |
break;
|
|
|
6034 |
|
|
|
6035 |
#如果是 cmd
|
|
|
6036 |
case "cmd";
|
|
|
6037 |
|
|
|
6038 |
#呈現錯誤訊息
|
|
|
6039 |
echo PHP_EOL;
|
|
|
6040 |
echo "Uncaught exception: ".$exception->getMessage().PHP_EOL;
|
|
|
6041 |
echo "File: ".$exception->getFile().PHP_EOL;
|
|
|
6042 |
echo "Line: ".$exception->getLine().PHP_EOL;
|
|
|
6043 |
echo "Trace: ".print_r($exception->getTrace(),true).PHP_EOL;
|
|
|
6044 |
echo "The exception code is: ".$exception->getCode().PHP_EOL;
|
|
|
6045 |
|
|
|
6046 |
#跳出 switch
|
|
|
6047 |
break;
|
|
|
6048 |
|
|
|
6049 |
#其他格式
|
|
|
6050 |
default:
|
|
|
6051 |
|
|
|
6052 |
#用var_dump
|
|
|
6053 |
var_dump($info);
|
|
|
6054 |
|
|
|
6055 |
}#switch end
|
|
|
6056 |
|
|
|
6057 |
}#if end
|
|
|
6058 |
|
|
|
6059 |
#debug
|
|
|
6060 |
#var_dump(__LINE__,$findManyKeyWordsFromManyString);
|
|
|
6061 |
|
|
|
6062 |
#結束執行,回傳代碼1給shell
|
|
|
6063 |
exit(1);
|
|
|
6064 |
|
|
|
6065 |
}#while end
|
|
|
6066 |
|
|
|
6067 |
#debug
|
|
|
6068 |
#var_dump(__LINE__,"passed");
|
|
|
6069 |
|
|
|
6070 |
#視為可以繼續執行
|
|
|
6071 |
return true;
|
|
|
6072 |
|
|
|
6073 |
});
|
|
|
6074 |
|
|
|
6075 |
}#funciton setErrorHandler end
|
|
|
6076 |
|
|
|
6077 |
}#class variableCheck end
|
|
|
6078 |
|
|
|
6079 |
?>
|