| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟Log應用有關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class logs{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#可省略參數:
|
|
|
45 |
#無.
|
|
|
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
48 |
#備註:
|
|
|
49 |
#無.
|
|
|
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
52 |
|
| 3 |
liveuser |
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
55 |
|
| 3 |
liveuser |
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
| 226 |
liveuser |
58 |
|
| 3 |
liveuser |
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
61 |
|
| 3 |
liveuser |
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
64 |
|
| 3 |
liveuser |
65 |
#回傳結果
|
|
|
66 |
return $result;
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
}#function __call end
|
| 226 |
liveuser |
69 |
|
| 3 |
liveuser |
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
80 |
#可省略參數:
|
|
|
81 |
#無.
|
|
|
82 |
#參考資料:
|
|
|
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
|
|
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
88 |
|
| 3 |
liveuser |
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
91 |
|
| 3 |
liveuser |
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
| 226 |
liveuser |
94 |
|
| 3 |
liveuser |
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
100 |
|
| 3 |
liveuser |
101 |
#回傳結果
|
|
|
102 |
return $result;
|
| 226 |
liveuser |
103 |
|
| 3 |
liveuser |
104 |
}#function __callStatic end
|
| 226 |
liveuser |
105 |
|
| 3 |
liveuser |
106 |
/*
|
|
|
107 |
#函式說明:
|
|
|
108 |
#撰寫log
|
|
|
109 |
#回傳結果:
|
|
|
110 |
#$result["status"],狀態,"true"或"false".
|
|
|
111 |
#$result["error"],錯誤訊息陣列.
|
|
|
112 |
#$result["function"],當前函式的名稱.
|
|
|
113 |
#$result["argu"],使用的參數.
|
|
|
114 |
#$result["content"],要寫入log的內容字串.
|
|
|
115 |
#必填參數:
|
|
|
116 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
117 |
$conf["path"]="";
|
|
|
118 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
119 |
$conf["content"]="";
|
|
|
120 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
121 |
$conf["fileArgu"]=__FILE__;
|
|
|
122 |
#可省略參數:
|
|
|
123 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
124 |
#$conf["rewrite"]="false";
|
|
|
125 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
126 |
#$conf["returnOnly"]="true";
|
|
|
127 |
#參考資料:
|
|
|
128 |
#無.
|
|
|
129 |
#備註:
|
|
|
130 |
#無.
|
| 226 |
liveuser |
131 |
*/
|
| 3 |
liveuser |
132 |
public static function record(&$conf){
|
| 226 |
liveuser |
133 |
|
| 3 |
liveuser |
134 |
#初始化要回傳的結果
|
|
|
135 |
$result=array();
|
|
|
136 |
|
|
|
137 |
#儲存當前執行的函數
|
|
|
138 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
139 |
|
| 3 |
liveuser |
140 |
#如果 $conf 不為陣列
|
|
|
141 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
142 |
|
| 3 |
liveuser |
143 |
#設置執行失敗
|
|
|
144 |
$result["status"]="false";
|
| 226 |
liveuser |
145 |
|
| 3 |
liveuser |
146 |
#設置執行錯誤訊息
|
|
|
147 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
148 |
|
|
|
149 |
#如果傳入的參數為 null
|
|
|
150 |
if($conf==null){
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
#設置執行錯誤訊息
|
|
|
153 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
154 |
|
| 3 |
liveuser |
155 |
}#if end
|
|
|
156 |
|
|
|
157 |
#回傳結果
|
|
|
158 |
return $result;
|
| 226 |
liveuser |
159 |
|
| 3 |
liveuser |
160 |
}#if end
|
| 226 |
liveuser |
161 |
|
| 3 |
liveuser |
162 |
#儲存使用的參數
|
|
|
163 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
164 |
|
| 3 |
liveuser |
165 |
#檢查參數
|
|
|
166 |
#函式說明:
|
|
|
167 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
168 |
#回傳結果:
|
|
|
169 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
170 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
171 |
#$result["function"],當前執行的函式名稱.
|
|
|
172 |
#$result["argu"],設置給予的參數.
|
|
|
173 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
174 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
175 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
176 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
177 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
178 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
179 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
180 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
181 |
#必填參數:
|
|
|
182 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
183 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
184 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
185 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
186 |
#可省略參數:
|
|
|
187 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
188 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","content","fileArgu");
|
|
|
189 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
190 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string",null,"string");
|
|
|
191 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
192 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
193 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
194 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("path","fileArgu");
|
|
|
195 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
196 |
#$conf["canBeEmpty"]=array();
|
|
|
197 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
198 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
199 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
200 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("rewrite","returnOnly");
|
|
|
201 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
202 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
203 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
204 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
|
|
205 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
206 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
207 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
208 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
209 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
210 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
211 |
#參考資料:
|
|
|
212 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
213 |
#備註:
|
|
|
214 |
#無.
|
|
|
215 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
216 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
217 |
|
| 3 |
liveuser |
218 |
#如果檢查失敗
|
|
|
219 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
220 |
|
| 3 |
liveuser |
221 |
#設置錯誤識別
|
|
|
222 |
$result["status"]="false";
|
| 226 |
liveuser |
223 |
|
| 3 |
liveuser |
224 |
#設置錯誤訊息
|
|
|
225 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
226 |
|
| 3 |
liveuser |
227 |
#回傳結果
|
|
|
228 |
return $result;
|
| 226 |
liveuser |
229 |
|
| 3 |
liveuser |
230 |
}#if end
|
| 226 |
liveuser |
231 |
|
| 3 |
liveuser |
232 |
#如果檢查不通過
|
|
|
233 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
234 |
|
| 3 |
liveuser |
235 |
#設置錯誤識別
|
|
|
236 |
$result["status"]="false";
|
| 226 |
liveuser |
237 |
|
| 3 |
liveuser |
238 |
#設置錯誤訊息
|
|
|
239 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
240 |
|
| 3 |
liveuser |
241 |
#回傳結果
|
|
|
242 |
return $result;
|
| 226 |
liveuser |
243 |
|
| 3 |
liveuser |
244 |
}#if end
|
| 226 |
liveuser |
245 |
|
| 3 |
liveuser |
246 |
#如果 content 參數不為 string
|
|
|
247 |
if(gettype($conf["content"])!=="string"){
|
| 226 |
liveuser |
248 |
|
| 3 |
liveuser |
249 |
#函式說明:
|
|
|
250 |
#記錄程式輸出的結果.
|
|
|
251 |
#回傳結果:
|
|
|
252 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
253 |
#$result["error"],錯誤訊息.
|
|
|
254 |
#$result["content"],程式的輸出.
|
|
|
255 |
#$result["function"],當前執行的涵式
|
|
|
256 |
#必填參數:
|
|
|
257 |
#$conf["code2run"],字串陣列,爲要運行的程式內容,每個元素代表一段php程式.內容不必含有php tag,但結尾必須為「;」.
|
|
|
258 |
$conf["record::getOutput"]["code2run"]=array("var_dump(\$varPassed[0]);");
|
|
|
259 |
#可省略參數:
|
|
|
260 |
#可省略參數:
|
|
|
261 |
#$conf["varPassed"],陣列,為要使用到的變數,在code2run參數裡面"\$varPassed[n]"代表第n+1個變數.
|
|
|
262 |
$conf["record::getOutput"]["varPassed"]=array($conf["content"]);
|
|
|
263 |
#參考資料:
|
|
|
264 |
#無.
|
|
|
265 |
#備註:
|
|
|
266 |
#無.
|
|
|
267 |
$getOutput=record::getOutput($conf["record::getOutput"]);
|
|
|
268 |
unset($conf["record::getOutput"]);
|
| 226 |
liveuser |
269 |
|
| 3 |
liveuser |
270 |
#如果執行失敗
|
|
|
271 |
if($getOutput["status"]==="false"){
|
| 226 |
liveuser |
272 |
|
| 3 |
liveuser |
273 |
#設置錯誤識別
|
|
|
274 |
$result["status"]="false";
|
| 226 |
liveuser |
275 |
|
| 3 |
liveuser |
276 |
#設置錯誤訊息
|
|
|
277 |
$result["error"]=$getOutput;
|
| 226 |
liveuser |
278 |
|
| 3 |
liveuser |
279 |
#回傳結果
|
|
|
280 |
return $result;
|
| 226 |
liveuser |
281 |
|
| 3 |
liveuser |
282 |
}#if end
|
| 226 |
liveuser |
283 |
|
| 3 |
liveuser |
284 |
#取得輸出並複寫成字串
|
|
|
285 |
$conf["content"]=$getOutput["content"];
|
| 226 |
liveuser |
286 |
|
| 3 |
liveuser |
287 |
}#if end
|
| 226 |
liveuser |
288 |
|
| 3 |
liveuser |
289 |
#如果要寫入 log 檔案
|
|
|
290 |
if($conf["returnOnly"]==="false"){
|
| 226 |
liveuser |
291 |
|
| 3 |
liveuser |
292 |
#涵式說明:
|
|
|
293 |
#將字串寫入到檔案
|
|
|
294 |
#回傳的結果:
|
|
|
295 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
296 |
#$result["error"],錯誤訊息陣列.
|
|
|
297 |
#$result["function"],當前執行的函數名稱.
|
|
|
298 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
299 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
300 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
301 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
302 |
#$result["argu"],使用的參數.
|
|
|
303 |
#必填的參數:
|
|
|
304 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
305 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
306 |
#可省略的參數:
|
|
|
307 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
308 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["path"];
|
|
|
309 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
310 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]=$conf["content"];
|
| 226 |
liveuser |
311 |
|
| 3 |
liveuser |
312 |
#如果要重新寫入
|
|
|
313 |
if($conf["rewrite"]==="true"){
|
| 226 |
liveuser |
314 |
|
| 3 |
liveuser |
315 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
316 |
$conf["fileAccess::writeTextIntoFile"]["writeMethod"]="w";
|
| 226 |
liveuser |
317 |
|
| 3 |
liveuser |
318 |
}#if end
|
| 226 |
liveuser |
319 |
|
| 3 |
liveuser |
320 |
#反之
|
|
|
321 |
else{
|
| 226 |
liveuser |
322 |
|
| 3 |
liveuser |
323 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
324 |
$conf["fileAccess::writeTextIntoFile"]["writeMethod"]="a";
|
| 226 |
liveuser |
325 |
|
| 3 |
liveuser |
326 |
}#else end
|
| 226 |
liveuser |
327 |
|
| 3 |
liveuser |
328 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
329 |
#$conf["checkRepeat"]="";
|
|
|
330 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
331 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
332 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
333 |
#$conf["repeatNameRule"]="";
|
|
|
334 |
$conf["fileAccess::writeTextIntoFile"]["web"]="false";#檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
335 |
#$conf["web"]="true";
|
|
|
336 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
337 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
| 226 |
liveuser |
338 |
|
| 3 |
liveuser |
339 |
#如果寫入檔案失敗
|
|
|
340 |
if($writeTextIntoFile["status"]==="false"){
|
| 226 |
liveuser |
341 |
|
| 3 |
liveuser |
342 |
#設置錯誤識別
|
|
|
343 |
$result["status"]="false";
|
| 226 |
liveuser |
344 |
|
| 3 |
liveuser |
345 |
#設置錯誤訊息
|
|
|
346 |
$result["error"]=$writeTextIntoFile;
|
| 226 |
liveuser |
347 |
|
| 3 |
liveuser |
348 |
#回傳結果
|
|
|
349 |
return $result;
|
| 226 |
liveuser |
350 |
|
| 3 |
liveuser |
351 |
}#if end
|
| 226 |
liveuser |
352 |
|
| 3 |
liveuser |
353 |
}#if end
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#設置執行正常
|
|
|
356 |
$result["status"]="true";
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
#回傳結果
|
|
|
359 |
return $result;
|
| 226 |
liveuser |
360 |
|
| 3 |
liveuser |
361 |
}#function record end
|
| 226 |
liveuser |
362 |
|
| 3 |
liveuser |
363 |
/*
|
|
|
364 |
#函式說明:
|
|
|
365 |
#解析讀取到的log內容,分段成數個訊息儲存到session陣列中並回傳完整的訊息部分.
|
|
|
366 |
#回傳結果:
|
|
|
367 |
#$result["status"],狀態,"true"或"false".
|
|
|
368 |
#$result["error"],錯誤訊息陣列.
|
|
|
369 |
#$result["function"],當前函式的名稱.
|
|
|
370 |
#$result["argu"],使用的參數.
|
|
|
371 |
#$result["content"],陣列,每個有關鍵字的訊息陣列.
|
|
|
372 |
#$result["lineNum"],數字,當前行數.
|
|
|
373 |
#必填參數:
|
|
|
374 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
375 |
$conf["path"]="";
|
|
|
376 |
#$conf["msgStart"],字串,用來識別訊息開頭的開頭關鍵字.
|
|
|
377 |
$conf["msgStart"]="";
|
|
|
378 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
379 |
$conf["fileArgu"]=__FILE__;
|
|
|
380 |
#可省略參數:
|
|
|
381 |
#$conf["sessionName"],字串,儲存log的session變數key.
|
|
|
382 |
#$conf["sessionName"]="";
|
|
|
383 |
#$conf["line2start"],字串,log從第幾列開始,預設為總行數減去linesPerTime+1.
|
|
|
384 |
#$conf["line2start"]="";
|
|
|
385 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
| 226 |
liveuser |
386 |
#$conf["linesPerTime"]="10";
|
| 3 |
liveuser |
387 |
#參考資料:
|
|
|
388 |
#無.
|
|
|
389 |
#備註:
|
|
|
390 |
#無.
|
|
|
391 |
*/
|
|
|
392 |
public static function parseLog2session($conf){
|
| 226 |
liveuser |
393 |
|
| 3 |
liveuser |
394 |
#初始化要回傳的結果
|
|
|
395 |
$result=array();
|
|
|
396 |
|
|
|
397 |
#儲存當前執行的函數
|
|
|
398 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
#如果 $conf 不為陣列
|
|
|
401 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
402 |
|
| 3 |
liveuser |
403 |
#設置執行失敗
|
|
|
404 |
$result["status"]="false";
|
| 226 |
liveuser |
405 |
|
| 3 |
liveuser |
406 |
#設置執行錯誤訊息
|
|
|
407 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
408 |
|
|
|
409 |
#如果傳入的參數為 null
|
|
|
410 |
if($conf==null){
|
| 226 |
liveuser |
411 |
|
| 3 |
liveuser |
412 |
#設置執行錯誤訊息
|
|
|
413 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
414 |
|
| 3 |
liveuser |
415 |
}#if end
|
|
|
416 |
|
|
|
417 |
#回傳結果
|
|
|
418 |
return $result;
|
| 226 |
liveuser |
419 |
|
| 3 |
liveuser |
420 |
}#if end
|
| 226 |
liveuser |
421 |
|
| 3 |
liveuser |
422 |
#儲存使用的參數
|
|
|
423 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
424 |
|
| 3 |
liveuser |
425 |
#函式說明:
|
|
|
426 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
427 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
428 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
429 |
#$result["function"],當前執行的函式名稱.
|
|
|
430 |
#$result["argu"],設置給予的參數.
|
|
|
431 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
432 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
433 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
434 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
435 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
436 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
437 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
438 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
439 |
#必填寫的參數:
|
|
|
440 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
441 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
442 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
443 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
444 |
#可以省略的參數:
|
|
|
445 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
446 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","msgStart","fileArgu");
|
|
|
447 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
448 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
449 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
450 |
#$conf["canBeEmptyString"]="false";
|
|
|
451 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
452 |
#$conf["canNotBeEmpty"]=array();
|
|
|
453 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
454 |
#$conf["canBeEmpty"]=array();
|
|
|
455 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
456 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sessionName","line2start","linesPerTime");
|
|
|
457 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
458 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sessionName","line2start","linesPerTime");
|
|
|
459 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
460 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
461 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
462 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("logs::parseSessionLog",null,null);
|
|
|
463 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
464 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
465 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
466 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
467 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
468 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
469 |
#參考資料來源:
|
|
|
470 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
471 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
472 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
473 |
|
| 3 |
liveuser |
474 |
#如果檢查失敗
|
|
|
475 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
476 |
|
| 3 |
liveuser |
477 |
#設置錯誤識別
|
|
|
478 |
$result["status"]="false";
|
| 226 |
liveuser |
479 |
|
| 3 |
liveuser |
480 |
#設置錯誤訊息
|
|
|
481 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
482 |
|
| 3 |
liveuser |
483 |
#回傳結果
|
|
|
484 |
return $result;
|
| 226 |
liveuser |
485 |
|
| 3 |
liveuser |
486 |
}#if end
|
| 226 |
liveuser |
487 |
|
| 3 |
liveuser |
488 |
#如果檢查不通過
|
|
|
489 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
490 |
|
| 3 |
liveuser |
491 |
#設置錯誤識別
|
|
|
492 |
$result["status"]="false";
|
| 226 |
liveuser |
493 |
|
| 3 |
liveuser |
494 |
#設置錯誤訊息
|
|
|
495 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
496 |
|
| 3 |
liveuser |
497 |
#回傳結果
|
|
|
498 |
return $result;
|
| 226 |
liveuser |
499 |
|
| 3 |
liveuser |
500 |
}#if end
|
| 226 |
liveuser |
501 |
|
| 3 |
liveuser |
502 |
#涵式說明:
|
|
|
503 |
#從檔案尾部開始讀取
|
|
|
504 |
#回傳結果:
|
|
|
505 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
506 |
#$result["error"],錯誤訊息.
|
|
|
507 |
#$result["function"],當前執行的函數名稱.
|
| 226 |
liveuser |
508 |
#$result["argu"],所使用的參數.
|
| 3 |
liveuser |
509 |
#$result["content"],讀取到的內容陣列.
|
|
|
510 |
#$result["totalLineCount"],檔案的總共行數.
|
|
|
511 |
#$result["lines"],取得輸出的行數.
|
|
|
512 |
#$result["lineNum"],取得當前行數.
|
|
|
513 |
#必填參數:
|
|
|
514 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
515 |
$conf["fileAccess::tail"]["file"]=$conf["path"];
|
|
|
516 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
517 |
$conf["fileAccess::tail"]["fileArgu"]=$conf["fileArgu"];
|
|
|
518 |
#可省略參數:
|
| 226 |
liveuser |
519 |
|
| 3 |
liveuser |
520 |
#如果有 $conf["line2start"]
|
|
|
521 |
if(isset($conf["line2start"])){
|
| 226 |
liveuser |
522 |
|
| 3 |
liveuser |
523 |
#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
|
|
|
524 |
$conf["fileAccess::tail"]["line2start"]=$conf["line2start"];
|
| 226 |
liveuser |
525 |
|
| 3 |
liveuser |
526 |
}#if end
|
| 226 |
liveuser |
527 |
|
| 3 |
liveuser |
528 |
#如果有設置 $conf["linesPerTime"]
|
|
|
529 |
if(isset($conf["linesPerTime"])){
|
| 226 |
liveuser |
530 |
|
| 3 |
liveuser |
531 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
|
|
532 |
$conf["fileAccess::tail"]["linesPerTime"]=$conf["linesPerTime"];
|
| 226 |
liveuser |
533 |
|
| 3 |
liveuser |
534 |
}#if end
|
| 226 |
liveuser |
535 |
|
| 3 |
liveuser |
536 |
$tail=fileAccess::tail($conf["fileAccess::tail"]);
|
|
|
537 |
unset($conf["fileAccess::tail"]);
|
| 226 |
liveuser |
538 |
|
| 3 |
liveuser |
539 |
#如果讀取內容失敗
|
|
|
540 |
if($tail["status"]==="false"){
|
| 226 |
liveuser |
541 |
|
| 3 |
liveuser |
542 |
#設置錯誤識別
|
|
|
543 |
$result["status"]="false";
|
| 226 |
liveuser |
544 |
|
| 3 |
liveuser |
545 |
#設置錯誤訊息
|
|
|
546 |
$result["error"]=$tail;
|
| 226 |
liveuser |
547 |
|
| 3 |
liveuser |
548 |
#回傳結果
|
|
|
549 |
return $result;
|
| 226 |
liveuser |
550 |
|
| 3 |
liveuser |
551 |
}#if end
|
| 226 |
liveuser |
552 |
|
| 3 |
liveuser |
553 |
#取得當前行數
|
|
|
554 |
$result["lineNum"]=$tail["lineNum"];
|
| 226 |
liveuser |
555 |
|
| 3 |
liveuser |
556 |
#函式說明:
|
|
|
557 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
558 |
#回傳的結果:
|
|
|
559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
560 |
#$result["error"],錯誤訊息.
|
|
|
561 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
562 |
#$result["content"],取得的變數內容.
|
|
|
563 |
#$result["function"],當前執行的函數名稱.
|
|
|
564 |
#必填的參數:
|
|
|
565 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
566 |
$conf["session::getSessionValu"]["sessionVarName"]=$conf["sessionName"];
|
|
|
567 |
#可省略的參數:
|
|
|
568 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
569 |
#$conf["unsetSessionVar"]="true";
|
|
|
570 |
#$conf["autoCreate"],字串,是否要自動建立該 session 變數,"true"代表要,預設為"false"代表不要.
|
|
|
571 |
$conf["session::getSessionValu"]["autoCreate"]="true";
|
|
|
572 |
#$conf["initVal"],字串,"autoCreate"參數為"true"時,要給予的初始內容,預設為"".
|
|
|
573 |
$conf["session::getSessionValu"]["initVal"]=array();
|
|
|
574 |
#參考資料:
|
|
|
575 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
576 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
577 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
578 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValu"]);
|
|
|
579 |
unset($conf["session::getSessionValu"]);
|
| 226 |
liveuser |
580 |
|
| 3 |
liveuser |
581 |
#如果讀取內容失敗
|
|
|
582 |
if($getSessionValue["status"]==="false"){
|
| 226 |
liveuser |
583 |
|
| 3 |
liveuser |
584 |
#設置錯誤識別
|
|
|
585 |
$result["status"]="false";
|
| 226 |
liveuser |
586 |
|
| 3 |
liveuser |
587 |
#設置錯誤訊息
|
|
|
588 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
589 |
|
| 3 |
liveuser |
590 |
#回傳結果
|
|
|
591 |
return $result;
|
| 226 |
liveuser |
592 |
|
| 3 |
liveuser |
593 |
}#if end
|
| 226 |
liveuser |
594 |
|
| 3 |
liveuser |
595 |
#如果 session 變數不存在
|
|
|
596 |
if($getSessionValue["founded"]==="false"){
|
| 226 |
liveuser |
597 |
|
| 3 |
liveuser |
598 |
#設置錯誤識別
|
|
|
599 |
$result["status"]="false";
|
| 226 |
liveuser |
600 |
|
| 3 |
liveuser |
601 |
#設置錯誤訊息
|
|
|
602 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
603 |
|
| 3 |
liveuser |
604 |
#回傳結果
|
|
|
605 |
return $result;
|
| 226 |
liveuser |
606 |
|
| 3 |
liveuser |
607 |
}#if end
|
| 226 |
liveuser |
608 |
|
| 3 |
liveuser |
609 |
#初始化訊息陣列為空
|
|
|
610 |
#$_SESSION[$conf["sessionName"]]=array();
|
| 226 |
liveuser |
611 |
|
| 3 |
liveuser |
612 |
#函式說明:
|
|
|
613 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
614 |
#回傳的結果:
|
|
|
615 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
616 |
#$result["error"],錯誤訊息.
|
|
|
617 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
618 |
#$result["content"],取得的變數內容.
|
|
|
619 |
#$result["function"],當前執行的函數名稱.
|
|
|
620 |
#必填的參數:
|
|
|
621 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
622 |
$conf["session::getSessionValu"]["sessionVarName"]=$conf["sessionName"]."_msg1";
|
|
|
623 |
#可省略的參數:
|
|
|
624 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
625 |
#$conf["unsetSessionVar"]="true";
|
|
|
626 |
#$conf["autoCreate"],字串,是否要自動建立該 session 變數,"true"代表要,預設為"false"代表不要.
|
|
|
627 |
$conf["session::getSessionValu"]["autoCreate"]="true";
|
|
|
628 |
#$conf["initVal"],字串,"autoCreate"參數為"true"時,要給予的初始內容,預設為"".
|
|
|
629 |
$conf["session::getSessionValu"]["initVal"]="false";
|
|
|
630 |
#參考資料:
|
|
|
631 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
632 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
633 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
634 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValu"]);
|
|
|
635 |
unset($conf["session::getSessionValu"]);
|
| 226 |
liveuser |
636 |
|
| 3 |
liveuser |
637 |
#如果讀取內容失敗
|
|
|
638 |
if($getSessionValue["status"]==="false"){
|
| 226 |
liveuser |
639 |
|
| 3 |
liveuser |
640 |
#設置錯誤識別
|
|
|
641 |
$result["status"]="false";
|
| 226 |
liveuser |
642 |
|
| 3 |
liveuser |
643 |
#設置錯誤訊息
|
|
|
644 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
645 |
|
| 3 |
liveuser |
646 |
#回傳結果
|
|
|
647 |
return $result;
|
| 226 |
liveuser |
648 |
|
| 3 |
liveuser |
649 |
}#if end
|
| 226 |
liveuser |
650 |
|
| 3 |
liveuser |
651 |
#如果 session 變數不存在
|
|
|
652 |
if($getSessionValue["founded"]==="false"){
|
| 226 |
liveuser |
653 |
|
| 3 |
liveuser |
654 |
#設置錯誤識別
|
|
|
655 |
$result["status"]="false";
|
| 226 |
liveuser |
656 |
|
| 3 |
liveuser |
657 |
#設置錯誤訊息
|
|
|
658 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
659 |
|
| 3 |
liveuser |
660 |
#回傳結果
|
|
|
661 |
return $result;
|
| 226 |
liveuser |
662 |
|
|
|
663 |
}#if end
|
|
|
664 |
|
| 3 |
liveuser |
665 |
#函式說明:
|
|
|
666 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
667 |
#回傳的結果:
|
|
|
668 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
669 |
#$result["error"],錯誤訊息.
|
|
|
670 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
671 |
#$result["content"],取得的變數內容.
|
|
|
672 |
#$result["function"],當前執行的函數名稱.
|
|
|
673 |
#必填的參數:
|
|
|
674 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
675 |
$conf["session::getSessionValu"]["sessionVarName"]=$conf["sessionName"]."_msg2";
|
|
|
676 |
#可省略的參數:
|
|
|
677 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
678 |
#$conf["unsetSessionVar"]="true";
|
|
|
679 |
#$conf["autoCreate"],字串,是否要自動建立該 session 變數,"true"代表要,預設為"false"代表不要.
|
|
|
680 |
$conf["session::getSessionValu"]["autoCreate"]="true";
|
|
|
681 |
#$conf["initVal"],字串,"autoCreate"參數為"true"時,要給予的初始內容,預設為"".
|
|
|
682 |
$conf["session::getSessionValu"]["initVal"]="false";
|
|
|
683 |
#參考資料:
|
|
|
684 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
685 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
686 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
687 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValu"]);
|
|
|
688 |
unset($conf["session::getSessionValu"]);
|
| 226 |
liveuser |
689 |
|
| 3 |
liveuser |
690 |
#如果讀取內容失敗
|
|
|
691 |
if($getSessionValue["status"]==="false"){
|
| 226 |
liveuser |
692 |
|
| 3 |
liveuser |
693 |
#設置錯誤識別
|
|
|
694 |
$result["status"]="false";
|
| 226 |
liveuser |
695 |
|
| 3 |
liveuser |
696 |
#設置錯誤訊息
|
|
|
697 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
698 |
|
| 3 |
liveuser |
699 |
#回傳結果
|
|
|
700 |
return $result;
|
| 226 |
liveuser |
701 |
|
| 3 |
liveuser |
702 |
}#if end
|
| 226 |
liveuser |
703 |
|
| 3 |
liveuser |
704 |
#如果 session 變數不存在
|
|
|
705 |
if($getSessionValue["founded"]==="false"){
|
| 226 |
liveuser |
706 |
|
| 3 |
liveuser |
707 |
#設置錯誤識別
|
|
|
708 |
$result["status"]="false";
|
| 226 |
liveuser |
709 |
|
| 3 |
liveuser |
710 |
#設置錯誤訊息
|
|
|
711 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
712 |
|
| 3 |
liveuser |
713 |
#回傳結果
|
|
|
714 |
return $result;
|
| 226 |
liveuser |
715 |
|
| 3 |
liveuser |
716 |
}#if end
|
| 226 |
liveuser |
717 |
|
| 3 |
liveuser |
718 |
#函式說明:
|
|
|
719 |
#取得session變數裡面的數值,然後卸除該session變數
|
|
|
720 |
#回傳的結果:
|
|
|
721 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
722 |
#$result["error"],錯誤訊息.
|
|
|
723 |
#$result["founded"],是否找到session變數,"true"代表找到,"false"代表沒找到.
|
|
|
724 |
#$result["content"],取得的變數內容.
|
|
|
725 |
#$result["function"],當前執行的函數名稱.
|
|
|
726 |
#必填的參數:
|
|
|
727 |
#$conf["sessionVarName"],字串,要取得內容的session變數名稱
|
|
|
728 |
$conf["session::getSessionValu"]["sessionVarName"]=$conf["sessionName"]."_aMsg";
|
|
|
729 |
#可省略的參數:
|
|
|
730 |
#$conf["unsetSessionVar"],字串,代表要卸除session變數,預設為"false"不卸除,"true"代表要卸除.
|
|
|
731 |
#$conf["unsetSessionVar"]="true";
|
|
|
732 |
#$conf["autoCreate"],字串,是否要自動建立該 session 變數,"true"代表要,預設為"false"代表不要.
|
|
|
733 |
$conf["session::getSessionValu"]["autoCreate"]="true";
|
|
|
734 |
#$conf["initVal"],字串,"autoCreate"參數為"true"時,要給予的初始內容,預設為"".
|
|
|
735 |
$conf["session::getSessionValu"]["initVal"]=array();
|
|
|
736 |
#參考資料:
|
|
|
737 |
#call-time-pass-by-reference-easy-fix-available=>http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available
|
|
|
738 |
#可變變數=>http://emn178.pixnet.net/blog/post/80119035-php%E6%95%99%E5%AD%B8---%E8%AE%8A%E6%95%B8%28variables%29
|
|
|
739 |
#卸除參考的原始變數=>http://stackoverflow.com/questions/6654538/php-function-to-unset-variables-passed-by-reference
|
|
|
740 |
$getSessionValue=session::getSessionValue($conf["session::getSessionValu"]);
|
|
|
741 |
unset($conf["session::getSessionValu"]);
|
| 226 |
liveuser |
742 |
|
| 3 |
liveuser |
743 |
#如果讀取內容失敗
|
|
|
744 |
if($getSessionValue["status"]==="false"){
|
| 226 |
liveuser |
745 |
|
| 3 |
liveuser |
746 |
#設置錯誤識別
|
|
|
747 |
$result["status"]="false";
|
| 226 |
liveuser |
748 |
|
| 3 |
liveuser |
749 |
#設置錯誤訊息
|
|
|
750 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
751 |
|
| 3 |
liveuser |
752 |
#回傳結果
|
|
|
753 |
return $result;
|
| 226 |
liveuser |
754 |
|
| 3 |
liveuser |
755 |
}#if end
|
| 226 |
liveuser |
756 |
|
| 3 |
liveuser |
757 |
#如果 session 變數不存在
|
|
|
758 |
if($getSessionValue["founded"]==="false"){
|
| 226 |
liveuser |
759 |
|
| 3 |
liveuser |
760 |
#設置錯誤識別
|
|
|
761 |
$result["status"]="false";
|
| 226 |
liveuser |
762 |
|
| 3 |
liveuser |
763 |
#設置錯誤訊息
|
|
|
764 |
$result["error"]=$getSessionValue;
|
| 226 |
liveuser |
765 |
|
| 3 |
liveuser |
766 |
#回傳結果
|
|
|
767 |
return $result;
|
| 226 |
liveuser |
768 |
|
| 3 |
liveuser |
769 |
}#if end
|
| 226 |
liveuser |
770 |
|
| 3 |
liveuser |
771 |
/*
|
| 226 |
liveuser |
772 |
|
| 3 |
liveuser |
773 |
#函式說明:
|
|
|
774 |
#撰寫log
|
|
|
775 |
#回傳結果:
|
|
|
776 |
#$result["status"],狀態,"true"或"false".
|
|
|
777 |
#$result["error"],錯誤訊息陣列.
|
|
|
778 |
#$result["function"],當前函式的名稱.
|
|
|
779 |
#$result["argu"],使用的參數.
|
|
|
780 |
#必填參數:
|
|
|
781 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
782 |
$conf["logs::record"]["path"]="/var/www/html/latest/tailJavaLogRes2.php.log";
|
|
|
783 |
#$conf["content"],字串,要寫的內容.
|
|
|
784 |
$conf["logs::record"]["content"]=json_encode($tail["content"]).PHP_EOL.PHP_EOL;
|
|
|
785 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
786 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
787 |
#可省略參數:
|
|
|
788 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
789 |
#$conf["rewrite"]="false";
|
|
|
790 |
$record=logs::record($conf["logs::record"]);
|
|
|
791 |
unset($conf["logs::record"]);
|
| 226 |
liveuser |
792 |
|
| 3 |
liveuser |
793 |
#如果執行失敗
|
|
|
794 |
if($record["status"]==="false")
|
|
|
795 |
{
|
|
|
796 |
#印出結果
|
|
|
797 |
var_dump($record);
|
| 226 |
liveuser |
798 |
|
| 3 |
liveuser |
799 |
#結束執行
|
|
|
800 |
exit;
|
| 226 |
liveuser |
801 |
|
| 3 |
liveuser |
802 |
}#if end
|
| 226 |
liveuser |
803 |
|
| 3 |
liveuser |
804 |
*/
|
| 226 |
liveuser |
805 |
|
| 3 |
liveuser |
806 |
#針對讀取到每行內容
|
|
|
807 |
foreach($tail["content"] as $line){
|
| 226 |
liveuser |
808 |
|
| 3 |
liveuser |
809 |
#儲存內容到單一訊息變數陣列
|
|
|
810 |
$_SESSION[$conf["sessionName"]."_aMsg"][]=$line;
|
| 226 |
liveuser |
811 |
|
| 3 |
liveuser |
812 |
#如果被搜尋的長度大於等於關鍵字長度
|
|
|
813 |
if( strlen($line)>=strlen($conf["msgStart"]) ){
|
| 226 |
liveuser |
814 |
|
| 3 |
liveuser |
815 |
#涵式說明:
|
|
|
816 |
#取得符合特定字首與字尾的字串
|
|
|
817 |
#回傳的結果:
|
|
|
818 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
819 |
#$result["function"],當前執行的函數名稱.
|
|
|
820 |
#$result["error"],錯誤訊息陣列.
|
|
|
821 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
822 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
823 |
#$result["argu"],使用的參數.
|
|
|
824 |
#必填參數:
|
|
|
825 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
826 |
$conf["search::getMeetConditionsString"]["checkString"]=$line;
|
|
|
827 |
#可省略參數:
|
|
|
828 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
829 |
$conf["search::getMeetConditionsString"]["frontWord"]=$conf["msgStart"];
|
|
|
830 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
831 |
#$conf["tailWord"]="";
|
|
|
832 |
#參考資料:
|
|
|
833 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
834 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
835 |
unset($conf["search::getMeetConditionsString"]);
|
|
|
836 |
|
| 3 |
liveuser |
837 |
#如果讀取內容失敗
|
|
|
838 |
if($getMeetConditionsString["status"]==="false"){
|
| 226 |
liveuser |
839 |
|
| 3 |
liveuser |
840 |
#設置錯誤識別
|
|
|
841 |
$result["status"]="false";
|
| 226 |
liveuser |
842 |
|
| 3 |
liveuser |
843 |
#設置錯誤訊息
|
|
|
844 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
845 |
|
| 3 |
liveuser |
846 |
#回傳結果
|
|
|
847 |
return $result;
|
| 226 |
liveuser |
848 |
|
| 3 |
liveuser |
849 |
}#if end
|
| 226 |
liveuser |
850 |
|
| 3 |
liveuser |
851 |
#如果是訊息的開頭
|
|
|
852 |
if($getMeetConditionsString["founded"]==="true"){
|
| 226 |
liveuser |
853 |
|
| 3 |
liveuser |
854 |
#如果 發現第一個訊息開頭 的識別為 "false"
|
|
|
855 |
if($_SESSION[$conf["sessionName"]."_msg1"]==="false"){
|
| 226 |
liveuser |
856 |
|
| 3 |
liveuser |
857 |
#將其設置為 "true"
|
|
|
858 |
$_SESSION[$conf["sessionName"]."_msg1"]="true";
|
| 226 |
liveuser |
859 |
|
| 3 |
liveuser |
860 |
}#if end
|
| 226 |
liveuser |
861 |
|
| 3 |
liveuser |
862 |
#反之如果 發現第二個訊息開頭 的識別為 "false"
|
|
|
863 |
else if($_SESSION[$conf["sessionName"]."_msg2"]==="false"){
|
| 226 |
liveuser |
864 |
|
| 3 |
liveuser |
865 |
#將其設置為 "true"
|
|
|
866 |
$_SESSION[$conf["sessionName"]."_msg2"]="true";
|
| 226 |
liveuser |
867 |
|
| 3 |
liveuser |
868 |
}#else end
|
| 226 |
liveuser |
869 |
|
| 3 |
liveuser |
870 |
#如果遇到已經找到兩個訊息的開頭
|
|
|
871 |
if($_SESSION[$conf["sessionName"]."_msg1"]==="true" && $_SESSION[$conf["sessionName"]."_msg2"]==="true"){
|
| 226 |
liveuser |
872 |
|
| 3 |
liveuser |
873 |
#移除下個訊息的時間戳記
|
|
|
874 |
unset($_SESSION[$conf["sessionName"]."_aMsg"][count($_SESSION[$conf["sessionName"]."_aMsg"])-1]);
|
| 226 |
liveuser |
875 |
|
| 3 |
liveuser |
876 |
/*
|
|
|
877 |
#debug
|
|
|
878 |
#函式說明:
|
|
|
879 |
#撰寫log
|
|
|
880 |
#回傳結果:
|
|
|
881 |
#$result["status"],狀態,"true"或"false".
|
|
|
882 |
#$result["error"],錯誤訊息陣列.
|
|
|
883 |
#$result["function"],當前函式的名稱.
|
|
|
884 |
#$result["argu"],使用的參數.
|
|
|
885 |
#必填參數:
|
|
|
886 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
887 |
$conf["logs::record"]["path"]=basename(__FILE__).".log";
|
|
|
888 |
#$conf["content"],字串,要寫的內容.
|
|
|
889 |
$conf["logs::record"]["content"]="msg:".json_encode($_SESSION[$conf["sessionName"]."_aMsg"]).PHP_EOL;
|
|
|
890 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
891 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
892 |
#可省略參數:
|
|
|
893 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
894 |
#$conf["rewrite"]="false";
|
|
|
895 |
logs::record($conf["logs::record"]);
|
|
|
896 |
unset($conf["logs::record"]);
|
|
|
897 |
*/
|
| 226 |
liveuser |
898 |
|
| 3 |
liveuser |
899 |
#儲存單一訊息陣列
|
|
|
900 |
$_SESSION[$conf["sessionName"]][]=$_SESSION[$conf["sessionName"]."_aMsg"];
|
| 226 |
liveuser |
901 |
|
| 3 |
liveuser |
902 |
#初始化訊息的內容為時間戳記而已
|
|
|
903 |
$_SESSION[$conf["sessionName"]."_aMsg"]=array($line);
|
| 226 |
liveuser |
904 |
|
| 3 |
liveuser |
905 |
#設置 發現第二個訊息開頭 的識別為 "false"
|
|
|
906 |
$_SESSION[$conf["sessionName"]."_msg2"]==="false";
|
| 226 |
liveuser |
907 |
|
| 3 |
liveuser |
908 |
}#if end
|
| 226 |
liveuser |
909 |
|
| 3 |
liveuser |
910 |
}#if end
|
|
|
911 |
|
|
|
912 |
}#if end
|
| 226 |
liveuser |
913 |
|
| 3 |
liveuser |
914 |
#到這邊為訊息中間的內容
|
| 226 |
liveuser |
915 |
#do nothing...
|
|
|
916 |
|
| 3 |
liveuser |
917 |
#如果 發現第一個訊息開頭 的識別為 "false"
|
|
|
918 |
if($_SESSION[$conf["sessionName"]."_msg1"]==="false"){
|
| 226 |
liveuser |
919 |
|
| 3 |
liveuser |
920 |
#將其設置為 空陣列
|
|
|
921 |
$_SESSION[$conf["sessionName"]."_aMsg"]=array();
|
| 226 |
liveuser |
922 |
|
| 3 |
liveuser |
923 |
}#if end
|
| 226 |
liveuser |
924 |
|
| 3 |
liveuser |
925 |
}#foreach end
|
| 226 |
liveuser |
926 |
|
| 3 |
liveuser |
927 |
#設置要回傳的訊息陣列
|
|
|
928 |
$result["content"]=$_SESSION[$conf["sessionName"]];
|
| 226 |
liveuser |
929 |
|
| 3 |
liveuser |
930 |
#設置執行正常
|
|
|
931 |
$result["status"]="true";
|
| 226 |
liveuser |
932 |
|
| 3 |
liveuser |
933 |
#回傳結果
|
|
|
934 |
return $result;
|
| 226 |
liveuser |
935 |
|
| 3 |
liveuser |
936 |
}#function parseLog2session end
|
|
|
937 |
|
|
|
938 |
/*
|
|
|
939 |
#函式說明:
|
|
|
940 |
#解析讀取到的log內容,分段成數個訊息(可以有多種)儲存到session陣列中並回傳完整的訊息部分.
|
|
|
941 |
#回傳結果:
|
|
|
942 |
#$result["status"],狀態,"true"或"false".
|
|
|
943 |
#$result["error"],錯誤訊息陣列.
|
|
|
944 |
#$result["function"],當前函式的名稱.
|
|
|
945 |
#$result["argu"],使用的參數.
|
|
|
946 |
#$result["content"],陣列,每個有關鍵字的訊息陣列.
|
|
|
947 |
#$result["lineNum"],數字,當前行數.
|
|
|
948 |
#必填參數:
|
|
|
949 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
950 |
$conf["path"]="";
|
|
|
951 |
#$conf["msgStart"],字串陣列,用來識別訊息開頭的開頭關鍵字,支援多種訊息的開頭.
|
|
|
952 |
$conf["msgStart"]=array("");
|
|
|
953 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
954 |
$conf["fileArgu"]=__FILE__;
|
|
|
955 |
#可省略參數:
|
|
|
956 |
#$conf["sessionName"],字串,儲存log的session變數key.
|
|
|
957 |
#$conf["sessionName"]="";
|
|
|
958 |
#$conf["line2start"],字串,log從第幾列開始,預設為總行數減去linesPerTime+1.
|
|
|
959 |
#$conf["line2start"]="";
|
|
|
960 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
| 226 |
liveuser |
961 |
#$conf["linesPerTime"]="10";
|
| 3 |
liveuser |
962 |
#參考資料:
|
|
|
963 |
#無.
|
|
|
964 |
#備註:
|
|
|
965 |
#無.
|
|
|
966 |
*/
|
|
|
967 |
public static function parseLog2sessionWithMultiMsgStartSupport($conf){
|
| 226 |
liveuser |
968 |
|
| 3 |
liveuser |
969 |
#初始化要回傳的結果
|
|
|
970 |
$result=array();
|
|
|
971 |
|
|
|
972 |
#儲存當前執行的函數
|
|
|
973 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
974 |
|
| 3 |
liveuser |
975 |
#如果 $conf 不為陣列
|
|
|
976 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
977 |
|
| 3 |
liveuser |
978 |
#設置執行失敗
|
|
|
979 |
$result["status"]="false";
|
| 226 |
liveuser |
980 |
|
| 3 |
liveuser |
981 |
#設置執行錯誤訊息
|
|
|
982 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
983 |
|
|
|
984 |
#如果傳入的參數為 null
|
|
|
985 |
if($conf==null){
|
| 226 |
liveuser |
986 |
|
| 3 |
liveuser |
987 |
#設置執行錯誤訊息
|
|
|
988 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
989 |
|
| 3 |
liveuser |
990 |
}#if end
|
|
|
991 |
|
|
|
992 |
#回傳結果
|
|
|
993 |
return $result;
|
| 226 |
liveuser |
994 |
|
| 3 |
liveuser |
995 |
}#if end
|
| 226 |
liveuser |
996 |
|
| 3 |
liveuser |
997 |
#儲存使用的參數
|
|
|
998 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
999 |
|
| 3 |
liveuser |
1000 |
#函式說明:
|
|
|
1001 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1002 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1003 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1004 |
#$result["function"],當前執行的函式名稱.
|
|
|
1005 |
#$result["argu"],設置給予的參數.
|
|
|
1006 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1007 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1008 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1009 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1010 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1011 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1012 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1013 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1014 |
#必填寫的參數:
|
|
|
1015 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1016 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1017 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1018 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1019 |
#可以省略的參數:
|
|
|
1020 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1021 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","msgStart","fileArgu");
|
|
|
1022 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1023 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
|
|
|
1024 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1025 |
#$conf["canBeEmptyString"]="false";
|
|
|
1026 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1027 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1028 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1029 |
#$conf["canBeEmpty"]=array();
|
|
|
1030 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1031 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sessionName","line2start","linesPerTime");
|
|
|
1032 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1033 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sessionName","line2start","linesPerTime");
|
|
|
1034 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1035 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1036 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1037 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("logs::parseSessionLog",null,null);
|
|
|
1038 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1039 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1040 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1041 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1042 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1043 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1044 |
#參考資料來源:
|
|
|
1045 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1046 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1047 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1048 |
|
| 3 |
liveuser |
1049 |
#如果檢查失敗
|
|
|
1050 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1051 |
|
| 3 |
liveuser |
1052 |
#設置錯誤識別
|
|
|
1053 |
$result["status"]="false";
|
| 226 |
liveuser |
1054 |
|
| 3 |
liveuser |
1055 |
#設置錯誤訊息
|
|
|
1056 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1057 |
|
| 3 |
liveuser |
1058 |
#回傳結果
|
|
|
1059 |
return $result;
|
| 226 |
liveuser |
1060 |
|
| 3 |
liveuser |
1061 |
}#if end
|
| 226 |
liveuser |
1062 |
|
| 3 |
liveuser |
1063 |
#如果檢查不通過
|
|
|
1064 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1065 |
|
| 3 |
liveuser |
1066 |
#設置錯誤識別
|
|
|
1067 |
$result["status"]="false";
|
| 226 |
liveuser |
1068 |
|
| 3 |
liveuser |
1069 |
#設置錯誤訊息
|
|
|
1070 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1071 |
|
| 3 |
liveuser |
1072 |
#回傳結果
|
|
|
1073 |
return $result;
|
| 226 |
liveuser |
1074 |
|
| 3 |
liveuser |
1075 |
}#if end
|
| 226 |
liveuser |
1076 |
|
| 3 |
liveuser |
1077 |
#針對每種訊息格式的開頭
|
|
|
1078 |
foreach($conf["msgStart"] as $msgStart){
|
| 226 |
liveuser |
1079 |
|
| 3 |
liveuser |
1080 |
#函式說明:
|
|
|
1081 |
#解析讀取到的log內容,分段成數個訊息儲存到session陣列中並回傳完整的訊息部分.
|
|
|
1082 |
#回傳結果:
|
|
|
1083 |
#$result["status"],狀態,"true"或"false".
|
|
|
1084 |
#$result["error"],錯誤訊息陣列.
|
|
|
1085 |
#$result["function"],當前函式的名稱.
|
|
|
1086 |
#$result["argu"],使用的參數.
|
|
|
1087 |
#$result["content"],陣列,每個有關鍵字的訊息陣列.
|
|
|
1088 |
#$result["lineNun"],數字,當前行數.
|
|
|
1089 |
#必填參數:
|
|
|
1090 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
1091 |
$conf["logs::parseLog2session"]["path"]=$conf["path"];
|
|
|
1092 |
#$conf["msgStart"],字串,用來識別訊息開頭的開頭關鍵字.
|
|
|
1093 |
$conf["logs::parseLog2session"]["msgStart"]=$msgStart;
|
|
|
1094 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1095 |
$conf["logs::parseLog2session"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1096 |
#可省略參數:
|
|
|
1097 |
#$conf["sessionName"],字串,儲存log的session變數key.
|
|
|
1098 |
$conf["logs::parseLog2session"]["sessionName"]=$conf["sessionName"];
|
| 226 |
liveuser |
1099 |
|
| 3 |
liveuser |
1100 |
#如果有設定 $conf["line2start"]
|
|
|
1101 |
if(isset($conf["line2start"])){
|
| 226 |
liveuser |
1102 |
|
| 3 |
liveuser |
1103 |
#$conf["line2start"],字串,log從第幾列開始,預設為總行數減去linesPerTime+1.
|
|
|
1104 |
$conf["logs::parseLog2session"]["line2start"]=$conf["line2start"];
|
| 226 |
liveuser |
1105 |
|
| 3 |
liveuser |
1106 |
}#if end
|
| 226 |
liveuser |
1107 |
|
| 3 |
liveuser |
1108 |
#如果有設定 $conf["linesPerTime"]
|
|
|
1109 |
if(isset($conf["linesPerTime"])){
|
| 226 |
liveuser |
1110 |
|
| 3 |
liveuser |
1111 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
| 226 |
liveuser |
1112 |
$conf["logs::parseLog2session"]["linesPerTime"]=$conf["linesPerTime"];
|
|
|
1113 |
|
| 3 |
liveuser |
1114 |
}#if end
|
| 226 |
liveuser |
1115 |
|
| 3 |
liveuser |
1116 |
$parseLog2session=logs::parseLog2session($conf["logs::parseLog2session"]);
|
|
|
1117 |
unset($conf["logs::parseLog2session"]);
|
| 226 |
liveuser |
1118 |
|
| 3 |
liveuser |
1119 |
#如果執行失敗
|
|
|
1120 |
if($parseLog2session["status"]==="false"){
|
| 226 |
liveuser |
1121 |
|
| 3 |
liveuser |
1122 |
#設置錯誤識別
|
|
|
1123 |
$result["status"]="false";
|
| 226 |
liveuser |
1124 |
|
| 3 |
liveuser |
1125 |
#設置錯誤訊息
|
|
|
1126 |
$result["error"]=$parseLog2session;
|
| 226 |
liveuser |
1127 |
|
| 3 |
liveuser |
1128 |
#回傳結果
|
|
|
1129 |
return $result;
|
| 226 |
liveuser |
1130 |
|
| 3 |
liveuser |
1131 |
}#if end
|
| 226 |
liveuser |
1132 |
|
| 3 |
liveuser |
1133 |
#記錄當前行數.
|
| 226 |
liveuser |
1134 |
$result["lineNum"]=$parseLog2session["lineNum"];
|
|
|
1135 |
|
| 3 |
liveuser |
1136 |
#記錄結果
|
|
|
1137 |
$resultContent[]=$parseLog2session["content"];
|
| 226 |
liveuser |
1138 |
|
| 3 |
liveuser |
1139 |
}#foreach end
|
| 226 |
liveuser |
1140 |
|
| 3 |
liveuser |
1141 |
#初始化要回傳的內容
|
|
|
1142 |
$result["content"]=array();
|
| 226 |
liveuser |
1143 |
|
| 3 |
liveuser |
1144 |
#合併陣列
|
|
|
1145 |
foreach($resultContent as $rc){
|
| 226 |
liveuser |
1146 |
|
| 3 |
liveuser |
1147 |
#函式說明:
|
|
|
1148 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
1149 |
#回傳的結果:
|
|
|
1150 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
1151 |
#$result["error"],錯誤訊息陣列.
|
|
|
1152 |
#$result["function"],當前執行的函數.
|
|
|
1153 |
#$result["content"],合併好的一維陣列.
|
|
|
1154 |
#必填的參數
|
|
|
1155 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
1156 |
$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$rc);
|
|
|
1157 |
#可省略的參數:
|
|
|
1158 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
1159 |
#$conf["allowRepeat"]="true";
|
|
|
1160 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
1161 |
unset($conf["arrays::mergeArray"]);
|
| 226 |
liveuser |
1162 |
|
| 3 |
liveuser |
1163 |
#如果檢查失敗
|
|
|
1164 |
if($mergeArray["status"]=="false"){
|
| 226 |
liveuser |
1165 |
|
| 3 |
liveuser |
1166 |
#設置錯誤識別
|
|
|
1167 |
$result["status"]="false";
|
| 226 |
liveuser |
1168 |
|
| 3 |
liveuser |
1169 |
#設置錯誤訊息
|
|
|
1170 |
$result["error"]=$mergeArray;
|
| 226 |
liveuser |
1171 |
|
| 3 |
liveuser |
1172 |
#回傳結果
|
|
|
1173 |
return $result;
|
| 226 |
liveuser |
1174 |
|
| 3 |
liveuser |
1175 |
}#if end
|
| 226 |
liveuser |
1176 |
|
| 3 |
liveuser |
1177 |
#取得合併好的一維陣列
|
|
|
1178 |
$result["content"]=$mergeArray["content"];
|
| 226 |
liveuser |
1179 |
|
| 3 |
liveuser |
1180 |
}#foreach end
|
| 226 |
liveuser |
1181 |
|
| 3 |
liveuser |
1182 |
#重新設置 sesssion 變數
|
|
|
1183 |
#涵式說明:
|
|
|
1184 |
#建立session變數,並指派其內容
|
|
|
1185 |
#回傳的結果:
|
|
|
1186 |
#$result["status"],執行狀態,"true"代表執行成功;"false"代表執行失敗.
|
|
|
1187 |
#$result["error"],錯誤訊息陣列.
|
|
|
1188 |
#$result["function"],當前執行的函數名稱.
|
|
|
1189 |
#必填的參數:
|
|
|
1190 |
#$conf["sessionName"],字串,要建立的session變數名稱,建議可採用name1.name2.name3的格式.
|
|
|
1191 |
$conf["session::create"]["sessionName"]=$conf["sessionName"];
|
| 226 |
liveuser |
1192 |
#可省略的參數:
|
| 3 |
liveuser |
1193 |
#$conf["sessionValue"],字串,session變數的內容,預設為"".
|
|
|
1194 |
$conf["session::create"]["sessionValue"]=$result["content"];
|
|
|
1195 |
$create=session::create($conf["session::create"]);
|
|
|
1196 |
unset($conf["session::create"]);
|
| 226 |
liveuser |
1197 |
|
| 3 |
liveuser |
1198 |
#如果執行失敗
|
|
|
1199 |
if($create["status"]==="false"){
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
#設置錯誤識別
|
|
|
1202 |
$result["status"]="false";
|
| 226 |
liveuser |
1203 |
|
| 3 |
liveuser |
1204 |
#設置錯誤訊息
|
|
|
1205 |
$result["error"]=$create;
|
| 226 |
liveuser |
1206 |
|
| 3 |
liveuser |
1207 |
#回傳結果
|
|
|
1208 |
return $result;
|
| 226 |
liveuser |
1209 |
|
|
|
1210 |
}#if end
|
|
|
1211 |
|
| 3 |
liveuser |
1212 |
#設置執行正常
|
|
|
1213 |
$result["status"]="true";
|
| 226 |
liveuser |
1214 |
|
| 3 |
liveuser |
1215 |
#回傳結果
|
|
|
1216 |
return $result;
|
| 226 |
liveuser |
1217 |
|
| 3 |
liveuser |
1218 |
}#parseLog2sessionWithMultiMsgStartSupport
|
|
|
1219 |
|
|
|
1220 |
/*
|
|
|
1221 |
#函式說明:
|
|
|
1222 |
#解析多個訊息陣列,尋找有關鍵字出現的訊息,並回傳之.
|
|
|
1223 |
#回傳結果:
|
|
|
1224 |
#$result["status"],狀態,"true"或"false".
|
|
|
1225 |
#$result["error"],錯誤訊息陣列.
|
|
|
1226 |
#$result["function"],當前函式的名稱.
|
|
|
1227 |
#$result["argu"],使用的參數.
|
|
|
1228 |
#$result["content"],陣列,有開頭關鍵字出現的訊息陣列.
|
|
|
1229 |
#必填參數:
|
|
|
1230 |
#$conf["msgs"],陣列,由多個訊息陣列組成.
|
|
|
1231 |
$conf["msgs"]=array();
|
|
|
1232 |
#$conf["keyWord"],陣列,每個關鍵字.
|
|
|
1233 |
$conf["keyWord"]=array();
|
|
|
1234 |
#$conf["keyWordAddr"],陣列,關鍵字的位置是第幾個.
|
|
|
1235 |
$conf["keyWordAddr"]=array();
|
|
|
1236 |
#可省略參數:
|
|
|
1237 |
#無
|
|
|
1238 |
#參考資料:
|
|
|
1239 |
#無.
|
|
|
1240 |
#備註:
|
|
|
1241 |
#無.
|
|
|
1242 |
*/
|
|
|
1243 |
public static function filterMsgPack($conf){
|
| 226 |
liveuser |
1244 |
|
| 3 |
liveuser |
1245 |
#初始化要回傳的結果
|
|
|
1246 |
$result=array();
|
|
|
1247 |
|
|
|
1248 |
#取得當前執行的函數名稱
|
|
|
1249 |
$result["function"]=__FUNCTION__;
|
|
|
1250 |
|
|
|
1251 |
#如果沒有參數
|
|
|
1252 |
if(func_num_args()==0){
|
|
|
1253 |
|
|
|
1254 |
#設置執行失敗
|
|
|
1255 |
$result["status"]="false";
|
|
|
1256 |
|
|
|
1257 |
#設置執行錯誤訊息
|
|
|
1258 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1259 |
|
|
|
1260 |
#回傳結果
|
|
|
1261 |
return $result;
|
|
|
1262 |
|
|
|
1263 |
}#if end
|
|
|
1264 |
|
|
|
1265 |
#取得參數
|
|
|
1266 |
$result["argu"]=$conf;
|
|
|
1267 |
|
|
|
1268 |
#如果 $conf 不為陣列
|
|
|
1269 |
if(gettype($conf)!=="array"){
|
|
|
1270 |
|
|
|
1271 |
#設置執行失敗
|
|
|
1272 |
$result["status"]="false";
|
|
|
1273 |
|
|
|
1274 |
#設置執行錯誤訊息
|
|
|
1275 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1276 |
|
|
|
1277 |
#如果傳入的參數為 null
|
|
|
1278 |
if(is_null($conf)){
|
|
|
1279 |
|
|
|
1280 |
#設置執行錯誤訊息
|
|
|
1281 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1282 |
|
|
|
1283 |
}#if end
|
|
|
1284 |
|
|
|
1285 |
#回傳結果
|
|
|
1286 |
return $result;
|
|
|
1287 |
|
|
|
1288 |
}#if end
|
| 226 |
liveuser |
1289 |
|
| 3 |
liveuser |
1290 |
#初始化符合條件的訊息陣列
|
| 226 |
liveuser |
1291 |
$result["content"]=array();
|
|
|
1292 |
|
| 3 |
liveuser |
1293 |
#函式說明:
|
|
|
1294 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1295 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1296 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1297 |
#$result["function"],當前執行的函式名稱.
|
|
|
1298 |
#$result["argu"],設置給予的參數.
|
|
|
1299 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1300 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1301 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1302 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1303 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1304 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1305 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1306 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1307 |
#必填寫的參數:
|
|
|
1308 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1309 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1310 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1311 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1312 |
#可以省略的參數:
|
|
|
1313 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1314 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("msgs","keyWord","keyWordAddr");
|
|
|
1315 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1316 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
|
|
|
1317 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1318 |
#$conf["canBeEmptyString"]="false";
|
|
|
1319 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1320 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1321 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1322 |
#$conf["canBeEmpty"]=array();
|
|
|
1323 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1324 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sessionName","line2start","linesPerTime");
|
|
|
1325 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1326 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sessionName","line2start","linesPerTime");
|
|
|
1327 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1328 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1329 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1330 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("logs::parseSessionLog",null,null);
|
|
|
1331 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1332 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1333 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1334 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1335 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1336 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1337 |
#參考資料來源:
|
|
|
1338 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1339 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1340 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1341 |
|
| 3 |
liveuser |
1342 |
#如果檢查失敗
|
|
|
1343 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1344 |
|
| 3 |
liveuser |
1345 |
#設置錯誤識別
|
|
|
1346 |
$result["status"]="false";
|
| 226 |
liveuser |
1347 |
|
| 3 |
liveuser |
1348 |
#設置錯誤訊息
|
|
|
1349 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1350 |
|
| 3 |
liveuser |
1351 |
#回傳結果
|
|
|
1352 |
return $result;
|
| 226 |
liveuser |
1353 |
|
| 3 |
liveuser |
1354 |
}#if end
|
| 226 |
liveuser |
1355 |
|
| 3 |
liveuser |
1356 |
#如果檢查不通過
|
|
|
1357 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1358 |
|
| 3 |
liveuser |
1359 |
#設置錯誤識別
|
|
|
1360 |
$result["status"]="false";
|
| 226 |
liveuser |
1361 |
|
| 3 |
liveuser |
1362 |
#設置錯誤訊息
|
|
|
1363 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1364 |
|
| 3 |
liveuser |
1365 |
#回傳結果
|
|
|
1366 |
return $result;
|
| 226 |
liveuser |
1367 |
|
| 3 |
liveuser |
1368 |
}#if end
|
| 226 |
liveuser |
1369 |
|
| 3 |
liveuser |
1370 |
#初始化關鍵字最遠的位置為0
|
|
|
1371 |
$farAddr=0;
|
| 226 |
liveuser |
1372 |
|
| 3 |
liveuser |
1373 |
#尋找關鍵字裡面位置最遠者
|
|
|
1374 |
foreach($conf["keyWordAddr"] as $kwa){
|
| 226 |
liveuser |
1375 |
|
| 3 |
liveuser |
1376 |
#如果發現更遠的
|
|
|
1377 |
if($kwa>$farAddr){
|
| 226 |
liveuser |
1378 |
|
| 3 |
liveuser |
1379 |
#套用之
|
|
|
1380 |
$farAddr=$kwa;
|
| 226 |
liveuser |
1381 |
|
| 3 |
liveuser |
1382 |
}#if end
|
| 226 |
liveuser |
1383 |
|
|
|
1384 |
}#foreach end
|
|
|
1385 |
|
| 3 |
liveuser |
1386 |
#針對每個訊息
|
|
|
1387 |
foreach($conf["msgs"] as $msg){
|
| 226 |
liveuser |
1388 |
|
| 3 |
liveuser |
1389 |
/*
|
|
|
1390 |
#函式說明:
|
|
|
1391 |
#撰寫log
|
|
|
1392 |
#回傳結果:
|
|
|
1393 |
#$result["status"],狀態,"true"或"false".
|
|
|
1394 |
#$result["error"],錯誤訊息陣列.
|
|
|
1395 |
#$result["function"],當前函式的名稱.
|
|
|
1396 |
#$result["argu"],使用的參數.
|
|
|
1397 |
#必填參數:
|
|
|
1398 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
1399 |
$conf["logs::record"]["path"]=basename(__FILE__).".log";
|
|
|
1400 |
#$conf["content"],字串,要寫的內容.
|
|
|
1401 |
$conf["logs::record"]["content"]="msg:".json_encode($msg).PHP_EOL;
|
|
|
1402 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1403 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1404 |
#可省略參數:
|
|
|
1405 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1406 |
#$conf["rewrite"]="false";
|
|
|
1407 |
logs::record($conf["logs::record"]);
|
|
|
1408 |
unset($conf["logs::record"]);
|
|
|
1409 |
*/
|
| 226 |
liveuser |
1410 |
|
| 3 |
liveuser |
1411 |
#針對訊息中的每一列
|
|
|
1412 |
foreach($msg as $line){
|
| 226 |
liveuser |
1413 |
|
| 3 |
liveuser |
1414 |
#如果該行內容的長度不到關鍵字的位置
|
|
|
1415 |
if(strlen($line)<($farAddr+1)){
|
| 226 |
liveuser |
1416 |
|
| 3 |
liveuser |
1417 |
#換下一列
|
|
|
1418 |
continue;
|
| 226 |
liveuser |
1419 |
|
| 3 |
liveuser |
1420 |
}#if end
|
| 226 |
liveuser |
1421 |
|
| 3 |
liveuser |
1422 |
#到這裡代表長度ok
|
| 226 |
liveuser |
1423 |
|
| 3 |
liveuser |
1424 |
#debug
|
|
|
1425 |
$left=array();$right=array();
|
| 226 |
liveuser |
1426 |
|
| 3 |
liveuser |
1427 |
#針對每個關鍵字
|
|
|
1428 |
foreach($conf["keyWord"] as $index =>$keyWord){
|
| 226 |
liveuser |
1429 |
|
| 3 |
liveuser |
1430 |
#如果被搜尋的列位置不等於對應的關鍵字
|
|
|
1431 |
if($line[$conf["keyWordAddr"][$index]]!==$keyWord){
|
| 226 |
liveuser |
1432 |
|
| 3 |
liveuser |
1433 |
#換下一列
|
|
|
1434 |
continue 2;
|
| 226 |
liveuser |
1435 |
|
| 3 |
liveuser |
1436 |
}#if end
|
| 226 |
liveuser |
1437 |
|
| 3 |
liveuser |
1438 |
$left[]=$line[$conf["keyWordAddr"][$index]];
|
|
|
1439 |
$right[]=$keyWord;
|
| 226 |
liveuser |
1440 |
|
| 3 |
liveuser |
1441 |
}#foreach end
|
| 226 |
liveuser |
1442 |
|
|
|
1443 |
/*
|
| 3 |
liveuser |
1444 |
#函式說明:
|
|
|
1445 |
#撰寫log
|
|
|
1446 |
#回傳結果:
|
|
|
1447 |
#$result["status"],狀態,"true"或"false".
|
|
|
1448 |
#$result["error"],錯誤訊息陣列.
|
|
|
1449 |
#$result["function"],當前函式的名稱.
|
|
|
1450 |
#$result["argu"],使用的參數.
|
|
|
1451 |
#必填參數:
|
|
|
1452 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
1453 |
$conf["logs::record"]["path"]=basename(__FILE__).".log";
|
|
|
1454 |
#$conf["content"],字串,要寫的內容.
|
|
|
1455 |
$conf["logs::record"]["content"]="left:".json_encode($left)." right:".json_encode($right).PHP_EOL;
|
|
|
1456 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1457 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1458 |
#可省略參數:
|
|
|
1459 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1460 |
#$conf["rewrite"]="false";
|
|
|
1461 |
logs::record($conf["logs::record"]);
|
|
|
1462 |
unset($conf["logs::record"]);
|
|
|
1463 |
*/
|
| 226 |
liveuser |
1464 |
|
| 3 |
liveuser |
1465 |
#到這裡代關鍵字都符合位置
|
| 226 |
liveuser |
1466 |
|
| 3 |
liveuser |
1467 |
#儲存符合條件的訊息
|
|
|
1468 |
$result["content"][]=$msg;
|
| 226 |
liveuser |
1469 |
|
| 3 |
liveuser |
1470 |
}#foreach end
|
| 226 |
liveuser |
1471 |
|
| 3 |
liveuser |
1472 |
}#foreach end
|
| 226 |
liveuser |
1473 |
|
| 3 |
liveuser |
1474 |
#設置執行正常
|
|
|
1475 |
$result["status"]="true";
|
| 226 |
liveuser |
1476 |
|
| 3 |
liveuser |
1477 |
#回傳結果
|
|
|
1478 |
return $result;
|
| 226 |
liveuser |
1479 |
|
| 3 |
liveuser |
1480 |
}#function filterMsgPack end
|
| 226 |
liveuser |
1481 |
|
| 3 |
liveuser |
1482 |
/*
|
|
|
1483 |
#函式說明:
|
|
|
1484 |
#解析多個訊息陣列,尋找符合其中一組關鍵字出現的訊息,並回傳之.
|
|
|
1485 |
#回傳結果:
|
|
|
1486 |
#$result["status"],狀態,"true"或"false".
|
|
|
1487 |
#$result["error"],錯誤訊息陣列.
|
|
|
1488 |
#$result["function"],當前函式的名稱.
|
|
|
1489 |
#$result["argu"],使用的參數.
|
|
|
1490 |
#$result["content"],陣列,有開頭關鍵字出現的訊息陣列.
|
|
|
1491 |
#必填參數:
|
|
|
1492 |
#$conf["msgs"],陣列,由多個訊息陣列組成.
|
|
|
1493 |
$conf["msgs"]=array();
|
|
|
1494 |
#$conf["keyWords"],二維陣列,每個關鍵字.
|
|
|
1495 |
$conf["keyWords"]=array(array());
|
|
|
1496 |
#$conf["keyWordsAddr"],二維陣列,關鍵字的位置是第幾個.
|
|
|
1497 |
$conf["keyWordsAddr"]=array(array());
|
|
|
1498 |
#可省略參數:
|
|
|
1499 |
#無
|
|
|
1500 |
#參考資料:
|
|
|
1501 |
#無.
|
|
|
1502 |
#備註:
|
|
|
1503 |
#無.
|
|
|
1504 |
*/
|
|
|
1505 |
public static function filterMsgPackWithMultiKeywordSupport($conf){
|
| 226 |
liveuser |
1506 |
|
| 3 |
liveuser |
1507 |
#初始化要回傳的結果
|
|
|
1508 |
$result=array();
|
|
|
1509 |
|
|
|
1510 |
#取得當前執行的函數名稱
|
|
|
1511 |
$result["function"]=__FUNCTION__;
|
|
|
1512 |
|
|
|
1513 |
#如果沒有參數
|
|
|
1514 |
if(func_num_args()==0){
|
|
|
1515 |
|
|
|
1516 |
#設置執行失敗
|
|
|
1517 |
$result["status"]="false";
|
|
|
1518 |
|
|
|
1519 |
#設置執行錯誤訊息
|
|
|
1520 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1521 |
|
|
|
1522 |
#回傳結果
|
|
|
1523 |
return $result;
|
|
|
1524 |
|
|
|
1525 |
}#if end
|
|
|
1526 |
|
|
|
1527 |
#取得參數
|
|
|
1528 |
$result["argu"]=$conf;
|
|
|
1529 |
|
|
|
1530 |
#如果 $conf 不為陣列
|
|
|
1531 |
if(gettype($conf)!=="array"){
|
|
|
1532 |
|
|
|
1533 |
#設置執行失敗
|
|
|
1534 |
$result["status"]="false";
|
|
|
1535 |
|
|
|
1536 |
#設置執行錯誤訊息
|
|
|
1537 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1538 |
|
|
|
1539 |
#如果傳入的參數為 null
|
|
|
1540 |
if(is_null($conf)){
|
|
|
1541 |
|
|
|
1542 |
#設置執行錯誤訊息
|
|
|
1543 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1544 |
|
|
|
1545 |
}#if end
|
|
|
1546 |
|
|
|
1547 |
#回傳結果
|
|
|
1548 |
return $result;
|
|
|
1549 |
|
|
|
1550 |
}#if end
|
| 226 |
liveuser |
1551 |
|
| 3 |
liveuser |
1552 |
#初始化符合條件的訊息陣列
|
| 226 |
liveuser |
1553 |
$result["content"]=array();
|
|
|
1554 |
|
| 3 |
liveuser |
1555 |
#函式說明:
|
|
|
1556 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1557 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1558 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1559 |
#$result["function"],當前執行的函式名稱.
|
|
|
1560 |
#$result["argu"],設置給予的參數.
|
|
|
1561 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1562 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1563 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1564 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1565 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1566 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1567 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1568 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1569 |
#必填寫的參數:
|
|
|
1570 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1571 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1572 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1573 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1574 |
#可以省略的參數:
|
|
|
1575 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1576 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("msgs","keyWords","keyWordsAddr");
|
|
|
1577 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1578 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
|
|
|
1579 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1580 |
#$conf["canBeEmptyString"]="false";
|
|
|
1581 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1582 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1583 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1584 |
#$conf["canBeEmpty"]=array();
|
|
|
1585 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1586 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sessionName","line2start","linesPerTime");
|
|
|
1587 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1588 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sessionName","line2start","linesPerTime");
|
|
|
1589 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1590 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1591 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1592 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("logs::parseSessionLog",null,null);
|
|
|
1593 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1594 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1595 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1596 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1597 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1598 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1599 |
#參考資料來源:
|
|
|
1600 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1601 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1602 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1603 |
|
| 3 |
liveuser |
1604 |
#如果檢查失敗
|
|
|
1605 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1606 |
|
| 3 |
liveuser |
1607 |
#設置錯誤識別
|
|
|
1608 |
$result["status"]="false";
|
| 226 |
liveuser |
1609 |
|
| 3 |
liveuser |
1610 |
#設置錯誤訊息
|
|
|
1611 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1612 |
|
| 3 |
liveuser |
1613 |
#回傳結果
|
|
|
1614 |
return $result;
|
| 226 |
liveuser |
1615 |
|
| 3 |
liveuser |
1616 |
}#if end
|
| 226 |
liveuser |
1617 |
|
| 3 |
liveuser |
1618 |
#如果檢查不通過
|
|
|
1619 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1620 |
|
| 3 |
liveuser |
1621 |
#設置錯誤識別
|
|
|
1622 |
$result["status"]="false";
|
| 226 |
liveuser |
1623 |
|
| 3 |
liveuser |
1624 |
#設置錯誤訊息
|
|
|
1625 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1626 |
|
| 3 |
liveuser |
1627 |
#回傳結果
|
|
|
1628 |
return $result;
|
| 226 |
liveuser |
1629 |
|
| 3 |
liveuser |
1630 |
}#if end
|
| 226 |
liveuser |
1631 |
|
| 3 |
liveuser |
1632 |
#針對每個 $conf["keyWords"]
|
|
|
1633 |
foreach($conf["keyWords"] as $index=>$keyWord){
|
| 226 |
liveuser |
1634 |
|
| 3 |
liveuser |
1635 |
#函式說明:
|
|
|
1636 |
#解析多個訊息陣列,尋找有關鍵字出現的訊息,並回傳之.
|
|
|
1637 |
#回傳結果:
|
|
|
1638 |
#$result["status"],狀態,"true"或"false".
|
|
|
1639 |
#$result["error"],錯誤訊息陣列.
|
|
|
1640 |
#$result["function"],當前函式的名稱.
|
|
|
1641 |
#$result["argu"],使用的參數.
|
|
|
1642 |
#$result["content"],陣列,有開頭關鍵字出現的訊息陣列.
|
|
|
1643 |
#必填參數:
|
|
|
1644 |
#$conf["msgs"],陣列,由多個訊息陣列組成.
|
|
|
1645 |
$conf["logs::filterMsgPack"]["msgs"]=$conf["msgs"];
|
|
|
1646 |
#$conf["keyWord"],陣列,每個關鍵字.
|
|
|
1647 |
$conf["logs::filterMsgPack"]["keyWord"]=$keyWord;
|
|
|
1648 |
#$conf["keyWordAddr"],陣列,關鍵字的位置是第幾個.
|
|
|
1649 |
$conf["logs::filterMsgPack"]["keyWordAddr"]=$conf["keyWordsAddr"][$index];
|
|
|
1650 |
#可省略參數:
|
|
|
1651 |
#無
|
|
|
1652 |
$filterMsgPack=logs::filterMsgPack($conf["logs::filterMsgPack"]);
|
|
|
1653 |
unset($conf["logs::filterMsgPack"]);
|
| 226 |
liveuser |
1654 |
|
| 3 |
liveuser |
1655 |
#如果尋找關鍵字出現的訊息失敗
|
|
|
1656 |
if($filterMsgPack["status"]==="false"){
|
| 226 |
liveuser |
1657 |
|
| 3 |
liveuser |
1658 |
#設置錯誤識別
|
|
|
1659 |
$result["status"]="false";
|
| 226 |
liveuser |
1660 |
|
| 3 |
liveuser |
1661 |
#設置錯誤訊息
|
|
|
1662 |
$result["error"]=$filterMsgPack;
|
| 226 |
liveuser |
1663 |
|
| 3 |
liveuser |
1664 |
#回傳結果
|
|
|
1665 |
return $result;
|
| 226 |
liveuser |
1666 |
|
| 3 |
liveuser |
1667 |
}#if end
|
| 226 |
liveuser |
1668 |
|
| 3 |
liveuser |
1669 |
#儲存有關鍵字的訊息
|
|
|
1670 |
$resContent[]=$filterMsgPack["content"];
|
| 226 |
liveuser |
1671 |
|
| 3 |
liveuser |
1672 |
}#foreach end
|
| 226 |
liveuser |
1673 |
|
| 3 |
liveuser |
1674 |
#合併陣列
|
|
|
1675 |
foreach($resContent as $rc){
|
| 226 |
liveuser |
1676 |
|
| 3 |
liveuser |
1677 |
#函式說明:
|
|
|
1678 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
1679 |
#回傳的結果:
|
|
|
1680 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
1681 |
#$result["error"],錯誤訊息陣列.
|
|
|
1682 |
#$result["function"],當前執行的函數.
|
|
|
1683 |
#$result["content"],合併好的一維陣列.
|
|
|
1684 |
#必填的參數
|
|
|
1685 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
1686 |
$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$rc);
|
|
|
1687 |
#可省略的參數:
|
|
|
1688 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
1689 |
#$conf["allowRepeat"]="true";
|
|
|
1690 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
1691 |
unset($conf["arrays::mergeArray"]);
|
| 226 |
liveuser |
1692 |
|
| 3 |
liveuser |
1693 |
#如果檢查失敗
|
|
|
1694 |
if($mergeArray["status"]=="false"){
|
| 226 |
liveuser |
1695 |
|
| 3 |
liveuser |
1696 |
#設置錯誤識別
|
|
|
1697 |
$result["status"]="false";
|
| 226 |
liveuser |
1698 |
|
| 3 |
liveuser |
1699 |
#設置錯誤訊息
|
|
|
1700 |
$result["error"]=$mergeArray;
|
| 226 |
liveuser |
1701 |
|
| 3 |
liveuser |
1702 |
#回傳結果
|
|
|
1703 |
return $result;
|
| 226 |
liveuser |
1704 |
|
| 3 |
liveuser |
1705 |
}#if end
|
| 226 |
liveuser |
1706 |
|
| 3 |
liveuser |
1707 |
#取得合併好的一維陣列
|
|
|
1708 |
$result["content"]=$mergeArray["content"];
|
| 226 |
liveuser |
1709 |
|
| 3 |
liveuser |
1710 |
}#foreach end
|
| 226 |
liveuser |
1711 |
|
| 3 |
liveuser |
1712 |
#設置執行正常
|
|
|
1713 |
$result["status"]="true";
|
| 226 |
liveuser |
1714 |
|
| 3 |
liveuser |
1715 |
#回傳結果
|
|
|
1716 |
return $result;
|
| 226 |
liveuser |
1717 |
|
| 3 |
liveuser |
1718 |
}#function filterMsgPackWithMultiKeywordSupport end
|
|
|
1719 |
|
|
|
1720 |
}#class log end
|