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