| 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 |
用於改變php執行環境的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class config{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
48 |
|
| 3 |
liveuser |
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
51 |
|
| 3 |
liveuser |
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
| 226 |
liveuser |
54 |
|
| 3 |
liveuser |
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
57 |
|
| 3 |
liveuser |
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
60 |
|
| 3 |
liveuser |
61 |
#回傳結果
|
|
|
62 |
return $result;
|
| 226 |
liveuser |
63 |
|
| 3 |
liveuser |
64 |
}#function __call end
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
80 |
|
| 3 |
liveuser |
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
| 226 |
liveuser |
86 |
|
| 3 |
liveuser |
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
89 |
|
| 3 |
liveuser |
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
92 |
|
| 3 |
liveuser |
93 |
#回傳結果
|
|
|
94 |
return $result;
|
| 226 |
liveuser |
95 |
|
| 3 |
liveuser |
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#延長php的執行時間,每呼叫一次會初始化執行時間爲0,然後設定下次可以執行多久.
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#必填參數:
|
|
|
106 |
#$conf["sec"],整數,要延長多少執行時間,單位爲秒
|
|
|
107 |
$conf["sec"]=30;
|
|
|
108 |
#可省略參數:
|
|
|
109 |
#無.
|
|
|
110 |
#備註:
|
|
|
111 |
#無.
|
|
|
112 |
#參考資料:
|
|
|
113 |
#http://php.net/manual/en/function.set-time-limit.php
|
|
|
114 |
*/
|
|
|
115 |
public static function delayRunTimeExectionMax(&$conf){
|
| 226 |
liveuser |
116 |
|
| 3 |
liveuser |
117 |
#初始化要回傳的內容
|
|
|
118 |
$result=array();
|
| 226 |
liveuser |
119 |
|
| 3 |
liveuser |
120 |
#記錄當前執行的函數名稱
|
|
|
121 |
$result["function"]=__FUNCTION__;
|
|
|
122 |
|
|
|
123 |
#如果 $conf 不為陣列
|
|
|
124 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
125 |
|
| 3 |
liveuser |
126 |
#設置執行失敗
|
|
|
127 |
$result["status"]="false";
|
| 226 |
liveuser |
128 |
|
| 3 |
liveuser |
129 |
#設置執行錯誤訊息
|
|
|
130 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
131 |
|
|
|
132 |
#如果傳入的參數為 null
|
|
|
133 |
if($conf==null){
|
| 226 |
liveuser |
134 |
|
| 3 |
liveuser |
135 |
#設置執行錯誤訊息
|
|
|
136 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
137 |
|
| 3 |
liveuser |
138 |
}#if end
|
|
|
139 |
|
|
|
140 |
#回傳結果
|
|
|
141 |
return $result;
|
| 226 |
liveuser |
142 |
|
| 3 |
liveuser |
143 |
}#if end
|
|
|
144 |
|
|
|
145 |
#檢查參數
|
|
|
146 |
#函式說明:
|
|
|
147 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
148 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
149 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
150 |
#$result["function"],當前執行的函式名稱.
|
|
|
151 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
152 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
153 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
154 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
155 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
156 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
157 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
158 |
#必填寫的參數:
|
|
|
159 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
160 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
161 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
162 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sec");
|
| 226 |
liveuser |
163 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
164 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("integer");
|
|
|
165 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
166 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
167 |
#可以省略的參數:
|
|
|
168 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
169 |
$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
170 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
171 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("asc");
|
| 226 |
liveuser |
172 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
173 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
174 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
175 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
176 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
177 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
178 |
#參考資料來源:
|
|
|
179 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
180 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
181 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
182 |
|
|
|
183 |
#如果檢查參數失敗
|
|
|
184 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
185 |
|
| 3 |
liveuser |
186 |
#設置執行失敗
|
|
|
187 |
$result["status"]="false";
|
| 226 |
liveuser |
188 |
|
| 3 |
liveuser |
189 |
#設置執行錯誤訊息
|
|
|
190 |
$result["error"]=$checkArguments;
|
|
|
191 |
|
|
|
192 |
#回傳結果
|
|
|
193 |
return $result;
|
| 226 |
liveuser |
194 |
|
| 3 |
liveuser |
195 |
}#if end
|
| 226 |
liveuser |
196 |
|
| 3 |
liveuser |
197 |
#如果檢查不通過
|
|
|
198 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
199 |
|
| 3 |
liveuser |
200 |
#設置執行失敗
|
|
|
201 |
$result["status"]="false";
|
| 226 |
liveuser |
202 |
|
| 3 |
liveuser |
203 |
#設置執行錯誤訊息
|
|
|
204 |
$result["error"]=$checkArguments;
|
|
|
205 |
|
|
|
206 |
#回傳結果
|
|
|
207 |
return $result;
|
| 226 |
liveuser |
208 |
|
| 3 |
liveuser |
209 |
}#if end
|
| 226 |
liveuser |
210 |
|
| 3 |
liveuser |
211 |
#初始化執行時間爲0,然後再延長$conf["sec"] 秒
|
|
|
212 |
$setupResult=set_time_limit($conf["sec"]);
|
| 226 |
liveuser |
213 |
|
| 3 |
liveuser |
214 |
#如果爲 FALSE
|
|
|
215 |
if($setupResult==FALSE){
|
| 226 |
liveuser |
216 |
|
| 3 |
liveuser |
217 |
#設置執行不正常
|
|
|
218 |
$result["status"]="false";
|
| 226 |
liveuser |
219 |
|
| 3 |
liveuser |
220 |
#設置執行錯誤訊息
|
|
|
221 |
$result["error"]="初始與重置執行時間上限失敗";
|
| 226 |
liveuser |
222 |
|
| 3 |
liveuser |
223 |
#回傳結果
|
|
|
224 |
return $result;
|
| 226 |
liveuser |
225 |
|
| 3 |
liveuser |
226 |
}#if end
|
| 226 |
liveuser |
227 |
|
| 3 |
liveuser |
228 |
#執行到這邊代表執行正常
|
|
|
229 |
$result["status"]="true";
|
| 226 |
liveuser |
230 |
|
| 3 |
liveuser |
231 |
#回傳結果
|
|
|
232 |
return $result;
|
| 226 |
liveuser |
233 |
|
| 3 |
liveuser |
234 |
}#function delayRunTimeExectionMax end
|
| 226 |
liveuser |
235 |
|
| 3 |
liveuser |
236 |
/*
|
|
|
237 |
#函式說明:
|
|
|
238 |
#顯示目前的php設定值
|
|
|
239 |
#回傳的結果:
|
|
|
240 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
241 |
#$result["error"],錯誤訊息陣列.
|
|
|
242 |
#$result["function"],當前執行的函數名稱.
|
|
|
243 |
#$result["content"],常用的設定值的內容、也可指定想要看的設定值內容.
|
|
|
244 |
#必填參數:
|
|
|
245 |
#無.
|
|
|
246 |
#可省略參數:
|
|
|
247 |
#$conf["settingsName"],字串陣列,自己想要看的設定值內容,預設為array("display_errors","upload_max_filesize","post_max_size","output_buffering","session.auto_start","memory_limit").
|
|
|
248 |
#$conf["settingsName"]=array();
|
|
|
249 |
#$conf["showAll"],字串,是否要取得所有設定,"true"代表要,會覆寫$conf["settingsName"]的設定,"false"代表不要,預設為"fale".
|
|
|
250 |
#$conf["showAll"]="";
|
|
|
251 |
#參考資料:
|
|
|
252 |
#http://www.php.net/manual/en/function.ini-get.php
|
|
|
253 |
#http://www.php.net/manual/en/function.ini-get-all.php
|
|
|
254 |
#備註:
|
|
|
255 |
#無.
|
|
|
256 |
*/
|
|
|
257 |
public static function showSettings(&$conf){
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
#初始化要回傳的內容
|
|
|
260 |
$result=array();
|
| 226 |
liveuser |
261 |
|
| 3 |
liveuser |
262 |
#記錄當前執行的函數名稱
|
|
|
263 |
$result["function"]=__FUNCTION__;
|
|
|
264 |
|
|
|
265 |
#如果 $conf 不為陣列
|
|
|
266 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
267 |
|
| 3 |
liveuser |
268 |
#設置執行失敗
|
|
|
269 |
$result["status"]="false";
|
| 226 |
liveuser |
270 |
|
| 3 |
liveuser |
271 |
#設置執行錯誤訊息
|
|
|
272 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
273 |
|
|
|
274 |
#如果傳入的參數為 null
|
|
|
275 |
if($conf==null){
|
| 226 |
liveuser |
276 |
|
| 3 |
liveuser |
277 |
#設置執行錯誤訊息
|
|
|
278 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
279 |
|
| 3 |
liveuser |
280 |
}#if end
|
|
|
281 |
|
|
|
282 |
#回傳結果
|
|
|
283 |
return $result;
|
| 226 |
liveuser |
284 |
|
| 3 |
liveuser |
285 |
}#if end
|
|
|
286 |
|
|
|
287 |
#檢查參數
|
|
|
288 |
#函式說明:
|
|
|
289 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
290 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
291 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
292 |
#$result["function"],當前執行的函式名稱.
|
|
|
293 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
294 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
295 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
296 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
297 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
298 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
299 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
300 |
#必填寫的參數:
|
|
|
301 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
302 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
303 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
304 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("default");
|
| 226 |
liveuser |
305 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
306 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
307 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
308 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
309 |
#可以省略的參數:
|
|
|
310 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
311 |
$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
312 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
313 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("settingsName","showAll");
|
| 226 |
liveuser |
314 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
315 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
|
|
|
316 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
317 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array("display_errors","upload_max_filesize","post_max_size","output_buffering","session.auto_start","memory_limit"),"false");
|
|
|
318 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
319 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
320 |
#參考資料來源:
|
|
|
321 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
322 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
323 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
324 |
|
|
|
325 |
#如果檢查參數失敗
|
|
|
326 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
327 |
|
| 3 |
liveuser |
328 |
#設置執行失敗
|
|
|
329 |
$result["status"]="false";
|
| 226 |
liveuser |
330 |
|
| 3 |
liveuser |
331 |
#設置執行錯誤訊息
|
|
|
332 |
$result["error"]=$checkArguments;
|
|
|
333 |
|
|
|
334 |
#回傳結果
|
|
|
335 |
return $result;
|
| 226 |
liveuser |
336 |
|
| 3 |
liveuser |
337 |
}#if end
|
| 226 |
liveuser |
338 |
|
| 3 |
liveuser |
339 |
#如果檢查不通過
|
|
|
340 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
341 |
|
| 3 |
liveuser |
342 |
#設置執行失敗
|
|
|
343 |
$result["status"]="false";
|
| 226 |
liveuser |
344 |
|
| 3 |
liveuser |
345 |
#設置執行錯誤訊息
|
|
|
346 |
$result["error"]=$checkArguments;
|
|
|
347 |
|
|
|
348 |
#回傳結果
|
|
|
349 |
return $result;
|
| 226 |
liveuser |
350 |
|
| 3 |
liveuser |
351 |
}#if end
|
| 226 |
liveuser |
352 |
|
| 3 |
liveuser |
353 |
#如果要顯示所有設定
|
|
|
354 |
if($conf["showAll"]==="true"){
|
| 226 |
liveuser |
355 |
|
| 3 |
liveuser |
356 |
#取得設定值
|
|
|
357 |
$config=ini_get_all();
|
| 226 |
liveuser |
358 |
|
| 3 |
liveuser |
359 |
#如果取得設定值失敗
|
|
|
360 |
if($config==FALSE){
|
| 226 |
liveuser |
361 |
|
| 3 |
liveuser |
362 |
#設置執行不正常
|
|
|
363 |
$result["status"]="true";
|
| 226 |
liveuser |
364 |
|
| 3 |
liveuser |
365 |
#設置錯誤訊息
|
| 226 |
liveuser |
366 |
$result["error"][]="取得所有設定值失敗";
|
|
|
367 |
|
| 3 |
liveuser |
368 |
#回傳結果
|
|
|
369 |
return $result;
|
| 226 |
liveuser |
370 |
|
| 3 |
liveuser |
371 |
}#if end
|
| 226 |
liveuser |
372 |
|
| 3 |
liveuser |
373 |
#反之
|
|
|
374 |
else{
|
| 226 |
liveuser |
375 |
|
| 3 |
liveuser |
376 |
#取得設定值
|
|
|
377 |
$result["content"]=&$config;
|
| 226 |
liveuser |
378 |
|
|
|
379 |
}#else end
|
|
|
380 |
|
| 3 |
liveuser |
381 |
}#if end
|
| 226 |
liveuser |
382 |
|
| 3 |
liveuser |
383 |
#反之
|
|
|
384 |
else{
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#針對每個要顯示的設定值
|
|
|
387 |
foreach($conf["settingsName"] as $key=>$value){
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#檢查設定值
|
|
|
390 |
$config=ini_get($value);
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
#如果取得設定值失敗
|
|
|
393 |
if($config==FALSE){
|
| 226 |
liveuser |
394 |
|
| 3 |
liveuser |
395 |
#設置執行不正常
|
|
|
396 |
$result["status"]="true";
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
#設置錯誤訊息
|
| 226 |
liveuser |
399 |
$result["error"][]="參數「".$value."」不存在";
|
|
|
400 |
|
| 3 |
liveuser |
401 |
#回傳結果
|
|
|
402 |
return $result;
|
| 226 |
liveuser |
403 |
|
| 3 |
liveuser |
404 |
}#if end
|
| 226 |
liveuser |
405 |
|
| 3 |
liveuser |
406 |
#反之
|
|
|
407 |
else{
|
| 226 |
liveuser |
408 |
|
| 3 |
liveuser |
409 |
#取得設定值
|
|
|
410 |
$result["content"][$value]=$config;
|
| 226 |
liveuser |
411 |
|
| 3 |
liveuser |
412 |
}#else end
|
| 226 |
liveuser |
413 |
|
| 3 |
liveuser |
414 |
}#foreach end
|
| 226 |
liveuser |
415 |
|
|
|
416 |
}#else
|
|
|
417 |
|
| 3 |
liveuser |
418 |
#設置執行正常
|
|
|
419 |
$result["status"]="true";
|
| 226 |
liveuser |
420 |
|
| 3 |
liveuser |
421 |
#回傳結果
|
|
|
422 |
return $result;
|
| 226 |
liveuser |
423 |
|
| 3 |
liveuser |
424 |
}#function showSettings end
|
| 226 |
liveuser |
425 |
|
|
|
426 |
/*
|
| 3 |
liveuser |
427 |
#函式說明:
|
|
|
428 |
#將php設定檔常用的設定進行調整使之變成適用於開發模式、釋出模式、或自訂要調整哪些設定值
|
|
|
429 |
#回傳結果:
|
|
|
430 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
431 |
#$result["error"],錯誤訊息陣列.
|
|
|
432 |
#$result["function"],當前執行的函數名稱.
|
|
|
433 |
#必填參數:
|
|
|
434 |
#$conf["mode"],參數設定的模式,"release"代表是指共一般使用所需;"develop"代表是在開發狀態下所需;"custom"代表自訂參數設定內容
|
|
|
435 |
$conf["mode"]="release";
|
|
|
436 |
#可省略參數:
|
|
|
437 |
#$conf["customSettings"],要自訂的參數與其數值,例如array("display_errors=On").
|
|
|
438 |
#$conf["customSettings"]=array();
|
|
|
439 |
#參考資料:
|
|
|
440 |
#ini_set=>http://www.php.net/manual/en/function.ini-set.php
|
|
|
441 |
#各個參數適用的修改方式=>http://www.php.net/manual/en/ini.list.php
|
|
|
442 |
#各個參數適用的修改方式的解說=>http://hi.baidu.com/richardali/item/d28104083c70c638a2332a60
|
|
|
443 |
#備註:
|
|
|
444 |
#使用該函式後,網頁會無法顯示。
|
|
|
445 |
*/
|
|
|
446 |
public static function changeSettings(&$conf){
|
| 226 |
liveuser |
447 |
|
| 3 |
liveuser |
448 |
#初始化要回傳的結果
|
|
|
449 |
$result=array();
|
|
|
450 |
|
|
|
451 |
#儲存當前執行的函數
|
|
|
452 |
$result["function"]=__FUNCTION__;
|
|
|
453 |
|
|
|
454 |
#如果 $conf 不為陣列
|
|
|
455 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
456 |
|
| 3 |
liveuser |
457 |
#設置執行失敗
|
|
|
458 |
$result["status"]="false";
|
| 226 |
liveuser |
459 |
|
| 3 |
liveuser |
460 |
#設置執行錯誤訊息
|
|
|
461 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
462 |
|
|
|
463 |
#如果傳入的參數為 null
|
|
|
464 |
if($conf==null){
|
| 226 |
liveuser |
465 |
|
| 3 |
liveuser |
466 |
#設置執行錯誤訊息
|
|
|
467 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
468 |
|
| 3 |
liveuser |
469 |
}#if end
|
|
|
470 |
|
|
|
471 |
#回傳結果
|
|
|
472 |
return $result;
|
| 226 |
liveuser |
473 |
|
| 3 |
liveuser |
474 |
}#if end
|
| 226 |
liveuser |
475 |
|
| 3 |
liveuser |
476 |
#檢查參數
|
|
|
477 |
#函式說明:
|
|
|
478 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
479 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
480 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
481 |
#$result["function"],當前執行的函式名稱.
|
|
|
482 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
483 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
484 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
485 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
486 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
487 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
488 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
489 |
#必填寫的參數:
|
|
|
490 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
491 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
492 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
493 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode");
|
| 226 |
liveuser |
494 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
495 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
496 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
497 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
498 |
#可以省略的參數:
|
|
|
499 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
500 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
501 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
502 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("customSettings");
|
| 226 |
liveuser |
503 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
504 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
|
|
|
505 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
506 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
507 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
508 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
509 |
#參考資料來源:
|
|
|
510 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
511 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
512 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
513 |
|
| 3 |
liveuser |
514 |
#如果檢查失敗
|
|
|
515 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
516 |
|
| 3 |
liveuser |
517 |
#設置錯誤識別
|
|
|
518 |
$result["status"]="false";
|
| 226 |
liveuser |
519 |
|
| 3 |
liveuser |
520 |
#設置錯誤訊息
|
|
|
521 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
522 |
|
| 3 |
liveuser |
523 |
#回傳結果
|
|
|
524 |
return $result;
|
| 226 |
liveuser |
525 |
|
| 3 |
liveuser |
526 |
}#if end
|
| 226 |
liveuser |
527 |
|
| 3 |
liveuser |
528 |
#如果檢查不通過
|
|
|
529 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
530 |
|
| 3 |
liveuser |
531 |
#設置錯誤識別
|
|
|
532 |
$result["status"]="false";
|
| 226 |
liveuser |
533 |
|
| 3 |
liveuser |
534 |
#設置錯誤訊息
|
|
|
535 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
536 |
|
| 3 |
liveuser |
537 |
#回傳結果
|
|
|
538 |
return $result;
|
| 226 |
liveuser |
539 |
|
| 3 |
liveuser |
540 |
}#if end
|
| 226 |
liveuser |
541 |
|
| 3 |
liveuser |
542 |
#依據模式來進行設定
|
|
|
543 |
switch($conf["mode"]){
|
| 226 |
liveuser |
544 |
|
| 3 |
liveuser |
545 |
#如果是給大家正式使用的狀況
|
|
|
546 |
case "release":
|
| 226 |
liveuser |
547 |
|
| 3 |
liveuser |
548 |
#設置設定值
|
| 226 |
liveuser |
549 |
|
| 3 |
liveuser |
550 |
#關閉顯示錯誤訊息
|
|
|
551 |
$conf["customSettings"][]="display_errors=Off";
|
| 226 |
liveuser |
552 |
|
| 3 |
liveuser |
553 |
#初始化計數為0
|
|
|
554 |
$count=0;
|
| 226 |
liveuser |
555 |
|
| 3 |
liveuser |
556 |
#針對每個 $conf["customSettings"]
|
|
|
557 |
foreach($conf["customSettings"] as $configStr){
|
| 226 |
liveuser |
558 |
|
| 3 |
liveuser |
559 |
#用 "=" 分割設定字串
|
|
|
560 |
#函式說明:
|
|
|
561 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
562 |
#回傳的參數:
|
|
|
563 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
564 |
#$result["error"],錯誤訊息陣列
|
|
|
565 |
#$result["function"],當前執行的函數名稱.
|
|
|
566 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
567 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
568 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
569 |
#必填參數:
|
|
|
570 |
$conf["stringProcess::spiltString"]["stringIn"]=$configStr;#要處理的字串。
|
|
|
571 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
572 |
#備註:
|
|
|
573 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
574 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
575 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
576 |
|
| 3 |
liveuser |
577 |
#如果分割設定值字串失敗
|
|
|
578 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
579 |
|
| 3 |
liveuser |
580 |
#設置錯誤識別
|
|
|
581 |
$result["status"]="false";
|
| 226 |
liveuser |
582 |
|
| 3 |
liveuser |
583 |
#設置錯誤訊息
|
|
|
584 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
585 |
|
| 3 |
liveuser |
586 |
#回傳結果
|
|
|
587 |
return $result;
|
| 226 |
liveuser |
588 |
|
| 3 |
liveuser |
589 |
}#if end
|
| 226 |
liveuser |
590 |
|
| 3 |
liveuser |
591 |
#如果只有一段內容
|
|
|
592 |
if($spiltString["dataCounts"]=="1"){
|
| 226 |
liveuser |
593 |
|
| 3 |
liveuser |
594 |
#設置錯誤識別
|
|
|
595 |
$result["status"]="false";
|
| 226 |
liveuser |
596 |
|
| 3 |
liveuser |
597 |
#設置錯誤訊息
|
|
|
598 |
$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
|
| 226 |
liveuser |
599 |
|
| 3 |
liveuser |
600 |
#回傳結果
|
|
|
601 |
return $result;
|
| 226 |
liveuser |
602 |
|
| 3 |
liveuser |
603 |
}#if end
|
| 226 |
liveuser |
604 |
|
| 3 |
liveuser |
605 |
#設定暫時的設定值
|
|
|
606 |
$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
|
| 226 |
liveuser |
607 |
|
| 3 |
liveuser |
608 |
#如果設定失敗
|
|
|
609 |
if($oldConfigValue===false){
|
| 226 |
liveuser |
610 |
|
| 3 |
liveuser |
611 |
#設置錯誤識別
|
|
|
612 |
$result["status"]="false";
|
| 226 |
liveuser |
613 |
|
| 3 |
liveuser |
614 |
#設置錯誤訊息
|
|
|
615 |
$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
|
| 226 |
liveuser |
616 |
|
| 3 |
liveuser |
617 |
#回傳結果
|
|
|
618 |
return $result;
|
| 226 |
liveuser |
619 |
|
| 3 |
liveuser |
620 |
}#if end
|
| 226 |
liveuser |
621 |
|
| 3 |
liveuser |
622 |
#反之儲存舊的永久設地數值
|
|
|
623 |
else{
|
| 226 |
liveuser |
624 |
|
| 3 |
liveuser |
625 |
#取得舊的設定值
|
|
|
626 |
$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
|
|
627 |
$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
| 226 |
liveuser |
628 |
|
| 3 |
liveuser |
629 |
#取得新的設定值
|
|
|
630 |
$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
|
|
631 |
$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
| 226 |
liveuser |
632 |
|
| 3 |
liveuser |
633 |
#計數加1
|
|
|
634 |
$count++;
|
| 226 |
liveuser |
635 |
|
| 3 |
liveuser |
636 |
}#else end
|
| 226 |
liveuser |
637 |
|
| 3 |
liveuser |
638 |
}#foreach end
|
| 226 |
liveuser |
639 |
|
| 3 |
liveuser |
640 |
#跳出switch
|
|
|
641 |
break;
|
| 226 |
liveuser |
642 |
|
| 3 |
liveuser |
643 |
#如果是開發狀態下
|
|
|
644 |
case "develop";
|
| 226 |
liveuser |
645 |
|
| 3 |
liveuser |
646 |
#設置設定值
|
| 226 |
liveuser |
647 |
|
| 3 |
liveuser |
648 |
#開啟顯示錯誤訊息
|
|
|
649 |
$conf["customSettings"][]="display_errors=On";
|
| 226 |
liveuser |
650 |
|
| 3 |
liveuser |
651 |
#關閉使用記憶體的上限
|
|
|
652 |
$conf["customSettings"][]="memory_limit=-1";
|
| 226 |
liveuser |
653 |
|
| 3 |
liveuser |
654 |
#關閉php script執行的時間上限
|
|
|
655 |
$conf["customSettings"][]="max_execution_time=0";
|
| 226 |
liveuser |
656 |
|
| 3 |
liveuser |
657 |
#初始化計數為0
|
|
|
658 |
$count=0;
|
| 226 |
liveuser |
659 |
|
| 3 |
liveuser |
660 |
#針對每個 $conf["customSettings"]
|
|
|
661 |
foreach($conf["customSettings"] as $configStr){
|
| 226 |
liveuser |
662 |
|
| 3 |
liveuser |
663 |
#用 "=" 分割設定字串
|
|
|
664 |
#函式說明:
|
|
|
665 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
666 |
#回傳的參數:
|
|
|
667 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
668 |
#$result["error"],錯誤訊息陣列
|
|
|
669 |
#$result["function"],當前執行的函數名稱.
|
|
|
670 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
671 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
672 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
673 |
#必填參數:
|
|
|
674 |
$conf["stringProcess::spiltString"]["stringIn"]=$configStr;#要處理的字串。
|
|
|
675 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
676 |
#備註:
|
|
|
677 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
678 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
679 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
680 |
|
| 3 |
liveuser |
681 |
#如果分割設定值字串失敗
|
|
|
682 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
683 |
|
| 3 |
liveuser |
684 |
#設置錯誤識別
|
|
|
685 |
$result["status"]="false";
|
| 226 |
liveuser |
686 |
|
| 3 |
liveuser |
687 |
#設置錯誤訊息
|
|
|
688 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
689 |
|
| 3 |
liveuser |
690 |
#回傳結果
|
|
|
691 |
return $result;
|
| 226 |
liveuser |
692 |
|
| 3 |
liveuser |
693 |
}#if end
|
| 226 |
liveuser |
694 |
|
| 3 |
liveuser |
695 |
#如果只有一段內容
|
|
|
696 |
if($spiltString["dataCounts"]=="1"){
|
| 226 |
liveuser |
697 |
|
| 3 |
liveuser |
698 |
#設置錯誤識別
|
|
|
699 |
$result["status"]="false";
|
| 226 |
liveuser |
700 |
|
| 3 |
liveuser |
701 |
#設置錯誤訊息
|
|
|
702 |
$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
|
| 226 |
liveuser |
703 |
|
| 3 |
liveuser |
704 |
#回傳結果
|
|
|
705 |
return $result;
|
| 226 |
liveuser |
706 |
|
| 3 |
liveuser |
707 |
}#if end
|
| 226 |
liveuser |
708 |
|
| 3 |
liveuser |
709 |
#設定暫時的設定值
|
|
|
710 |
$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
|
| 226 |
liveuser |
711 |
|
| 3 |
liveuser |
712 |
#如果設定失敗
|
|
|
713 |
if($oldConfigValue===false){
|
| 226 |
liveuser |
714 |
|
| 3 |
liveuser |
715 |
#設置錯誤識別
|
|
|
716 |
$result["status"]="false";
|
| 226 |
liveuser |
717 |
|
| 3 |
liveuser |
718 |
#設置錯誤訊息
|
|
|
719 |
$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
|
| 226 |
liveuser |
720 |
|
| 3 |
liveuser |
721 |
#回傳結果
|
|
|
722 |
return $result;
|
| 226 |
liveuser |
723 |
|
| 3 |
liveuser |
724 |
}#if end
|
| 226 |
liveuser |
725 |
|
| 3 |
liveuser |
726 |
#反之儲存舊的永久設地數值
|
|
|
727 |
else{
|
| 226 |
liveuser |
728 |
|
| 3 |
liveuser |
729 |
#取得舊的設定值
|
|
|
730 |
$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
|
|
731 |
$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
| 226 |
liveuser |
732 |
|
| 3 |
liveuser |
733 |
#取得新的設定值
|
|
|
734 |
$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
|
|
735 |
$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
| 226 |
liveuser |
736 |
|
| 3 |
liveuser |
737 |
#計數加1
|
|
|
738 |
$count++;
|
| 226 |
liveuser |
739 |
|
| 3 |
liveuser |
740 |
}#else end
|
| 226 |
liveuser |
741 |
|
|
|
742 |
}#foreach end
|
|
|
743 |
|
| 3 |
liveuser |
744 |
#跳出switch
|
|
|
745 |
break;
|
| 226 |
liveuser |
746 |
|
| 3 |
liveuser |
747 |
#如果是自訂設定值的狀態
|
|
|
748 |
case "custom":
|
| 226 |
liveuser |
749 |
|
| 3 |
liveuser |
750 |
#初始化計數為0
|
|
|
751 |
$count=0;
|
| 226 |
liveuser |
752 |
|
| 3 |
liveuser |
753 |
#針對每個 $conf["customSettings"]
|
|
|
754 |
foreach($conf["customSettings"] as $configStr){
|
| 226 |
liveuser |
755 |
|
| 3 |
liveuser |
756 |
#用 "=" 分割設定字串
|
|
|
757 |
#函式說明:
|
|
|
758 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
759 |
#回傳的參數:
|
|
|
760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
761 |
#$result["error"],錯誤訊息陣列
|
|
|
762 |
#$result["function"],當前執行的函數名稱.
|
|
|
763 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
764 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
765 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
766 |
#必填參數:
|
|
|
767 |
$conf["stringProcess::spiltString"]["stringIn"]=$configStr;#要處理的字串。
|
|
|
768 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
769 |
#備註:
|
|
|
770 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
771 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
772 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
773 |
|
| 3 |
liveuser |
774 |
#如果分割設定值字串失敗
|
|
|
775 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
776 |
|
| 3 |
liveuser |
777 |
#設置錯誤識別
|
|
|
778 |
$result["status"]="false";
|
| 226 |
liveuser |
779 |
|
| 3 |
liveuser |
780 |
#設置錯誤訊息
|
|
|
781 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
782 |
|
| 3 |
liveuser |
783 |
#回傳結果
|
|
|
784 |
return $result;
|
| 226 |
liveuser |
785 |
|
| 3 |
liveuser |
786 |
}#if end
|
| 226 |
liveuser |
787 |
|
| 3 |
liveuser |
788 |
#如果只有一段內容
|
|
|
789 |
if($spiltString["dataCounts"]=="1"){
|
| 226 |
liveuser |
790 |
|
| 3 |
liveuser |
791 |
#設置錯誤識別
|
|
|
792 |
$result["status"]="false";
|
| 226 |
liveuser |
793 |
|
| 3 |
liveuser |
794 |
#設置錯誤訊息
|
|
|
795 |
$result["error"][]="設定值字串「".$configStr."」必須要用「=」來間隔設定屬性與其數值";
|
| 226 |
liveuser |
796 |
|
| 3 |
liveuser |
797 |
#回傳結果
|
|
|
798 |
return $result;
|
| 226 |
liveuser |
799 |
|
| 3 |
liveuser |
800 |
}#if end
|
| 226 |
liveuser |
801 |
|
| 3 |
liveuser |
802 |
#設定暫時的設定值
|
|
|
803 |
$oldConfigValue=ini_set($spiltString["dataArray"][0],$spiltString["dataArray"][1]);
|
| 226 |
liveuser |
804 |
|
| 3 |
liveuser |
805 |
#如果設定失敗
|
|
|
806 |
if($oldConfigValue===false){
|
| 226 |
liveuser |
807 |
|
| 3 |
liveuser |
808 |
#設置錯誤識別
|
|
|
809 |
$result["status"]="false";
|
| 226 |
liveuser |
810 |
|
| 3 |
liveuser |
811 |
#設置錯誤訊息
|
|
|
812 |
$result["error"][]="將屬性「".$spiltString["dataArray"][0]."」設定為「".$spiltString["dataArray"][1]."」失敗";
|
| 226 |
liveuser |
813 |
|
| 3 |
liveuser |
814 |
#回傳結果
|
|
|
815 |
return $result;
|
| 226 |
liveuser |
816 |
|
| 3 |
liveuser |
817 |
}#if end
|
| 226 |
liveuser |
818 |
|
| 3 |
liveuser |
819 |
#反之儲存舊的永久設地數值
|
|
|
820 |
else{
|
| 226 |
liveuser |
821 |
|
| 3 |
liveuser |
822 |
#取得舊的設定值
|
|
|
823 |
$result["config"][$count]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
|
|
824 |
$result["config"][$spiltString["dataArray"][0]]["oldValue"]=$spiltString["dataArray"][0]."=".$oldConfigValue;
|
| 226 |
liveuser |
825 |
|
| 3 |
liveuser |
826 |
#取得新的設定值
|
|
|
827 |
$result["config"][$count]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
|
|
828 |
$result["config"][$spiltString["dataArray"][0]]["newValue"]=$spiltString["dataArray"][0]."=".$spiltString["dataArray"][1];
|
| 226 |
liveuser |
829 |
|
| 3 |
liveuser |
830 |
#計數加1
|
|
|
831 |
$count++;
|
| 226 |
liveuser |
832 |
|
| 3 |
liveuser |
833 |
}#else end
|
| 226 |
liveuser |
834 |
|
| 3 |
liveuser |
835 |
}#foreach end
|
| 226 |
liveuser |
836 |
|
| 3 |
liveuser |
837 |
#跳出switch
|
|
|
838 |
break;
|
| 226 |
liveuser |
839 |
|
|
|
840 |
#如果不是以上狀況,那就是參數錯誤
|
| 3 |
liveuser |
841 |
default :
|
| 226 |
liveuser |
842 |
|
| 3 |
liveuser |
843 |
#設置錯誤訊息
|
|
|
844 |
$result["error"][]="\$conf[\"mode\"]模式設定錯誤";
|
| 226 |
liveuser |
845 |
|
| 3 |
liveuser |
846 |
#設置執行失敗
|
|
|
847 |
$result["status"]="false";
|
| 226 |
liveuser |
848 |
|
| 3 |
liveuser |
849 |
#回傳結果
|
|
|
850 |
return $result;
|
| 226 |
liveuser |
851 |
|
| 3 |
liveuser |
852 |
}#switch end
|
| 226 |
liveuser |
853 |
|
| 3 |
liveuser |
854 |
#設置執行正常
|
|
|
855 |
$result["status"]="true";
|
| 226 |
liveuser |
856 |
|
| 3 |
liveuser |
857 |
#回傳結果
|
|
|
858 |
return $result;
|
| 226 |
liveuser |
859 |
|
| 3 |
liveuser |
860 |
}#funciton changeSettings end
|
| 226 |
liveuser |
861 |
|
| 3 |
liveuser |
862 |
/*
|
|
|
863 |
#函式說明:
|
|
|
864 |
#依照條件增加記憶體的上限.
|
|
|
865 |
#回傳結果:
|
|
|
866 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
867 |
#$result["error"],錯誤訊息陣列.
|
|
|
868 |
#$result["function"],當前執行的函數名稱.
|
|
|
869 |
#$result["argu"],使用的參數.
|
|
|
870 |
#$result["content"],提示訊息.
|
|
|
871 |
#$result["stdout"],若有serverCache參數,則會回傳該項目,代表執行程式過程中的標準輸出.
|
|
|
872 |
#$result["stderr"],若有serverCache參數,則會回傳該項目,代表執行程式過程中的非標準輸出.
|
|
|
873 |
#$result["cache"],若有serverCache參數,則會回傳該項目,代表執行本函式程式的回傳結果.
|
|
|
874 |
#必填參數:
|
|
|
875 |
#無.
|
|
|
876 |
#可省略參數:
|
|
|
877 |
#$conf["stepAmount"],一次要增加多少上限,預設為當前環境的上限,單位位M(Mega Bytes).
|
|
|
878 |
#$conf["stepAmount"]="";
|
|
|
879 |
#$conf["whenAviMemLessThan"],字串整數,什麼時候要增加記憶體,預設為可用的記憶體不超過10%時,亦即10;範圍為1~50,亦即範圍為1~50%.
|
|
|
880 |
#$conf["whenAviMemLessThan"]="10"
|
|
|
881 |
#$conf["client"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為所有用戶的資訊.
|
|
|
882 |
#$conf["client"]=;
|
|
|
883 |
#$conf["serverCache"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為
|
|
|
884 |
#$conf["serverCache"]=;
|
|
|
885 |
#參考資料:
|
|
|
886 |
#https://www.php.net/manual/en/function.memory-get-usage.php
|
|
|
887 |
#https://www.php.net/manual/en/ini.core.php#ini.memory-limit
|
|
|
888 |
#https://www.php.net/manual/en/function.ini-set.php
|
|
|
889 |
#備註:
|
|
|
890 |
#無.
|
|
|
891 |
*/
|
|
|
892 |
public static function autoAddMemory(&$conf=array()){
|
| 226 |
liveuser |
893 |
|
| 3 |
liveuser |
894 |
#初始化要回傳的結果
|
|
|
895 |
$result=array();
|
|
|
896 |
|
|
|
897 |
#取得當前執行的函數名稱
|
|
|
898 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
899 |
|
| 3 |
liveuser |
900 |
#取得參數
|
|
|
901 |
$result["argu"]=$conf;
|
|
|
902 |
|
|
|
903 |
#如果 $conf 不為陣列
|
|
|
904 |
if(gettype($conf)!="array"){
|
|
|
905 |
|
|
|
906 |
#設置執行失敗
|
|
|
907 |
$result["status"]="false";
|
|
|
908 |
|
|
|
909 |
#設置執行錯誤訊息
|
|
|
910 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
911 |
|
|
|
912 |
#如果傳入的參數為 null
|
|
|
913 |
if(is_null($conf)){
|
|
|
914 |
|
|
|
915 |
#設置執行錯誤訊息
|
|
|
916 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
917 |
|
|
|
918 |
}#if end
|
|
|
919 |
|
|
|
920 |
#回傳結果
|
|
|
921 |
return $result;
|
|
|
922 |
|
|
|
923 |
}#if end
|
| 226 |
liveuser |
924 |
|
| 3 |
liveuser |
925 |
#函式說明:
|
|
|
926 |
#顯示目前的php設定值
|
|
|
927 |
#回傳的結果:
|
|
|
928 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
929 |
#$result["error"],錯誤訊息陣列.
|
|
|
930 |
#$result["function"],當前執行的函數名稱.
|
|
|
931 |
#$result["content"],常用的設定值的內容、也可指定想要看的設定值內容.
|
|
|
932 |
#必填參數:
|
|
|
933 |
#無.
|
|
|
934 |
#可省略參數:
|
|
|
935 |
#$conf["settingsName"],字串陣列,自己想要看的設定值內容,預設為array("display_errors","upload_max_filesize","post_max_size","output_buffering","session.auto_start","memory_limit").
|
|
|
936 |
$conf["config::showSettings"]["settingsName"]=array("memory_limit");
|
|
|
937 |
#$conf["showAll"],字串,是否要取得所有設定,"true"代表要,會覆寫$conf["settingsName"]的設定,"false"代表不要,預設為"fale".
|
|
|
938 |
#$conf["showAll"]="";
|
|
|
939 |
#參考資料:
|
|
|
940 |
#http://www.php.net/manual/en/function.ini-get.php
|
|
|
941 |
#http://www.php.net/manual/en/function.ini-get-all.php
|
|
|
942 |
#備註:
|
|
|
943 |
#無.
|
|
|
944 |
$showSettings=config::showSettings($conf["config::showSettings"]);
|
|
|
945 |
unset($conf["config::showSettings"]);
|
| 226 |
liveuser |
946 |
|
| 3 |
liveuser |
947 |
#如果執行失敗
|
|
|
948 |
if($showSettings["status"]==="false"){
|
| 226 |
liveuser |
949 |
|
| 3 |
liveuser |
950 |
#設置執行失敗
|
|
|
951 |
$result["status"]="false";
|
| 226 |
liveuser |
952 |
|
| 3 |
liveuser |
953 |
#設置錯誤資訊
|
|
|
954 |
$result["error"]=$showSettings;
|
| 226 |
liveuser |
955 |
|
| 3 |
liveuser |
956 |
#回傳結果
|
|
|
957 |
return $result;
|
| 226 |
liveuser |
958 |
|
| 3 |
liveuser |
959 |
}#if end
|
| 226 |
liveuser |
960 |
|
| 3 |
liveuser |
961 |
#取得系統設定的php記憶體上限
|
|
|
962 |
$phpMaxMemInConfig=$showSettings["content"]["memory_limit"];
|
| 226 |
liveuser |
963 |
|
| 3 |
liveuser |
964 |
#如果單位是M
|
|
|
965 |
#函式說明:
|
|
|
966 |
#取得符合特定字首與字尾的字串
|
|
|
967 |
#回傳結果:
|
|
|
968 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
969 |
#$result["function"],當前執行的函數名稱.
|
|
|
970 |
#$result["error"],錯誤訊息陣列.
|
|
|
971 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
972 |
#$result["content"],符合條件的字串,去掉字首字尾後的結果.
|
|
|
973 |
#$result["returnString"],爲符合字首字、尾條件的字串內容。
|
|
|
974 |
#$result["argu"],使用的參數.
|
|
|
975 |
#必填參數:
|
|
|
976 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
977 |
$conf["stringProcess::getMeetConditionsString"]["checkString"]=$phpMaxMemInConfig;
|
|
|
978 |
#可省略參數:
|
|
|
979 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
980 |
#$conf["stringProcess::getMeetConditionsString"]["frontWord"]="";
|
|
|
981 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
982 |
$conf["stringProcess::getMeetConditionsString"]["tailWord"]="M";
|
|
|
983 |
#參考資料:
|
|
|
984 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
985 |
#備註:
|
|
|
986 |
#無.
|
|
|
987 |
$getMeetConditionsString=search::getMeetConditionsString($conf["stringProcess::getMeetConditionsString"]);
|
|
|
988 |
unset($conf["stringProcess::getMeetConditionsString"]);
|
| 226 |
liveuser |
989 |
|
| 3 |
liveuser |
990 |
#如果執行失敗
|
|
|
991 |
if($getMeetConditionsString["status"]==="false"){
|
| 226 |
liveuser |
992 |
|
| 3 |
liveuser |
993 |
#設置執行失敗
|
|
|
994 |
$result["status"]="false";
|
| 226 |
liveuser |
995 |
|
| 3 |
liveuser |
996 |
#設置錯誤資訊
|
|
|
997 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
998 |
|
| 3 |
liveuser |
999 |
#回傳結果
|
|
|
1000 |
return $result;
|
| 226 |
liveuser |
1001 |
|
| 3 |
liveuser |
1002 |
}#if end
|
| 226 |
liveuser |
1003 |
|
| 3 |
liveuser |
1004 |
#如果是M結尾
|
|
|
1005 |
if($getMeetConditionsString["founded"]==="true"){
|
| 226 |
liveuser |
1006 |
|
| 3 |
liveuser |
1007 |
#轉換為bytes
|
|
|
1008 |
$phpMaxMemInConfig=$getMeetConditionsString["content"]*1024*1024;
|
| 226 |
liveuser |
1009 |
|
| 3 |
liveuser |
1010 |
}#if end
|
| 226 |
liveuser |
1011 |
|
| 3 |
liveuser |
1012 |
#函式說明:
|
|
|
1013 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
1014 |
#回傳結果:
|
|
|
1015 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1016 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
1017 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
1018 |
#$result["function"],當前執行的函式名稱.
|
|
|
1019 |
#$result["argu"],設置給予的參數.
|
|
|
1020 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1021 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1022 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1023 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1024 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1025 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1026 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1027 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1028 |
#必填參數:
|
|
|
1029 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1030 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1031 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1032 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1033 |
#可省略參數:
|
|
|
1034 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1035 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stepAmount");
|
|
|
1036 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1037 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1038 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1039 |
#$conf["canBeEmptyString"]="false";
|
|
|
1040 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1041 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1042 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1043 |
#$conf["canBeEmpty"]=array();
|
|
|
1044 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1045 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("stepAmount","whenAviMemLessThan");
|
|
|
1046 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1047 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("stepAmount","whenAviMemLessThan","client","serverCache");
|
|
|
1048 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1049 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
|
|
|
1050 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1051 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($phpMaxMemInConfig,"10",null,null);
|
|
|
1052 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1053 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1054 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1055 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1056 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1057 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1058 |
#參考資料:
|
|
|
1059 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1060 |
#備註:
|
|
|
1061 |
#無.
|
|
|
1062 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1063 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1064 |
|
| 3 |
liveuser |
1065 |
#如果執行失敗
|
|
|
1066 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
1067 |
|
| 3 |
liveuser |
1068 |
#設置執行失敗
|
|
|
1069 |
$result["status"]="false";
|
|
|
1070 |
|
|
|
1071 |
#設置執行錯誤訊息
|
|
|
1072 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1073 |
|
| 3 |
liveuser |
1074 |
#回傳結果
|
|
|
1075 |
return $result;
|
| 226 |
liveuser |
1076 |
|
| 3 |
liveuser |
1077 |
}#if end
|
| 226 |
liveuser |
1078 |
|
| 3 |
liveuser |
1079 |
#如果檢查不通過
|
|
|
1080 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
1081 |
|
| 3 |
liveuser |
1082 |
#設置執行失敗
|
|
|
1083 |
$result["status"]="false";
|
|
|
1084 |
|
|
|
1085 |
#設置執行錯誤訊息
|
|
|
1086 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1087 |
|
| 3 |
liveuser |
1088 |
#回傳結果
|
|
|
1089 |
return $result;
|
| 226 |
liveuser |
1090 |
|
| 3 |
liveuser |
1091 |
}#if end
|
| 226 |
liveuser |
1092 |
|
| 3 |
liveuser |
1093 |
#如果有 serverCache
|
|
|
1094 |
if(isset($conf["serverCache"])){
|
| 226 |
liveuser |
1095 |
|
| 3 |
liveuser |
1096 |
/* debug
|
| 226 |
liveuser |
1097 |
|
| 3 |
liveuser |
1098 |
#函式說明:
|
|
|
1099 |
#撰寫log
|
|
|
1100 |
#回傳結果:
|
|
|
1101 |
#$result["status"],狀態,"true"或"false".
|
|
|
1102 |
#$result["error"],錯誤訊息陣列.
|
|
|
1103 |
#$result["function"],當前函式的名稱.
|
|
|
1104 |
#$result["argu"],使用的參數.
|
|
|
1105 |
#$result["content"],要寫入log的內容字串.
|
|
|
1106 |
#必填參數:
|
|
|
1107 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
1108 |
$conf["logs::record"]["path"]="/tmp/config::autoAddMemory.log";
|
|
|
1109 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
1110 |
$conf["logs::record"]["content"]=$conf["serverCache"];
|
|
|
1111 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1112 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1113 |
#可省略參數:
|
|
|
1114 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1115 |
#$conf["rewrite"]="false";
|
|
|
1116 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
1117 |
#$conf["returnOnly"]="true";
|
|
|
1118 |
#參考資料:
|
|
|
1119 |
#無.
|
|
|
1120 |
#備註:
|
|
|
1121 |
#無.
|
|
|
1122 |
$record=logs::record($conf["logs::record"]);
|
|
|
1123 |
unset($conf["logs::record"]);
|
| 226 |
liveuser |
1124 |
|
| 3 |
liveuser |
1125 |
#如果執行失敗
|
|
|
1126 |
if($record["status"]==="false"){
|
| 226 |
liveuser |
1127 |
|
| 3 |
liveuser |
1128 |
#設置執行錯誤識別
|
|
|
1129 |
$result["status"]="false";
|
| 226 |
liveuser |
1130 |
|
| 3 |
liveuser |
1131 |
#設置執行錯誤
|
|
|
1132 |
$result["error"]=$record;
|
| 226 |
liveuser |
1133 |
|
| 3 |
liveuser |
1134 |
#回傳結果
|
|
|
1135 |
return $result;
|
| 226 |
liveuser |
1136 |
|
| 3 |
liveuser |
1137 |
}#if end
|
| 226 |
liveuser |
1138 |
|
| 3 |
liveuser |
1139 |
*/
|
| 226 |
liveuser |
1140 |
|
| 3 |
liveuser |
1141 |
#記錄回傳的參考
|
|
|
1142 |
#$result["cache"]=&$result;
|
| 226 |
liveuser |
1143 |
|
| 3 |
liveuser |
1144 |
#如果有 clientSide
|
|
|
1145 |
if(isset($conf["serverCache"]["clientSide"])){
|
| 226 |
liveuser |
1146 |
|
| 3 |
liveuser |
1147 |
#如果有 addOnProcessFunc
|
|
|
1148 |
if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"])){
|
| 226 |
liveuser |
1149 |
|
| 3 |
liveuser |
1150 |
#如果有 addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon
|
|
|
1151 |
if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"])){
|
| 226 |
liveuser |
1152 |
|
| 3 |
liveuser |
1153 |
/* debug
|
| 226 |
liveuser |
1154 |
|
| 3 |
liveuser |
1155 |
#函式說明:
|
|
|
1156 |
#撰寫log
|
|
|
1157 |
#回傳結果:
|
|
|
1158 |
#$result["status"],狀態,"true"或"false".
|
|
|
1159 |
#$result["error"],錯誤訊息陣列.
|
|
|
1160 |
#$result["function"],當前函式的名稱.
|
|
|
1161 |
#$result["argu"],使用的參數.
|
|
|
1162 |
#$result["content"],要寫入log的內容字串.
|
|
|
1163 |
#必填參數:
|
|
|
1164 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
1165 |
$conf["logs::record"]["path"]="/tmp/config::autoAddMemory.log";
|
|
|
1166 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
1167 |
$conf["logs::record"]["content"]=$conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"];
|
|
|
1168 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1169 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1170 |
#可省略參數:
|
|
|
1171 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1172 |
#$conf["rewrite"]="false";
|
|
|
1173 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
1174 |
#$conf["returnOnly"]="true";
|
|
|
1175 |
#參考資料:
|
|
|
1176 |
#無.
|
|
|
1177 |
#備註:
|
|
|
1178 |
#無.
|
|
|
1179 |
$record=logs::record($conf["logs::record"]);
|
|
|
1180 |
unset($conf["logs::record"]);
|
| 226 |
liveuser |
1181 |
|
| 3 |
liveuser |
1182 |
#如果執行失敗
|
|
|
1183 |
if($record["status"]==="false"){
|
| 226 |
liveuser |
1184 |
|
| 3 |
liveuser |
1185 |
#設置執行錯誤識別
|
|
|
1186 |
$result["status"]="false";
|
| 226 |
liveuser |
1187 |
|
| 3 |
liveuser |
1188 |
#設置執行錯誤
|
|
|
1189 |
$result["error"]=$record;
|
| 226 |
liveuser |
1190 |
|
| 3 |
liveuser |
1191 |
#回傳結果
|
|
|
1192 |
return $result;
|
| 226 |
liveuser |
1193 |
|
| 3 |
liveuser |
1194 |
}#if end
|
| 226 |
liveuser |
1195 |
|
| 3 |
liveuser |
1196 |
*/
|
| 226 |
liveuser |
1197 |
|
| 3 |
liveuser |
1198 |
#如果有程式在背景執行
|
|
|
1199 |
if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"])){
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
#如果該程序資訊存在
|
|
|
1202 |
if(isset($conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0])){
|
| 226 |
liveuser |
1203 |
|
| 3 |
liveuser |
1204 |
#另存程序變數參考
|
|
|
1205 |
$process=&$conf["serverCache"]["clientSide"]["addOnProcessFunc"]["\qbpwcf\sock::addOnProcessFuncForUnixDomainSockServerInRunWithAutoAddMemoryDaemon"]["content"][0];
|
| 226 |
liveuser |
1206 |
|
| 3 |
liveuser |
1207 |
/* debug
|
| 226 |
liveuser |
1208 |
|
| 3 |
liveuser |
1209 |
#函式說明:
|
|
|
1210 |
#撰寫log
|
|
|
1211 |
#回傳結果:
|
|
|
1212 |
#$result["status"],狀態,"true"或"false".
|
|
|
1213 |
#$result["error"],錯誤訊息陣列.
|
|
|
1214 |
#$result["function"],當前函式的名稱.
|
|
|
1215 |
#$result["argu"],使用的參數.
|
|
|
1216 |
#$result["content"],要寫入log的內容字串.
|
|
|
1217 |
#必填參數:
|
|
|
1218 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
1219 |
$conf["logs::record"]["path"]="/tmp/config::autoAddMemory.log";
|
|
|
1220 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
1221 |
$conf["logs::record"]["content"]=$process;
|
|
|
1222 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1223 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1224 |
#可省略參數:
|
|
|
1225 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1226 |
#$conf["rewrite"]="false";
|
|
|
1227 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
1228 |
#$conf["returnOnly"]="true";
|
|
|
1229 |
#參考資料:
|
|
|
1230 |
#無.
|
|
|
1231 |
#備註:
|
|
|
1232 |
#無.
|
|
|
1233 |
$record=logs::record($conf["logs::record"]);
|
|
|
1234 |
unset($conf["logs::record"]);
|
| 226 |
liveuser |
1235 |
|
| 3 |
liveuser |
1236 |
#如果執行失敗
|
|
|
1237 |
if($record["status"]==="false"){
|
| 226 |
liveuser |
1238 |
|
| 3 |
liveuser |
1239 |
#設置執行錯誤識別
|
|
|
1240 |
$result["status"]="false";
|
| 226 |
liveuser |
1241 |
|
| 3 |
liveuser |
1242 |
#設置執行錯誤
|
|
|
1243 |
$result["error"]=$record;
|
| 226 |
liveuser |
1244 |
|
| 3 |
liveuser |
1245 |
#回傳結果
|
|
|
1246 |
return $result;
|
| 226 |
liveuser |
1247 |
|
| 3 |
liveuser |
1248 |
}#if end
|
| 226 |
liveuser |
1249 |
|
| 3 |
liveuser |
1250 |
*/
|
| 226 |
liveuser |
1251 |
|
| 3 |
liveuser |
1252 |
#取得標準輸出
|
|
|
1253 |
$result["stdout"]=$process["content"];
|
| 226 |
liveuser |
1254 |
|
| 3 |
liveuser |
1255 |
#取得非標準輸出
|
|
|
1256 |
$result["error"]=$process["error"];
|
| 226 |
liveuser |
1257 |
|
| 3 |
liveuser |
1258 |
#如果標準輸出是 reource
|
|
|
1259 |
if(gettype($process["content"])==="resource"){
|
| 226 |
liveuser |
1260 |
|
| 3 |
liveuser |
1261 |
#取得程式執行過程產生的標準輸出
|
|
|
1262 |
$result["stdout"]=stream_get_contents($process["content"]);
|
| 226 |
liveuser |
1263 |
|
| 3 |
liveuser |
1264 |
}#if end
|
| 226 |
liveuser |
1265 |
|
| 3 |
liveuser |
1266 |
#如果非標準輸出是 reource
|
|
|
1267 |
if(gettype($process["error"])==="resource"){
|
| 226 |
liveuser |
1268 |
|
| 3 |
liveuser |
1269 |
#取得程式執行過程產生的標準輸出
|
|
|
1270 |
$result["error"]=stream_get_contents($process["error"]);
|
| 226 |
liveuser |
1271 |
|
| 3 |
liveuser |
1272 |
}#if end
|
| 226 |
liveuser |
1273 |
|
| 3 |
liveuser |
1274 |
#如果記錄上顯示該程序尚在執行中
|
|
|
1275 |
if($process["proc_get_status"]["running"]===true){
|
| 226 |
liveuser |
1276 |
|
| 3 |
liveuser |
1277 |
#嘗試取得該程序的狀態
|
|
|
1278 |
$proc_get_status=proc_get_status($process["process"]);
|
| 226 |
liveuser |
1279 |
|
| 3 |
liveuser |
1280 |
#如果已經結束執行
|
|
|
1281 |
if($proc_get_status["running"]===false){
|
| 226 |
liveuser |
1282 |
|
| 3 |
liveuser |
1283 |
#設置要結束執行unix domain server
|
|
|
1284 |
$result["exit"]="true";
|
| 226 |
liveuser |
1285 |
|
| 3 |
liveuser |
1286 |
#設置執行正常
|
|
|
1287 |
$result["status"]="true";
|
| 226 |
liveuser |
1288 |
|
| 3 |
liveuser |
1289 |
}#if end
|
| 226 |
liveuser |
1290 |
|
| 3 |
liveuser |
1291 |
}#if end
|
| 226 |
liveuser |
1292 |
|
| 3 |
liveuser |
1293 |
#反之代表程序已經結束
|
|
|
1294 |
else{
|
| 226 |
liveuser |
1295 |
|
| 3 |
liveuser |
1296 |
#設置要結束執行unix domain server
|
|
|
1297 |
$result["exit"]="true";
|
| 226 |
liveuser |
1298 |
|
| 3 |
liveuser |
1299 |
#設置執行正常
|
|
|
1300 |
$result["status"]="true";
|
| 226 |
liveuser |
1301 |
|
| 3 |
liveuser |
1302 |
}#else end
|
| 226 |
liveuser |
1303 |
|
| 3 |
liveuser |
1304 |
/* debug
|
| 226 |
liveuser |
1305 |
|
| 3 |
liveuser |
1306 |
#函式說明:
|
|
|
1307 |
#撰寫log
|
|
|
1308 |
#回傳結果:
|
|
|
1309 |
#$result["status"],狀態,"true"或"false".
|
|
|
1310 |
#$result["error"],錯誤訊息陣列.
|
|
|
1311 |
#$result["function"],當前函式的名稱.
|
|
|
1312 |
#$result["argu"],使用的參數.
|
|
|
1313 |
#$result["content"],要寫入log的內容字串.
|
|
|
1314 |
#必填參數:
|
|
|
1315 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
1316 |
$conf["logs::record"]["path"]="/tmp/config::autoAddMemory.log";
|
|
|
1317 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
1318 |
$conf["logs::record"]["content"]=$result;
|
|
|
1319 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1320 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1321 |
#可省略參數:
|
|
|
1322 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1323 |
#$conf["rewrite"]="false";
|
|
|
1324 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
1325 |
#$conf["returnOnly"]="true";
|
|
|
1326 |
#參考資料:
|
|
|
1327 |
#無.
|
|
|
1328 |
#備註:
|
|
|
1329 |
#無.
|
|
|
1330 |
$record=logs::record($conf["logs::record"]);
|
|
|
1331 |
unset($conf["logs::record"]);
|
| 226 |
liveuser |
1332 |
|
| 3 |
liveuser |
1333 |
#如果執行失敗
|
|
|
1334 |
if($record["status"]==="false"){
|
| 226 |
liveuser |
1335 |
|
| 3 |
liveuser |
1336 |
#設置執行錯誤識別
|
|
|
1337 |
$result["status"]="false";
|
| 226 |
liveuser |
1338 |
|
| 3 |
liveuser |
1339 |
#設置執行錯誤
|
|
|
1340 |
$result["error"]=$record;
|
| 226 |
liveuser |
1341 |
|
| 3 |
liveuser |
1342 |
#回傳結果
|
|
|
1343 |
return $result;
|
| 226 |
liveuser |
1344 |
|
| 3 |
liveuser |
1345 |
}#if end
|
| 226 |
liveuser |
1346 |
|
| 3 |
liveuser |
1347 |
*/
|
| 226 |
liveuser |
1348 |
|
| 3 |
liveuser |
1349 |
}#if end
|
| 226 |
liveuser |
1350 |
|
| 3 |
liveuser |
1351 |
}#if end
|
| 226 |
liveuser |
1352 |
|
| 3 |
liveuser |
1353 |
}#if end
|
| 226 |
liveuser |
1354 |
|
| 3 |
liveuser |
1355 |
}#if end
|
| 226 |
liveuser |
1356 |
|
| 3 |
liveuser |
1357 |
}#if end
|
| 226 |
liveuser |
1358 |
|
| 3 |
liveuser |
1359 |
}#if end
|
| 226 |
liveuser |
1360 |
|
|
|
1361 |
#如果參數 whenAviMemLessThan 不為
|
| 3 |
liveuser |
1362 |
$whenAviMemLessThan=(int)($conf["whenAviMemLessThan"]);
|
| 226 |
liveuser |
1363 |
|
| 3 |
liveuser |
1364 |
#如果小於1
|
|
|
1365 |
if($whenAviMemLessThan<1){
|
| 226 |
liveuser |
1366 |
|
| 3 |
liveuser |
1367 |
#設置為1
|
|
|
1368 |
$whenAviMemLessThan=1;
|
| 226 |
liveuser |
1369 |
|
| 3 |
liveuser |
1370 |
}#if end
|
| 226 |
liveuser |
1371 |
|
| 3 |
liveuser |
1372 |
#如果大於50
|
|
|
1373 |
else if($whenAviMemLessThan>50){
|
| 226 |
liveuser |
1374 |
|
| 3 |
liveuser |
1375 |
#設置為50
|
|
|
1376 |
$whenAviMemLessThan=50;
|
| 226 |
liveuser |
1377 |
|
| 3 |
liveuser |
1378 |
}#if end
|
| 226 |
liveuser |
1379 |
|
| 3 |
liveuser |
1380 |
#計算需要增加記憶體的門檻
|
|
|
1381 |
$condition=$phpMaxMemInConfig*$whenAviMemLessThan/100;
|
| 226 |
liveuser |
1382 |
|
| 3 |
liveuser |
1383 |
#get memeory usage
|
|
|
1384 |
$memUsedInBytes=\memory_get_usage();
|
| 226 |
liveuser |
1385 |
|
| 3 |
liveuser |
1386 |
#如果使用的記憶體已經達到門檻
|
|
|
1387 |
if($memUsedInBytes>=$condition){
|
| 226 |
liveuser |
1388 |
|
| 3 |
liveuser |
1389 |
#計算新的記憶體上限
|
|
|
1390 |
$newMemoryLimit=$phpMaxMemInConfig+$stepAmount;
|
| 226 |
liveuser |
1391 |
|
| 3 |
liveuser |
1392 |
#依照 stepAmount 來增加可用記憶體的上限
|
|
|
1393 |
$return=\ini_set("memory_limit",$stepAmount);
|
| 226 |
liveuser |
1394 |
|
| 3 |
liveuser |
1395 |
#如果設置失敗
|
|
|
1396 |
if($return===false){
|
| 226 |
liveuser |
1397 |
|
| 3 |
liveuser |
1398 |
#設置執行失敗
|
|
|
1399 |
$result["status"]="false";
|
|
|
1400 |
|
|
|
1401 |
#設置執行錯誤訊息
|
|
|
1402 |
$result["error"][]="加大記憶體上限失敗";
|
| 226 |
liveuser |
1403 |
|
| 3 |
liveuser |
1404 |
#cache
|
|
|
1405 |
$result["cache"]=&$result;
|
| 226 |
liveuser |
1406 |
|
| 3 |
liveuser |
1407 |
#回傳結果
|
|
|
1408 |
return $result;
|
| 226 |
liveuser |
1409 |
|
| 3 |
liveuser |
1410 |
}#if end
|
| 226 |
liveuser |
1411 |
|
| 3 |
liveuser |
1412 |
#設置正常訊息
|
|
|
1413 |
$result["content"]="memeory_limit changed from ".$return." to ".$newMemoryLimit;
|
| 226 |
liveuser |
1414 |
|
| 3 |
liveuser |
1415 |
}#if end
|
| 226 |
liveuser |
1416 |
|
| 3 |
liveuser |
1417 |
#提示未改變
|
| 226 |
liveuser |
1418 |
$result["content"]="memeory_limit not changed";
|
|
|
1419 |
|
| 3 |
liveuser |
1420 |
#設置執行正常
|
|
|
1421 |
$result["status"]="true";
|
| 226 |
liveuser |
1422 |
|
| 3 |
liveuser |
1423 |
#cache
|
|
|
1424 |
$result["cache"]=&$result;
|
| 226 |
liveuser |
1425 |
|
| 3 |
liveuser |
1426 |
#回傳結果
|
|
|
1427 |
return $result;
|
| 226 |
liveuser |
1428 |
|
| 3 |
liveuser |
1429 |
}#function autoAddMemory end
|
| 226 |
liveuser |
1430 |
|
| 3 |
liveuser |
1431 |
/*
|
|
|
1432 |
#函式說明:
|
|
|
1433 |
#建立供 apache 讀取的設定檔案.
|
|
|
1434 |
#回傳結果:
|
|
|
1435 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1436 |
#$result["error"],錯誤訊息陣列.
|
|
|
1437 |
#$result["function"],當前執行的函數名稱.
|
|
|
1438 |
#$result["content"],定義對應的內容.
|
|
|
1439 |
#必填參數:
|
|
|
1440 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1441 |
$conf["fileArgu"]=__FILE__;
|
|
|
1442 |
#$conf["configFileAddr"],字串,定義檔位置與名稱
|
|
|
1443 |
$conf["configFileAddr"]="";
|
|
|
1444 |
#$conf["content"],陣列,要儲存的key -> value 陣列.
|
|
|
1445 |
$conf["content"]=array("169.254.1.1"=>array("groupName"=>"local"));
|
|
|
1446 |
#可省略參數:
|
|
|
1447 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為後者.
|
|
|
1448 |
#$conf["web"]="false";
|
|
|
1449 |
#參考資料:
|
|
|
1450 |
#無.
|
|
|
1451 |
#備註:
|
|
|
1452 |
#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
|
|
|
1453 |
*/
|
|
|
1454 |
public static function create(&$conf=array()){
|
| 226 |
liveuser |
1455 |
|
| 3 |
liveuser |
1456 |
#初始化要回傳的結果
|
|
|
1457 |
$result=array();
|
|
|
1458 |
|
|
|
1459 |
#儲存當前執行的函數
|
|
|
1460 |
$result["function"]=__FUNCTION__;
|
|
|
1461 |
|
|
|
1462 |
#如果 $conf 不為陣列
|
|
|
1463 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1464 |
|
| 3 |
liveuser |
1465 |
#設置執行失敗
|
|
|
1466 |
$result["status"]="false";
|
| 226 |
liveuser |
1467 |
|
| 3 |
liveuser |
1468 |
#設置執行錯誤訊息
|
|
|
1469 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1470 |
|
|
|
1471 |
#如果傳入的參數為 null
|
|
|
1472 |
if($conf==null){
|
| 226 |
liveuser |
1473 |
|
| 3 |
liveuser |
1474 |
#設置執行錯誤訊息
|
|
|
1475 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1476 |
|
| 3 |
liveuser |
1477 |
}#if end
|
|
|
1478 |
|
|
|
1479 |
#回傳結果
|
|
|
1480 |
return $result;
|
| 226 |
liveuser |
1481 |
|
| 3 |
liveuser |
1482 |
}#if end
|
| 226 |
liveuser |
1483 |
|
| 3 |
liveuser |
1484 |
#檢查參數
|
|
|
1485 |
#函式說明:
|
|
|
1486 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1487 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1488 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1489 |
#$result["function"],當前執行的函式名稱.
|
|
|
1490 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1491 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1492 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1493 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1494 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1495 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1496 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1497 |
#必填寫的參數:
|
|
|
1498 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1499 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1500 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1501 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr","content");
|
| 226 |
liveuser |
1502 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1503 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
1504 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1505 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1506 |
#可以省略的參數:
|
|
|
1507 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1508 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1509 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1510 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
| 226 |
liveuser |
1511 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1512 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1513 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1514 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
1515 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1516 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1517 |
#參考資料來源:
|
|
|
1518 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1519 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1520 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1521 |
|
| 3 |
liveuser |
1522 |
#如果檢查失敗
|
|
|
1523 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1524 |
|
| 3 |
liveuser |
1525 |
#設置錯誤識別
|
|
|
1526 |
$result["status"]="false";
|
| 226 |
liveuser |
1527 |
|
| 3 |
liveuser |
1528 |
#設置錯誤訊息
|
|
|
1529 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1530 |
|
| 3 |
liveuser |
1531 |
#回傳結果
|
|
|
1532 |
return $result;
|
| 226 |
liveuser |
1533 |
|
| 3 |
liveuser |
1534 |
}#if end
|
| 226 |
liveuser |
1535 |
|
| 3 |
liveuser |
1536 |
#如果檢查不通過
|
|
|
1537 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1538 |
|
| 3 |
liveuser |
1539 |
#設置錯誤識別
|
|
|
1540 |
$result["status"]="false";
|
| 226 |
liveuser |
1541 |
|
| 3 |
liveuser |
1542 |
#設置錯誤訊息
|
|
|
1543 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1544 |
|
| 3 |
liveuser |
1545 |
#回傳結果
|
|
|
1546 |
return $result;
|
| 226 |
liveuser |
1547 |
|
| 3 |
liveuser |
1548 |
}#if end
|
| 226 |
liveuser |
1549 |
|
| 3 |
liveuser |
1550 |
#debug
|
| 226 |
liveuser |
1551 |
#var_dump($conf["content"]);exit;
|
|
|
1552 |
|
| 3 |
liveuser |
1553 |
#函式說明:
|
|
|
1554 |
#將字串寫入到檔案
|
|
|
1555 |
#回傳結果:
|
|
|
1556 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
1557 |
#$result["error"],錯誤訊息陣列.
|
|
|
1558 |
#$result["function"],當前執行的函數名稱.
|
|
|
1559 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
1560 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
1561 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
1562 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
1563 |
#$result["argu"],使用的參數.
|
|
|
1564 |
#必填參數:
|
|
|
1565 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1566 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1567 |
#可省略參數:
|
|
|
1568 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
1569 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["configFileAddr"];
|
|
|
1570 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
1571 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]=base64_encode(urlencode(json_encode($conf["content"])));
|
|
|
1572 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
1573 |
#$conf["writeMethod"]="a";
|
|
|
1574 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
1575 |
#$conf["checkRepeat"]="";
|
|
|
1576 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
1577 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
1578 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
1579 |
#$conf["repeatNameRule"]="";
|
|
|
1580 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
1581 |
$conf["fileAccess::writeTextIntoFile"]["web"]="false";
|
|
|
1582 |
#參考資料:
|
|
|
1583 |
#無.
|
|
|
1584 |
#備註:
|
|
|
1585 |
#無.
|
|
|
1586 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
1587 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
| 226 |
liveuser |
1588 |
|
| 3 |
liveuser |
1589 |
#如果執行敗
|
|
|
1590 |
if($writeTextIntoFile["status"]=="false"){
|
| 226 |
liveuser |
1591 |
|
| 3 |
liveuser |
1592 |
#設置錯誤識別
|
|
|
1593 |
$result["status"]="false";
|
| 226 |
liveuser |
1594 |
|
| 3 |
liveuser |
1595 |
#設置錯誤訊息
|
|
|
1596 |
$result["error"]=$writeTextIntoFile;
|
| 226 |
liveuser |
1597 |
|
| 3 |
liveuser |
1598 |
#回傳結果
|
|
|
1599 |
return $result;
|
| 226 |
liveuser |
1600 |
|
| 3 |
liveuser |
1601 |
}#if end
|
| 226 |
liveuser |
1602 |
|
| 3 |
liveuser |
1603 |
#設置定義正常
|
|
|
1604 |
$result["status"]="true";
|
| 226 |
liveuser |
1605 |
|
| 3 |
liveuser |
1606 |
#回傳結果
|
|
|
1607 |
return $result;
|
| 226 |
liveuser |
1608 |
|
| 3 |
liveuser |
1609 |
}#function create end
|
| 226 |
liveuser |
1610 |
|
| 3 |
liveuser |
1611 |
/*
|
|
|
1612 |
#函式說明:
|
|
|
1613 |
#提供post的變數查尋定義檔,給予回應.
|
|
|
1614 |
#回傳結果:
|
|
|
1615 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1616 |
#$result["error"],錯誤訊息陣列.
|
|
|
1617 |
#$result["function"],當前執行的函數名稱.
|
|
|
1618 |
#$result["argu"],使用的參數陣列.
|
|
|
1619 |
#$result["founded"],"true"代表有找到定義,"false"代表沒有找到定義.
|
|
|
1620 |
#$result["content"],定義對應的內容.
|
|
|
1621 |
#必填參數:
|
|
|
1622 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1623 |
$conf["fileArgu"]=__FILE__;
|
|
|
1624 |
#$conf["configFileAddr"],字串/陣列,若為字串則為定義檔位置與名稱;若為陣列則為實際的定義檔案內容(每個元素代表一個設定對應的內容).
|
|
|
1625 |
$conf["configFileAddr"]="";
|
|
|
1626 |
#可省略參數:
|
|
|
1627 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為後者.
|
|
|
1628 |
#$conf["web"]="false";
|
|
|
1629 |
#參考資料:
|
|
|
1630 |
#無.
|
|
|
1631 |
#備註:
|
|
|
1632 |
#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
|
|
|
1633 |
*/
|
|
|
1634 |
public static function server(&$conf=array()){
|
| 226 |
liveuser |
1635 |
|
| 3 |
liveuser |
1636 |
#初始化要回傳的結果
|
|
|
1637 |
$result=array();
|
|
|
1638 |
|
|
|
1639 |
#儲存當前執行的函數
|
|
|
1640 |
$result["function"]=__FUNCTION__;
|
|
|
1641 |
|
|
|
1642 |
#如果 $conf 不為陣列
|
|
|
1643 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1644 |
|
| 3 |
liveuser |
1645 |
#設置執行失敗
|
|
|
1646 |
$result["status"]="false";
|
| 226 |
liveuser |
1647 |
|
| 3 |
liveuser |
1648 |
#設置執行錯誤訊息
|
|
|
1649 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1650 |
|
|
|
1651 |
#如果傳入的參數為 null
|
|
|
1652 |
if($conf==null){
|
| 226 |
liveuser |
1653 |
|
| 3 |
liveuser |
1654 |
#設置執行錯誤訊息
|
|
|
1655 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1656 |
|
| 3 |
liveuser |
1657 |
}#if end
|
|
|
1658 |
|
|
|
1659 |
#回傳結果
|
|
|
1660 |
return $result;
|
| 226 |
liveuser |
1661 |
|
| 3 |
liveuser |
1662 |
}#if end
|
| 226 |
liveuser |
1663 |
|
| 3 |
liveuser |
1664 |
#記錄所使用的參數
|
|
|
1665 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
1666 |
|
| 3 |
liveuser |
1667 |
#檢查參數
|
|
|
1668 |
#函式說明:
|
|
|
1669 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1670 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1671 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1672 |
#$result["function"],當前執行的函式名稱.
|
|
|
1673 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1674 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1675 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1676 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1677 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1678 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1679 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1680 |
#必填寫的參數:
|
|
|
1681 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1682 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1683 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1684 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","configFileAddr");
|
| 226 |
liveuser |
1685 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1686 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string",null);
|
|
|
1687 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1688 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1689 |
#可以省略的參數:
|
|
|
1690 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1691 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1692 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1693 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
| 226 |
liveuser |
1694 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1695 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1696 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1697 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
1698 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1699 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1700 |
#參考資料來源:
|
|
|
1701 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1702 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1703 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1704 |
|
| 3 |
liveuser |
1705 |
#如果檢查失敗
|
|
|
1706 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1707 |
|
| 3 |
liveuser |
1708 |
#設置錯誤識別
|
|
|
1709 |
$result["status"]="false";
|
| 226 |
liveuser |
1710 |
|
| 3 |
liveuser |
1711 |
#設置錯誤訊息
|
|
|
1712 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1713 |
|
| 3 |
liveuser |
1714 |
#回傳結果
|
|
|
1715 |
return $result;
|
| 226 |
liveuser |
1716 |
|
| 3 |
liveuser |
1717 |
}#if end
|
| 226 |
liveuser |
1718 |
|
| 3 |
liveuser |
1719 |
#如果檢查不通過
|
|
|
1720 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1721 |
|
| 3 |
liveuser |
1722 |
#設置錯誤識別
|
|
|
1723 |
$result["status"]="false";
|
| 226 |
liveuser |
1724 |
|
| 3 |
liveuser |
1725 |
#設置錯誤訊息
|
|
|
1726 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1727 |
|
| 3 |
liveuser |
1728 |
#回傳結果
|
|
|
1729 |
return $result;
|
| 226 |
liveuser |
1730 |
|
| 3 |
liveuser |
1731 |
}#if end
|
| 226 |
liveuser |
1732 |
|
| 3 |
liveuser |
1733 |
#debug
|
|
|
1734 |
#var_dump($checkArguments);exit;
|
| 226 |
liveuser |
1735 |
|
| 3 |
liveuser |
1736 |
#儲存key的結構
|
|
|
1737 |
$keys=array();
|
| 226 |
liveuser |
1738 |
|
| 3 |
liveuser |
1739 |
#如果沒有 post 變數存在
|
|
|
1740 |
if(count($_POST)<1){
|
| 226 |
liveuser |
1741 |
|
| 3 |
liveuser |
1742 |
#設置錯誤識別
|
|
|
1743 |
$result["status"]="false";
|
| 226 |
liveuser |
1744 |
|
| 3 |
liveuser |
1745 |
#設置錯誤訊息
|
|
|
1746 |
$result["error"][]="沒有post變數";
|
| 226 |
liveuser |
1747 |
|
| 3 |
liveuser |
1748 |
#回傳結果
|
|
|
1749 |
return $result;
|
| 226 |
liveuser |
1750 |
|
| 3 |
liveuser |
1751 |
}#if end
|
| 226 |
liveuser |
1752 |
|
| 3 |
liveuser |
1753 |
#debug
|
|
|
1754 |
#var_dump($_POST);exit;
|
| 226 |
liveuser |
1755 |
|
| 3 |
liveuser |
1756 |
#取得第一層key
|
|
|
1757 |
$layer=array_keys($_POST)[0];
|
| 226 |
liveuser |
1758 |
|
| 3 |
liveuser |
1759 |
#取得數值內容
|
|
|
1760 |
$values=$_POST[$layer];
|
| 226 |
liveuser |
1761 |
|
| 3 |
liveuser |
1762 |
#如果該層級內容形態是陣列
|
|
|
1763 |
while(gettype($values)==="array"){
|
| 226 |
liveuser |
1764 |
|
| 3 |
liveuser |
1765 |
#抓取查尋的key結構
|
|
|
1766 |
$keys[]=$layer;
|
| 226 |
liveuser |
1767 |
|
| 3 |
liveuser |
1768 |
#取得新層級的key
|
|
|
1769 |
$layer=array_keys($values)[0];
|
| 226 |
liveuser |
1770 |
|
| 3 |
liveuser |
1771 |
#取得新的內容
|
|
|
1772 |
$values=$values[$layer];
|
| 226 |
liveuser |
1773 |
|
| 3 |
liveuser |
1774 |
}#while end
|
| 226 |
liveuser |
1775 |
|
| 3 |
liveuser |
1776 |
#取得最後一層的key
|
|
|
1777 |
$keys[]=$layer;
|
| 226 |
liveuser |
1778 |
|
| 3 |
liveuser |
1779 |
#debug
|
|
|
1780 |
#var_dump($keys);exit;
|
| 226 |
liveuser |
1781 |
|
| 3 |
liveuser |
1782 |
#設置預設的定義內容
|
|
|
1783 |
$result["content"]="undefined";
|
| 226 |
liveuser |
1784 |
|
| 3 |
liveuser |
1785 |
#如果configFileAddr是字串
|
|
|
1786 |
if(gettype($conf["configFileAddr"])==="string"){
|
| 226 |
liveuser |
1787 |
|
| 3 |
liveuser |
1788 |
#代表為檔案位置
|
| 226 |
liveuser |
1789 |
|
| 3 |
liveuser |
1790 |
#函式說明:
|
|
|
1791 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
1792 |
#回傳的變數說明:
|
|
|
1793 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
1794 |
#$result["error"],錯誤訊息提示.
|
|
|
1795 |
#$result["warning"],警告訊息.
|
|
|
1796 |
#$result["function"],當前執行的函數名稱.
|
|
|
1797 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
1798 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
1799 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
1800 |
#$result["base64data"],為檔案的base64內容.
|
|
|
1801 |
#$result["mimeType"],為檔案的mime type.
|
|
|
1802 |
#必填的參數:
|
|
|
1803 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
1804 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["configFileAddr"];
|
|
|
1805 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1806 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1807 |
#可省略參數:
|
|
|
1808 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
1809 |
$conf["fileAccess::getFileContent"]["web"]=$conf["web"];
|
|
|
1810 |
#參考資料:
|
|
|
1811 |
#file(),取得檔案內容的行數.
|
|
|
1812 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
1813 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
1814 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
1815 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
1816 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
1817 |
|
| 3 |
liveuser |
1818 |
#如果讀取檔案失敗
|
|
|
1819 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
1820 |
|
| 3 |
liveuser |
1821 |
#設置錯誤識別
|
|
|
1822 |
$result["status"]="false";
|
| 226 |
liveuser |
1823 |
|
| 3 |
liveuser |
1824 |
#設置錯誤訊息
|
|
|
1825 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
1826 |
|
| 3 |
liveuser |
1827 |
#回傳結果
|
|
|
1828 |
return $result;
|
| 226 |
liveuser |
1829 |
|
| 3 |
liveuser |
1830 |
}#if end
|
| 226 |
liveuser |
1831 |
|
| 3 |
liveuser |
1832 |
#debug
|
|
|
1833 |
#var_dump($getFileContent);
|
|
|
1834 |
#var_dump(base64_decode($getFileContent));
|
|
|
1835 |
#var_dump(urldecode(base64_decode($getFileContent)));
|
|
|
1836 |
#var_dump(json_decode(urldecode(base64_decode($getFileContent))));
|
|
|
1837 |
#exit;
|
| 226 |
liveuser |
1838 |
|
| 3 |
liveuser |
1839 |
#針對每行
|
|
|
1840 |
foreach($getFileContent["fileContent"] as $line){
|
| 226 |
liveuser |
1841 |
|
| 3 |
liveuser |
1842 |
#解析內容
|
|
|
1843 |
$def=(array)json_decode(urldecode(base64_decode($line)));
|
| 226 |
liveuser |
1844 |
|
| 3 |
liveuser |
1845 |
#debug
|
|
|
1846 |
#var_dump($def);exit;
|
|
|
1847 |
#var_dump($keys[$i]);exit;
|
| 226 |
liveuser |
1848 |
|
| 3 |
liveuser |
1849 |
#初始化要找到的層級
|
|
|
1850 |
$i=0;
|
| 226 |
liveuser |
1851 |
|
| 3 |
liveuser |
1852 |
#如果有所屬的層級
|
|
|
1853 |
while(isset($def[$keys[$i]])){
|
| 226 |
liveuser |
1854 |
|
| 3 |
liveuser |
1855 |
#取得層級所屬的內容
|
|
|
1856 |
$def=(array)$def[$keys[$i]];
|
| 226 |
liveuser |
1857 |
|
| 3 |
liveuser |
1858 |
#debug
|
|
|
1859 |
#var_dump($def);exit;
|
| 226 |
liveuser |
1860 |
|
| 3 |
liveuser |
1861 |
#如果還不是最後一個key層級
|
|
|
1862 |
if(isset($keys[$i+1])){
|
| 226 |
liveuser |
1863 |
|
| 3 |
liveuser |
1864 |
#層級加一
|
|
|
1865 |
$i++;
|
| 226 |
liveuser |
1866 |
|
| 3 |
liveuser |
1867 |
}#if end
|
| 226 |
liveuser |
1868 |
|
| 3 |
liveuser |
1869 |
#反之是最後一個key的層級了
|
|
|
1870 |
else{
|
| 226 |
liveuser |
1871 |
|
| 3 |
liveuser |
1872 |
#設置定義的內容
|
|
|
1873 |
$result["content"]=$def;
|
| 226 |
liveuser |
1874 |
|
| 3 |
liveuser |
1875 |
#設置有找到定義
|
|
|
1876 |
$result["founded"]="true";
|
| 226 |
liveuser |
1877 |
|
| 3 |
liveuser |
1878 |
#設置定義正常
|
|
|
1879 |
$result["status"]="true";
|
| 226 |
liveuser |
1880 |
|
| 3 |
liveuser |
1881 |
#回傳結果
|
|
|
1882 |
return $result;
|
| 226 |
liveuser |
1883 |
|
| 3 |
liveuser |
1884 |
}#else end
|
| 226 |
liveuser |
1885 |
|
| 3 |
liveuser |
1886 |
}#while end
|
| 226 |
liveuser |
1887 |
|
| 3 |
liveuser |
1888 |
#到這邊代表沒有符合的元素
|
| 226 |
liveuser |
1889 |
|
| 3 |
liveuser |
1890 |
}#foreach end
|
| 226 |
liveuser |
1891 |
|
| 3 |
liveuser |
1892 |
}#if end
|
| 226 |
liveuser |
1893 |
|
| 3 |
liveuser |
1894 |
#反之如果為array
|
|
|
1895 |
else if(gettype($conf["configFileAddr"])==="array"){
|
| 226 |
liveuser |
1896 |
|
| 3 |
liveuser |
1897 |
#針對每行
|
|
|
1898 |
foreach($conf["configFileAddr"] as $configName=>$def){
|
| 226 |
liveuser |
1899 |
|
| 3 |
liveuser |
1900 |
#debug
|
|
|
1901 |
#var_dump($def);exit;
|
|
|
1902 |
#var_dump($keys[$i]);exit;
|
| 226 |
liveuser |
1903 |
|
| 3 |
liveuser |
1904 |
#初始化要找到的層級
|
|
|
1905 |
$i=0;
|
| 226 |
liveuser |
1906 |
|
| 3 |
liveuser |
1907 |
#如果有所屬的層級
|
|
|
1908 |
while(isset($def[$keys[$i]])){
|
| 226 |
liveuser |
1909 |
|
| 3 |
liveuser |
1910 |
#取得層級所屬的內容
|
|
|
1911 |
$def=(array)$def[$keys[$i]];
|
| 226 |
liveuser |
1912 |
|
| 3 |
liveuser |
1913 |
#debug
|
|
|
1914 |
#var_dump($def);exit;
|
| 226 |
liveuser |
1915 |
|
| 3 |
liveuser |
1916 |
#如果還不是最後一個key層級
|
|
|
1917 |
if(isset($keys[$i+1])){
|
| 226 |
liveuser |
1918 |
|
| 3 |
liveuser |
1919 |
#層級加一
|
|
|
1920 |
$i++;
|
| 226 |
liveuser |
1921 |
|
| 3 |
liveuser |
1922 |
}#if end
|
| 226 |
liveuser |
1923 |
|
| 3 |
liveuser |
1924 |
#反之是最後一個key的層級了
|
|
|
1925 |
else{
|
| 226 |
liveuser |
1926 |
|
| 3 |
liveuser |
1927 |
#設置定義的內容
|
|
|
1928 |
$result["content"]=$def;
|
| 226 |
liveuser |
1929 |
|
| 3 |
liveuser |
1930 |
#設置有找到定義
|
|
|
1931 |
$result["founded"]="true";
|
| 226 |
liveuser |
1932 |
|
| 3 |
liveuser |
1933 |
#設置定義正常
|
|
|
1934 |
$result["status"]="true";
|
| 226 |
liveuser |
1935 |
|
| 3 |
liveuser |
1936 |
#回傳結果
|
|
|
1937 |
return $result;
|
| 226 |
liveuser |
1938 |
|
| 3 |
liveuser |
1939 |
}#else end
|
| 226 |
liveuser |
1940 |
|
| 3 |
liveuser |
1941 |
}#while end
|
| 226 |
liveuser |
1942 |
|
| 3 |
liveuser |
1943 |
#到這邊代表沒有符合的元素
|
| 226 |
liveuser |
1944 |
|
| 3 |
liveuser |
1945 |
}#foreach end
|
| 226 |
liveuser |
1946 |
|
| 3 |
liveuser |
1947 |
}#if end
|
| 226 |
liveuser |
1948 |
|
| 3 |
liveuser |
1949 |
#反之如果為其他形態
|
|
|
1950 |
else{
|
| 226 |
liveuser |
1951 |
|
| 3 |
liveuser |
1952 |
#設置錯誤識別
|
|
|
1953 |
$result["status"]="false";
|
| 226 |
liveuser |
1954 |
|
| 3 |
liveuser |
1955 |
#設置錯誤訊息
|
|
|
1956 |
$result["error"][]="configFileAddr的形態只能為string或array";
|
| 226 |
liveuser |
1957 |
|
| 3 |
liveuser |
1958 |
#回傳結果
|
|
|
1959 |
return $result;
|
| 226 |
liveuser |
1960 |
|
| 3 |
liveuser |
1961 |
}#else end
|
| 226 |
liveuser |
1962 |
|
| 3 |
liveuser |
1963 |
#設置定義正常
|
|
|
1964 |
$result["status"]="true";
|
| 226 |
liveuser |
1965 |
|
| 3 |
liveuser |
1966 |
#設置沒有找到定義
|
|
|
1967 |
$result["founded"]="false";
|
| 226 |
liveuser |
1968 |
|
| 3 |
liveuser |
1969 |
#回傳結果
|
|
|
1970 |
return $result;
|
| 226 |
liveuser |
1971 |
|
| 3 |
liveuser |
1972 |
}#function server end
|
| 226 |
liveuser |
1973 |
|
| 3 |
liveuser |
1974 |
/*
|
|
|
1975 |
#函式說明:
|
|
|
1976 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
1977 |
#回傳結果:
|
|
|
1978 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1979 |
#$result["argu"],使用的參數.
|
|
|
1980 |
#$result["error"],錯誤訊息陣列.
|
|
|
1981 |
#$result["function"],當前執行的函數名稱.
|
|
|
1982 |
#$result["rawContent"],得到的原始訊息.
|
|
|
1983 |
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
1984 |
#必填參數:
|
|
|
1985 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
1986 |
$conf["server"]="";
|
|
|
1987 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
1988 |
$conf["postName"]="";
|
|
|
1989 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1990 |
$conf["fileArgu"]=__FILE__;
|
|
|
1991 |
#可省略參數:
|
|
|
1992 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
1993 |
#$conf["cache"]="false";
|
|
|
1994 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
1995 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
1996 |
#$conf["inBg"],字串,預設為"false",代表在前景執行;反之為"true"代表在背景中執行,會強制將"cache"參數設為"false".
|
|
|
1997 |
#$conf["inBg"]="true";
|
|
|
1998 |
#參考資料:
|
|
|
1999 |
#無.
|
|
|
2000 |
#備註:
|
|
|
2001 |
#目前僅能跟server函式提供的服務對接.
|
|
|
2002 |
*/
|
|
|
2003 |
public static function client(&$conf=array()){
|
| 226 |
liveuser |
2004 |
|
| 3 |
liveuser |
2005 |
#初始化要回傳的結果
|
|
|
2006 |
$result=array();
|
|
|
2007 |
|
|
|
2008 |
#儲存當前執行的函數
|
|
|
2009 |
$result["function"]=__FUNCTION__;
|
|
|
2010 |
|
|
|
2011 |
#取得參數
|
|
|
2012 |
$result["argu"]=$conf;
|
|
|
2013 |
|
|
|
2014 |
#如果 $conf 不為陣列
|
|
|
2015 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2016 |
|
| 3 |
liveuser |
2017 |
#設置執行失敗
|
|
|
2018 |
$result["status"]="false";
|
| 226 |
liveuser |
2019 |
|
| 3 |
liveuser |
2020 |
#設置執行錯誤訊息
|
|
|
2021 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2022 |
|
|
|
2023 |
#如果傳入的參數為 null
|
|
|
2024 |
if($conf==null){
|
| 226 |
liveuser |
2025 |
|
| 3 |
liveuser |
2026 |
#設置執行錯誤訊息
|
|
|
2027 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2028 |
|
| 3 |
liveuser |
2029 |
}#if end
|
|
|
2030 |
|
|
|
2031 |
#回傳結果
|
|
|
2032 |
return $result;
|
| 226 |
liveuser |
2033 |
|
| 3 |
liveuser |
2034 |
}#if end
|
| 226 |
liveuser |
2035 |
|
| 3 |
liveuser |
2036 |
#檢查參數
|
|
|
2037 |
#函式說明:
|
|
|
2038 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2039 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2040 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2041 |
#$result["function"],當前執行的函式名稱.
|
|
|
2042 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2043 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2044 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2045 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2046 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2047 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2048 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2049 |
#必填寫的參數:
|
|
|
2050 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2051 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2052 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2053 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("server","postName","fileArgu");
|
| 226 |
liveuser |
2054 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2055 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2056 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2057 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2058 |
#可以省略的參數:
|
|
|
2059 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2060 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2061 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2062 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("cache","clientCacheDaemonSock","inBg");
|
| 226 |
liveuser |
2063 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2064 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
2065 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2066 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true",null,"false");
|
|
|
2067 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2068 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2069 |
#參考資料來源:
|
|
|
2070 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2071 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2072 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2073 |
|
| 3 |
liveuser |
2074 |
#如果檢查失敗
|
|
|
2075 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
2076 |
|
| 3 |
liveuser |
2077 |
#設置錯誤識別
|
|
|
2078 |
$result["status"]="false";
|
| 226 |
liveuser |
2079 |
|
| 3 |
liveuser |
2080 |
#設置錯誤訊息
|
|
|
2081 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2082 |
|
| 3 |
liveuser |
2083 |
#回傳結果
|
|
|
2084 |
return $result;
|
| 226 |
liveuser |
2085 |
|
| 3 |
liveuser |
2086 |
}#if end
|
| 226 |
liveuser |
2087 |
|
| 3 |
liveuser |
2088 |
#如果檢查不通過
|
|
|
2089 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
2090 |
|
| 3 |
liveuser |
2091 |
#設置錯誤識別
|
|
|
2092 |
$result["status"]="false";
|
| 226 |
liveuser |
2093 |
|
| 3 |
liveuser |
2094 |
#設置錯誤訊息
|
|
|
2095 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2096 |
|
| 3 |
liveuser |
2097 |
#回傳結果
|
|
|
2098 |
return $result;
|
| 226 |
liveuser |
2099 |
|
| 3 |
liveuser |
2100 |
}#if end
|
| 226 |
liveuser |
2101 |
|
| 3 |
liveuser |
2102 |
#如果要在背景執行
|
|
|
2103 |
if($conf["inBg"]==="true"){
|
| 226 |
liveuser |
2104 |
|
| 3 |
liveuser |
2105 |
#函式說明:
|
|
|
2106 |
#運行curl cmd
|
|
|
2107 |
#回傳結果:
|
|
|
2108 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2109 |
#$result["error"],錯誤訊息陣列.
|
|
|
2110 |
#$result["function"],當前執行的函式名稱.
|
|
|
2111 |
#$result["founded"],識別網址找不找得到.
|
|
|
2112 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
2113 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
2114 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
2115 |
#$result["cmd"],執行的command.
|
|
|
2116 |
#$result["argu],使用的參數.
|
|
|
2117 |
#必填參數:
|
|
|
2118 |
#$conf["url"],字串,目標url.
|
|
|
2119 |
$conf["cmd::curlCmd"]["url"]=$conf["server"];
|
|
|
2120 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2121 |
$conf["cmd::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2122 |
#可省略參數:
|
|
|
2123 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
2124 |
#$conf["header"]=array();
|
|
|
2125 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
2126 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
2127 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
2128 |
$conf["cmd::curlCmd"]["postVar"]=array($conf["postName"]=>"");
|
|
|
2129 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
2130 |
#$conf["rawPost"]="";
|
|
|
2131 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
2132 |
#$conf["urlEncode"]="false";
|
|
|
2133 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
2134 |
#$conf["agent"]="";
|
|
|
2135 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
2136 |
#$conf["cookie"]="";
|
|
|
2137 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2138 |
#$conf["forceNewCookie"]="";
|
|
|
2139 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
2140 |
#$conf["inBg"]="true";
|
|
|
2141 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
2142 |
$conf["catchWebContent::curlCmd"]["bgInProc"]="true";
|
|
|
2143 |
#參考資料:
|
|
|
2144 |
#無.
|
|
|
2145 |
#備註:
|
|
|
2146 |
#無.
|
|
|
2147 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
2148 |
unset($conf["catchWebContent::curlCmd"]);
|
| 226 |
liveuser |
2149 |
|
| 3 |
liveuser |
2150 |
#如果執行失敗
|
|
|
2151 |
if($curlCmd["status"]==="false"){
|
| 226 |
liveuser |
2152 |
|
| 3 |
liveuser |
2153 |
#設置錯誤識別
|
|
|
2154 |
$result["status"]="false";
|
| 226 |
liveuser |
2155 |
|
| 3 |
liveuser |
2156 |
#設置錯誤訊息
|
|
|
2157 |
$result["error"]=$curlCmd;
|
| 226 |
liveuser |
2158 |
|
| 3 |
liveuser |
2159 |
#回傳結果
|
|
|
2160 |
return $result;
|
| 226 |
liveuser |
2161 |
|
| 3 |
liveuser |
2162 |
}#if end
|
| 226 |
liveuser |
2163 |
|
| 3 |
liveuser |
2164 |
#設置proc資訊
|
|
|
2165 |
$result["content"]=$curlCmd["content"];
|
| 226 |
liveuser |
2166 |
|
| 3 |
liveuser |
2167 |
#設置執行正常
|
|
|
2168 |
$result["status"]="true";
|
| 226 |
liveuser |
2169 |
|
| 3 |
liveuser |
2170 |
#回傳結果
|
|
|
2171 |
return $result;
|
| 226 |
liveuser |
2172 |
|
| 3 |
liveuser |
2173 |
}#if end
|
| 226 |
liveuser |
2174 |
|
| 3 |
liveuser |
2175 |
#如果沒有設置 cacheFile
|
|
|
2176 |
if(!isset($conf["cacheFile"])){
|
| 226 |
liveuser |
2177 |
|
| 3 |
liveuser |
2178 |
#取得以該檔案為准的實際位置 lib path
|
|
|
2179 |
exec("cd ".pathinfo(__FILE__)["dirname"].";pwd;",$output,$status);
|
| 226 |
liveuser |
2180 |
|
| 3 |
liveuser |
2181 |
#初始化之
|
|
|
2182 |
$conf["clientCacheDaemonSock"]=$output[0]."/var/config::client/clientCacheDaemon.sock";
|
| 226 |
liveuser |
2183 |
|
| 3 |
liveuser |
2184 |
}#if end
|
| 226 |
liveuser |
2185 |
|
| 3 |
liveuser |
2186 |
#如果有要使用cache
|
|
|
2187 |
if($conf["cache"]==="true"){
|
| 226 |
liveuser |
2188 |
|
| 3 |
liveuser |
2189 |
#查詢 cahce 內容
|
|
|
2190 |
#連線到 sock::unixDomainSocketServer 產生的 unix domain socket,傳送指定的訊息.
|
|
|
2191 |
#回傳結果:
|
|
|
2192 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
2193 |
#$result["error"],錯誤訊息陣列.
|
|
|
2194 |
#$result["function"],當前執行的函式名稱.
|
|
|
2195 |
#$result["argu"],使用的參數.
|
|
|
2196 |
#$result["content"],得到的回應.
|
|
|
2197 |
#必填參數:
|
|
|
2198 |
#$conf["msg"],陣列,要傳送的訊息,其主$conf["msg"]["id"],是無法指定的.
|
|
|
2199 |
$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["msg"]=array("postName"=>$conf["postName"],"server"=>$conf["server"]);
|
|
|
2200 |
#可省略參數:
|
|
|
2201 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
2202 |
$conf["sock::sendAnyMsgToQBPWCFunixSocket"]["sock"]=$conf["clientCacheDaemonSock"];
|
|
|
2203 |
#參考資料:
|
|
|
2204 |
#無.
|
|
|
2205 |
#備註:
|
|
|
2206 |
#無.
|
|
|
2207 |
$sendAnyMsgToQBPWCFunixSocket=sock::sendAnyMsgToQBPWCFunixSocket($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
|
|
|
2208 |
unset($conf["sock::sendAnyMsgToQBPWCFunixSocket"]);
|
| 226 |
liveuser |
2209 |
|
| 3 |
liveuser |
2210 |
#如果執行失敗
|
|
|
2211 |
if($sendAnyMsgToQBPWCFunixSocket["status"]=="false"){
|
| 226 |
liveuser |
2212 |
|
| 3 |
liveuser |
2213 |
#設置錯誤識別
|
|
|
2214 |
$result["status"]="false";
|
| 226 |
liveuser |
2215 |
|
| 3 |
liveuser |
2216 |
#設置錯誤訊息
|
|
|
2217 |
$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
|
| 226 |
liveuser |
2218 |
|
| 3 |
liveuser |
2219 |
#回傳結果
|
|
|
2220 |
return $result;
|
| 226 |
liveuser |
2221 |
|
| 3 |
liveuser |
2222 |
}#if end
|
| 226 |
liveuser |
2223 |
|
| 3 |
liveuser |
2224 |
#如果執行失敗
|
|
|
2225 |
if($sendAnyMsgToQBPWCFunixSocket["status"]==="false"){
|
| 226 |
liveuser |
2226 |
|
| 3 |
liveuser |
2227 |
#設置錯誤識別
|
|
|
2228 |
$result["status"]="false";
|
| 226 |
liveuser |
2229 |
|
| 3 |
liveuser |
2230 |
#設置錯誤訊息
|
|
|
2231 |
$result["error"]=$sendAnyMsgToQBPWCFunixSocket;
|
| 226 |
liveuser |
2232 |
|
| 3 |
liveuser |
2233 |
#回傳結果
|
|
|
2234 |
return $result;
|
| 226 |
liveuser |
2235 |
|
| 3 |
liveuser |
2236 |
}#if end
|
| 226 |
liveuser |
2237 |
|
| 3 |
liveuser |
2238 |
#debug
|
|
|
2239 |
#var_dump(__LINE__,$sendAnyMsgToQBPWCFunixSocket);
|
| 226 |
liveuser |
2240 |
|
| 3 |
liveuser |
2241 |
#設置回應的內容
|
|
|
2242 |
$result["rawContent"]=$sendAnyMsgToQBPWCFunixSocket["content"];
|
| 226 |
liveuser |
2243 |
|
| 3 |
liveuser |
2244 |
#設置解析好的json回應內容
|
|
|
2245 |
$result["content"]=json_decode($sendAnyMsgToQBPWCFunixSocket["content"]);
|
| 226 |
liveuser |
2246 |
|
| 3 |
liveuser |
2247 |
#設置執行正常
|
|
|
2248 |
$result["status"]="true";
|
| 226 |
liveuser |
2249 |
|
| 3 |
liveuser |
2250 |
#回傳結果
|
|
|
2251 |
return $result;
|
| 226 |
liveuser |
2252 |
|
| 3 |
liveuser |
2253 |
}#if end
|
| 226 |
liveuser |
2254 |
|
| 3 |
liveuser |
2255 |
#函式說明:
|
|
|
2256 |
#運行curl cmd
|
|
|
2257 |
#回傳結果:
|
|
|
2258 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2259 |
#$result["error"],錯誤訊息陣列.
|
|
|
2260 |
#$result["function"],當前執行的函式名稱.
|
|
|
2261 |
#$result["content"],取得的回應內容陣列.
|
|
|
2262 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
2263 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
2264 |
#$result["cmd"],執行的command.
|
|
|
2265 |
#$result["argu],使用的參數.
|
|
|
2266 |
#必填參數:
|
|
|
2267 |
#$conf["url"],字串,目標url.
|
|
|
2268 |
$conf["cmd::curlCmd"]["url"]=$conf["server"];
|
|
|
2269 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2270 |
$conf["cmd::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2271 |
#可省略參數:
|
|
|
2272 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
2273 |
#$conf["header"]=array();
|
|
|
2274 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
2275 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
2276 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
2277 |
$conf["cmd::curlCmd"]["postVar"]=array($conf["postName"]=>"");
|
|
|
2278 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
2279 |
#$conf["rawPost"]="";
|
|
|
2280 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
2281 |
#$conf["urlEncode"]="false";
|
|
|
2282 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
2283 |
#$conf["agent"]="";
|
|
|
2284 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
2285 |
#$conf["cookie"]="";
|
|
|
2286 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2287 |
#$conf["forceNewCookie"]="";
|
|
|
2288 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
2289 |
#$conf["inBg"]="true";
|
|
|
2290 |
#備註:
|
|
|
2291 |
#無.
|
|
|
2292 |
$curlCmd=catchWebContent::curlCmd($conf["cmd::curlCmd"]);
|
|
|
2293 |
unset($conf["cmd::curlCmd"]);
|
| 226 |
liveuser |
2294 |
|
| 3 |
liveuser |
2295 |
#如果執行失敗
|
|
|
2296 |
if($curlCmd["status"]==="false"){
|
| 226 |
liveuser |
2297 |
|
| 3 |
liveuser |
2298 |
#設置錯誤識別
|
|
|
2299 |
$result["status"]="false";
|
| 226 |
liveuser |
2300 |
|
| 3 |
liveuser |
2301 |
#設置錯誤訊息
|
|
|
2302 |
$result["error"]=$curlCmd;
|
| 226 |
liveuser |
2303 |
|
| 3 |
liveuser |
2304 |
#回傳結果
|
|
|
2305 |
return $result;
|
| 226 |
liveuser |
2306 |
|
| 3 |
liveuser |
2307 |
}#if end
|
| 226 |
liveuser |
2308 |
|
| 3 |
liveuser |
2309 |
#設置執行正常
|
|
|
2310 |
$result["status"]="true";
|
| 226 |
liveuser |
2311 |
|
| 3 |
liveuser |
2312 |
#設置回應的內容
|
|
|
2313 |
$result["rawContent"]=$curlCmd["fullContent"];
|
| 226 |
liveuser |
2314 |
|
| 3 |
liveuser |
2315 |
#設置解析好的json回應內容
|
|
|
2316 |
$result["content"]=json_decode($curlCmd["fullContent"]);
|
| 226 |
liveuser |
2317 |
|
| 3 |
liveuser |
2318 |
#回傳結果
|
|
|
2319 |
return $result;
|
| 226 |
liveuser |
2320 |
|
| 3 |
liveuser |
2321 |
}#function client end
|
| 226 |
liveuser |
2322 |
|
| 3 |
liveuser |
2323 |
/*
|
|
|
2324 |
#函式說明:
|
|
|
2325 |
#給clientCacheDaemon用的addOnProcessFunc,處理來自config::client有使用cache的要求.
|
|
|
2326 |
#回傳結果:
|
|
|
2327 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2328 |
#$result["error"],錯誤訊息陣列.
|
|
|
2329 |
#$result["function"],當前執行的函數名稱.
|
|
|
2330 |
#$result["warning"],警告訊息陣列.
|
|
|
2331 |
#必填參數:
|
|
|
2332 |
#$conf["request"],陣列,收到的訊息.
|
|
|
2333 |
#$conf["request"]=array();
|
|
|
2334 |
#$conf["request"]["postName"],字串,要查詢的索引.
|
|
|
2335 |
#$conf["request"]["postName"]="";
|
|
|
2336 |
#$conf["request"]["server"],字串,要去哪個config server查詢.
|
|
|
2337 |
#$conf["request"]["server"]="";
|
|
|
2338 |
#$conf["request"]["id"],字串,用來識別用戶的uuid.
|
|
|
2339 |
#$conf["request"]["id"]="";
|
|
|
2340 |
#$conf["socket"],client的socket
|
|
|
2341 |
#$conf["socket"]=;
|
|
|
2342 |
#$conf["info"],陣列,sock跟cache file path資訊.
|
|
|
2343 |
#$conf["info"]=array();
|
|
|
2344 |
#$conf["info"]["sock"],字串,unix domain socket addr.
|
|
|
2345 |
#$conf["info"]["sock"]=;
|
|
|
2346 |
#$conf["info"]["cacheFilePath"],字串,cache file path.
|
|
|
2347 |
#$conf["info"]["cacheFilePath"]=;
|
|
|
2348 |
#$conf["info"]["checkVersionInterval"],字串,距離最後一次取得資料的時間多久就要檢查是否有新資料,預設為60秒.
|
|
|
2349 |
#$conf["info"]["checkVersionInterval"]="60";
|
|
|
2350 |
#$conf["clientCache"],陣列.存放跟取得快取的陣列.
|
|
|
2351 |
#$conf["clientCache"]=array();
|
|
|
2352 |
#$conf["last_req_time"],字串,存放上次執行的unixtime.
|
|
|
2353 |
#$conf["last_req_time"]="";
|
|
|
2354 |
#可省略參數:
|
|
|
2355 |
#無.
|
|
|
2356 |
#參考資料:
|
|
|
2357 |
#無.
|
|
|
2358 |
#備註:
|
|
|
2359 |
#無,
|
|
|
2360 |
*/
|
|
|
2361 |
public static function addOnProcessFuncForClientCacheDaemon(&$conf){
|
| 226 |
liveuser |
2362 |
|
| 3 |
liveuser |
2363 |
#debug
|
|
|
2364 |
#var_dump(__LINE__,"into function ".__FUNCTION__);
|
| 226 |
liveuser |
2365 |
|
| 3 |
liveuser |
2366 |
#初始化結果
|
|
|
2367 |
$result=array();
|
|
|
2368 |
|
|
|
2369 |
#取得當前執行的函數名稱
|
|
|
2370 |
$result["function"]=__FUNCTION__;
|
|
|
2371 |
|
|
|
2372 |
#取得參數
|
|
|
2373 |
$result["argu"]=$conf;
|
|
|
2374 |
|
|
|
2375 |
#如果 $conf 不為陣列
|
|
|
2376 |
if(gettype($conf)!=="array"){
|
|
|
2377 |
|
|
|
2378 |
#設置執行失敗
|
|
|
2379 |
$result["status"]="false";
|
|
|
2380 |
|
|
|
2381 |
#設置執行錯誤訊息
|
|
|
2382 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2383 |
|
|
|
2384 |
#如果傳入的參數為 null
|
|
|
2385 |
if(is_null($conf)){
|
|
|
2386 |
|
|
|
2387 |
#設置執行錯誤訊息
|
|
|
2388 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2389 |
|
|
|
2390 |
}#if end
|
|
|
2391 |
|
|
|
2392 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2393 |
|
| 3 |
liveuser |
2394 |
#寫入回應的內容
|
|
|
2395 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2396 |
|
| 3 |
liveuser |
2397 |
#結束回應
|
|
|
2398 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2399 |
|
| 3 |
liveuser |
2400 |
#關閉socket連線,將回應輸出.
|
|
|
2401 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2402 |
|
| 3 |
liveuser |
2403 |
#回傳給用戶 - end
|
|
|
2404 |
|
|
|
2405 |
#回傳結果
|
|
|
2406 |
return $result;
|
|
|
2407 |
|
|
|
2408 |
}#if end
|
| 226 |
liveuser |
2409 |
|
| 3 |
liveuser |
2410 |
#debug
|
|
|
2411 |
#var_dump(__LINE__,"檢查 參數");
|
| 226 |
liveuser |
2412 |
|
| 3 |
liveuser |
2413 |
#函式說明:
|
|
|
2414 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2415 |
#回傳結果:
|
|
|
2416 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2417 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2418 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2419 |
#$result["function"],當前執行的函式名稱.
|
|
|
2420 |
#$result["argu"],設置給予的參數.
|
|
|
2421 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2422 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2423 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2424 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2425 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2426 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2427 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2428 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2429 |
#必填參數:
|
|
|
2430 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2431 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2432 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2433 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2434 |
#可省略參數:
|
|
|
2435 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2436 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("socket","request","info","clientCache","last_req_time");
|
|
|
2437 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2438 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("resource","array","array","array","integer");
|
|
|
2439 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2440 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2441 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2442 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("socket","info");
|
|
|
2443 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2444 |
#$conf["canBeEmpty"]=array();
|
|
|
2445 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2446 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
2447 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2448 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","request");
|
|
|
2449 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2450 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("resource","array");
|
|
|
2451 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2452 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
2453 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2454 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2455 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2456 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2457 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2458 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2459 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2460 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2461 |
#參考資料:
|
|
|
2462 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2463 |
#備註:
|
|
|
2464 |
#無.
|
|
|
2465 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2466 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2467 |
|
| 3 |
liveuser |
2468 |
#如果執行失敗
|
|
|
2469 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
2470 |
|
| 3 |
liveuser |
2471 |
#設置錯誤識別
|
|
|
2472 |
$result["status"]="false";
|
| 226 |
liveuser |
2473 |
|
| 3 |
liveuser |
2474 |
#設置錯誤訊息
|
|
|
2475 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2476 |
|
| 3 |
liveuser |
2477 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2478 |
|
| 3 |
liveuser |
2479 |
#寫入回應的內容
|
|
|
2480 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2481 |
|
| 3 |
liveuser |
2482 |
#結束回應
|
|
|
2483 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2484 |
|
| 3 |
liveuser |
2485 |
#關閉socket連線,將回應輸出.
|
|
|
2486 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2487 |
|
| 3 |
liveuser |
2488 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2489 |
|
| 3 |
liveuser |
2490 |
#回傳結果
|
|
|
2491 |
return $result;
|
| 226 |
liveuser |
2492 |
|
| 3 |
liveuser |
2493 |
}#if end
|
| 226 |
liveuser |
2494 |
|
| 3 |
liveuser |
2495 |
#如果檢查不通過
|
|
|
2496 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
2497 |
|
| 3 |
liveuser |
2498 |
#設置錯誤識別
|
|
|
2499 |
$result["status"]="false";
|
| 226 |
liveuser |
2500 |
|
| 3 |
liveuser |
2501 |
#設置錯誤訊息
|
|
|
2502 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2503 |
|
| 3 |
liveuser |
2504 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2505 |
|
| 3 |
liveuser |
2506 |
#寫入回應的內容
|
|
|
2507 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2508 |
|
| 3 |
liveuser |
2509 |
#結束回應
|
|
|
2510 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2511 |
|
| 3 |
liveuser |
2512 |
#關閉socket連線,將回應輸出.
|
|
|
2513 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2514 |
|
| 3 |
liveuser |
2515 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2516 |
|
| 3 |
liveuser |
2517 |
#回傳結果
|
|
|
2518 |
return $result;
|
| 226 |
liveuser |
2519 |
|
| 3 |
liveuser |
2520 |
}#if end
|
| 226 |
liveuser |
2521 |
|
| 3 |
liveuser |
2522 |
#debug
|
|
|
2523 |
#var_dump(__LINE__,"檢查 request 參數");
|
| 226 |
liveuser |
2524 |
|
| 3 |
liveuser |
2525 |
#函式說明:
|
|
|
2526 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2527 |
#回傳結果:
|
|
|
2528 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2529 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2530 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2531 |
#$result["function"],當前執行的函式名稱.
|
|
|
2532 |
#$result["argu"],設置給予的參數.
|
|
|
2533 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2534 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2535 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2536 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2537 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2538 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2539 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2540 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2541 |
#必填參數:
|
|
|
2542 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2543 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["request"];
|
|
|
2544 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2545 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2546 |
#可省略參數:
|
|
|
2547 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2548 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id","postName","server");
|
|
|
2549 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2550 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2551 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2552 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2553 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2554 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("sock");
|
|
|
2555 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2556 |
#$conf["canBeEmpty"]=array();
|
|
|
2557 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2558 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
2559 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2560 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","request");
|
|
|
2561 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2562 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("resource","array");
|
|
|
2563 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2564 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
2565 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2566 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2567 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2568 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2569 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2570 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2571 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2572 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2573 |
#參考資料:
|
|
|
2574 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2575 |
#備註:
|
|
|
2576 |
#無.
|
|
|
2577 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2578 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2579 |
|
| 3 |
liveuser |
2580 |
#如果執行失敗
|
|
|
2581 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
2582 |
|
| 3 |
liveuser |
2583 |
#設置錯誤識別
|
|
|
2584 |
$result["status"]="false";
|
| 226 |
liveuser |
2585 |
|
| 3 |
liveuser |
2586 |
#設置錯誤訊息
|
|
|
2587 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2588 |
|
| 3 |
liveuser |
2589 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2590 |
|
| 3 |
liveuser |
2591 |
#寫入回應的內容
|
|
|
2592 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2593 |
|
| 3 |
liveuser |
2594 |
#結束回應
|
|
|
2595 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2596 |
|
| 3 |
liveuser |
2597 |
#關閉socket連線,將回應輸出.
|
|
|
2598 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2599 |
|
| 3 |
liveuser |
2600 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2601 |
|
| 3 |
liveuser |
2602 |
#回傳結果
|
|
|
2603 |
return $result;
|
| 226 |
liveuser |
2604 |
|
| 3 |
liveuser |
2605 |
}#if end
|
| 226 |
liveuser |
2606 |
|
| 3 |
liveuser |
2607 |
#如果檢查不通過
|
|
|
2608 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
2609 |
|
| 3 |
liveuser |
2610 |
#設置錯誤識別
|
|
|
2611 |
$result["status"]="false";
|
| 226 |
liveuser |
2612 |
|
| 3 |
liveuser |
2613 |
#設置錯誤訊息
|
|
|
2614 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2615 |
|
| 3 |
liveuser |
2616 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2617 |
|
| 3 |
liveuser |
2618 |
#寫入回應的內容
|
|
|
2619 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2620 |
|
| 3 |
liveuser |
2621 |
#結束回應
|
|
|
2622 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2623 |
|
| 3 |
liveuser |
2624 |
#關閉socket連線,將回應輸出.
|
|
|
2625 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2626 |
|
| 3 |
liveuser |
2627 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2628 |
|
| 3 |
liveuser |
2629 |
#回傳結果
|
|
|
2630 |
return $result;
|
| 226 |
liveuser |
2631 |
|
| 3 |
liveuser |
2632 |
}#if end
|
| 226 |
liveuser |
2633 |
|
| 3 |
liveuser |
2634 |
#函式說明:
|
|
|
2635 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
2636 |
#回傳結果:
|
|
|
2637 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2638 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
2639 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
2640 |
#$result["function"],當前執行的函式名稱.
|
|
|
2641 |
#$result["argu"],設置給予的參數.
|
|
|
2642 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2643 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2644 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2645 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2646 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2647 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2648 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2649 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2650 |
#必填參數:
|
|
|
2651 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2652 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["info"];
|
|
|
2653 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2654 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2655 |
#可省略參數:
|
|
|
2656 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2657 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sock","cacheFilePath","checkVersionInterval");
|
|
|
2658 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2659 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2660 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2661 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2662 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2663 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("sock");
|
|
|
2664 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2665 |
#$conf["canBeEmpty"]=array();
|
|
|
2666 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2667 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
2668 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2669 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","request");
|
|
|
2670 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2671 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("resource","array");
|
|
|
2672 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2673 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
2674 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
2675 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
2676 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
2677 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
2678 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
2679 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
2680 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2681 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2682 |
#參考資料:
|
|
|
2683 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2684 |
#備註:
|
|
|
2685 |
#無.
|
|
|
2686 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2687 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2688 |
|
| 3 |
liveuser |
2689 |
#如果執行失敗
|
|
|
2690 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
2691 |
|
| 3 |
liveuser |
2692 |
#設置錯誤識別
|
|
|
2693 |
$result["status"]="false";
|
| 226 |
liveuser |
2694 |
|
| 3 |
liveuser |
2695 |
#設置錯誤訊息
|
|
|
2696 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2697 |
|
| 3 |
liveuser |
2698 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2699 |
|
| 3 |
liveuser |
2700 |
#寫入回應的內容
|
|
|
2701 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2702 |
|
| 3 |
liveuser |
2703 |
#結束回應
|
|
|
2704 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2705 |
|
| 3 |
liveuser |
2706 |
#關閉socket連線,將回應輸出.
|
|
|
2707 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2708 |
|
| 3 |
liveuser |
2709 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2710 |
|
| 3 |
liveuser |
2711 |
#回傳結果
|
|
|
2712 |
return $result;
|
| 226 |
liveuser |
2713 |
|
| 3 |
liveuser |
2714 |
}#if end
|
| 226 |
liveuser |
2715 |
|
| 3 |
liveuser |
2716 |
#如果檢查不通過
|
|
|
2717 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
2718 |
|
| 3 |
liveuser |
2719 |
#設置錯誤識別
|
|
|
2720 |
$result["status"]="false";
|
| 226 |
liveuser |
2721 |
|
| 3 |
liveuser |
2722 |
#設置錯誤訊息
|
|
|
2723 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2724 |
|
| 3 |
liveuser |
2725 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2726 |
|
| 3 |
liveuser |
2727 |
#寫入回應的內容
|
|
|
2728 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2729 |
|
| 3 |
liveuser |
2730 |
#結束回應
|
|
|
2731 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2732 |
|
| 3 |
liveuser |
2733 |
#關閉socket連線,將回應輸出.
|
|
|
2734 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2735 |
|
| 3 |
liveuser |
2736 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2737 |
|
| 3 |
liveuser |
2738 |
#回傳結果
|
|
|
2739 |
return $result;
|
| 226 |
liveuser |
2740 |
|
| 3 |
liveuser |
2741 |
}#if end
|
| 226 |
liveuser |
2742 |
|
| 3 |
liveuser |
2743 |
#判斷 client cahce 有無指定來源的資料
|
| 226 |
liveuser |
2744 |
|
| 3 |
liveuser |
2745 |
#debug
|
|
|
2746 |
#var_dump(__LINE__,"判斷 client cahce 有無指定來源的資料");
|
| 226 |
liveuser |
2747 |
|
| 3 |
liveuser |
2748 |
#來源
|
|
|
2749 |
#$conf["request"]["server"];
|
| 226 |
liveuser |
2750 |
|
| 3 |
liveuser |
2751 |
#debug
|
|
|
2752 |
#var_dump(__LINE__,$conf["request"]["server"]);
|
| 226 |
liveuser |
2753 |
|
| 3 |
liveuser |
2754 |
#索引
|
|
|
2755 |
#$conf["request"]["postName"];
|
| 226 |
liveuser |
2756 |
|
| 3 |
liveuser |
2757 |
#debug
|
|
|
2758 |
#var_dump(__LINE__,$conf["request"]["postName"]);
|
| 226 |
liveuser |
2759 |
|
| 3 |
liveuser |
2760 |
#如果存在
|
|
|
2761 |
if(isset($conf["clientCache"]["share"]["configs"])){
|
| 226 |
liveuser |
2762 |
|
| 3 |
liveuser |
2763 |
#debug
|
|
|
2764 |
#var_dump(__LINE__,$conf["clientCache"]["share"]["configs"]);
|
| 226 |
liveuser |
2765 |
|
| 3 |
liveuser |
2766 |
#如果有對應來源的資料
|
|
|
2767 |
if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]])){
|
| 226 |
liveuser |
2768 |
|
| 3 |
liveuser |
2769 |
#如果有該索引的資料
|
|
|
2770 |
if(isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]])){
|
| 226 |
liveuser |
2771 |
|
| 3 |
liveuser |
2772 |
#如果存在 content 跟 time
|
|
|
2773 |
if( isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]) && isset($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"]) ){
|
| 226 |
liveuser |
2774 |
|
| 3 |
liveuser |
2775 |
#取得 content
|
|
|
2776 |
$result["content"]=json_decode($conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]);
|
| 226 |
liveuser |
2777 |
|
| 3 |
liveuser |
2778 |
#記錄多少秒未更新
|
|
|
2779 |
$secsNoUpdate=time()-$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"];
|
| 226 |
liveuser |
2780 |
|
| 3 |
liveuser |
2781 |
#記錄資料過期多少秒
|
|
|
2782 |
$secsExpired=$secsNoUpdate-$conf["info"]["checkVersionInterval"];
|
| 226 |
liveuser |
2783 |
|
| 3 |
liveuser |
2784 |
#提示資料超過期限未更新
|
|
|
2785 |
if($secsNoUpdate>$conf["info"]["checkVersionInterval"]){
|
| 226 |
liveuser |
2786 |
|
| 3 |
liveuser |
2787 |
#設置警告訊息
|
|
|
2788 |
$result["warning"][]="data expired for ".$secsExpired." secs";
|
| 226 |
liveuser |
2789 |
|
|
|
2790 |
}#if end
|
|
|
2791 |
|
| 3 |
liveuser |
2792 |
#設置執行正常
|
|
|
2793 |
$result["status"]="true";
|
| 226 |
liveuser |
2794 |
|
| 3 |
liveuser |
2795 |
#debug
|
|
|
2796 |
#var_dump(__LINE__,$result,json_encode($result));
|
| 226 |
liveuser |
2797 |
|
| 3 |
liveuser |
2798 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2799 |
|
| 3 |
liveuser |
2800 |
#初始化要回傳的訊息
|
|
|
2801 |
$msg=array();
|
| 226 |
liveuser |
2802 |
|
| 3 |
liveuser |
2803 |
#設置回傳的內容
|
|
|
2804 |
$msg["content"]=$result["content"];
|
| 226 |
liveuser |
2805 |
|
| 3 |
liveuser |
2806 |
#設置回傳的狀態
|
|
|
2807 |
$msg["status"]=$result["status"];
|
| 226 |
liveuser |
2808 |
|
| 3 |
liveuser |
2809 |
#寫入回應的內容
|
|
|
2810 |
fwrite($conf["socket"],json_encode($msg).PHP_EOL);
|
| 226 |
liveuser |
2811 |
|
| 3 |
liveuser |
2812 |
#結束回應
|
|
|
2813 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2814 |
|
| 3 |
liveuser |
2815 |
#關閉socket連線,將回應輸出.
|
|
|
2816 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2817 |
|
| 3 |
liveuser |
2818 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2819 |
|
| 3 |
liveuser |
2820 |
#回傳結果
|
|
|
2821 |
return $result;
|
| 226 |
liveuser |
2822 |
|
| 3 |
liveuser |
2823 |
}#if end
|
| 226 |
liveuser |
2824 |
|
| 3 |
liveuser |
2825 |
}#if end
|
| 226 |
liveuser |
2826 |
|
| 3 |
liveuser |
2827 |
}#if end
|
| 226 |
liveuser |
2828 |
|
| 3 |
liveuser |
2829 |
}#if end
|
| 226 |
liveuser |
2830 |
|
| 3 |
liveuser |
2831 |
#執行到這邊代表沒有資料
|
| 226 |
liveuser |
2832 |
|
| 3 |
liveuser |
2833 |
#函式說明:
|
|
|
2834 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
2835 |
#回傳結果:
|
|
|
2836 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2837 |
#$result["error"],錯誤訊息陣列.
|
|
|
2838 |
#$result["function"],當前執行的函數名稱.
|
|
|
2839 |
#$result["rawContent"],得到的原始訊息.
|
|
|
2840 |
#$result["content"],用json_decode後的結果.
|
|
|
2841 |
#必填參數:
|
|
|
2842 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
2843 |
$conf["config::client"]["server"]=$conf["request"]["server"];
|
|
|
2844 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
2845 |
$conf["config::client"]["postName"]=$conf["request"]["postName"];
|
|
|
2846 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2847 |
$conf["config::client"]["fileArgu"]=__FILE__;
|
|
|
2848 |
#可省略參數:
|
|
|
2849 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
2850 |
$conf["config::client"]["cache"]="false";
|
|
|
2851 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
2852 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
2853 |
#參考資料:
|
|
|
2854 |
#無.
|
|
|
2855 |
#備註:
|
|
|
2856 |
#目前僅能跟server函式提供的服務對接.
|
|
|
2857 |
$client=config::client($conf["config::client"]);
|
|
|
2858 |
unset($conf["config::client"]);
|
| 226 |
liveuser |
2859 |
|
| 3 |
liveuser |
2860 |
#debug
|
|
|
2861 |
#var_dump(__LINE__,$client);
|
| 226 |
liveuser |
2862 |
|
| 3 |
liveuser |
2863 |
/*
|
| 226 |
liveuser |
2864 |
|
| 3 |
liveuser |
2865 |
#debug
|
|
|
2866 |
#函式說明:
|
|
|
2867 |
#撰寫log
|
|
|
2868 |
#回傳結果:
|
|
|
2869 |
#$result["status"],狀態,"true"或"false".
|
|
|
2870 |
#$result["error"],錯誤訊息陣列.
|
|
|
2871 |
#$result["function"],當前函式的名稱.
|
|
|
2872 |
#$result["argu"],使用的參數.
|
|
|
2873 |
#$result["content"],要寫入log的內容字串.
|
|
|
2874 |
#必填參數:
|
|
|
2875 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2876 |
$conf["config::record"]["path"]="/tmp/test.log";
|
|
|
2877 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2878 |
$conf["config::record"]["content"]=$client;
|
|
|
2879 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2880 |
$conf["config::record"]["fileArgu"]=__FILE__;
|
|
|
2881 |
#可省略參數:
|
|
|
2882 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2883 |
#$conf["rewrite"]="false";
|
|
|
2884 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2885 |
#$conf["returnOnly"]="true";
|
|
|
2886 |
#參考資料:
|
|
|
2887 |
#無.
|
|
|
2888 |
#備註:
|
|
|
2889 |
#無.
|
|
|
2890 |
config::record($conf["config::record"]);
|
|
|
2891 |
unset($conf["config::record"]);
|
| 226 |
liveuser |
2892 |
|
| 3 |
liveuser |
2893 |
*/
|
| 226 |
liveuser |
2894 |
|
| 3 |
liveuser |
2895 |
#如果執行失敗
|
|
|
2896 |
if($client["status"]==="false"){
|
| 226 |
liveuser |
2897 |
|
| 3 |
liveuser |
2898 |
#設置錯誤識別
|
|
|
2899 |
$result["status"]="false";
|
| 226 |
liveuser |
2900 |
|
| 3 |
liveuser |
2901 |
#設置錯誤訊息
|
|
|
2902 |
$result["error"]=$client;
|
| 226 |
liveuser |
2903 |
|
| 3 |
liveuser |
2904 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2905 |
|
| 3 |
liveuser |
2906 |
#寫入回應的內容
|
|
|
2907 |
fwrite($conf["socket"],json_encode($result).PHP_EOL);
|
| 226 |
liveuser |
2908 |
|
| 3 |
liveuser |
2909 |
#結束回應
|
|
|
2910 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2911 |
|
| 3 |
liveuser |
2912 |
#關閉socket連線,將回應輸出.
|
|
|
2913 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2914 |
|
| 3 |
liveuser |
2915 |
#回傳給用戶 - end
|
| 226 |
liveuser |
2916 |
|
| 3 |
liveuser |
2917 |
#回傳結果
|
|
|
2918 |
return $result;
|
| 226 |
liveuser |
2919 |
|
| 3 |
liveuser |
2920 |
}#if end
|
|
|
2921 |
|
|
|
2922 |
#新增 client cache 內容
|
|
|
2923 |
$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["content"]=$client["rawContent"];
|
|
|
2924 |
|
|
|
2925 |
#更新 client cache 的最後更新時間
|
|
|
2926 |
$conf["clientCache"]["share"]["configs"][$conf["request"]["server"]][$conf["request"]["postName"]]["time"]=time();
|
|
|
2927 |
|
|
|
2928 |
#debug
|
|
|
2929 |
#var_dump(__LINE__,$conf["clientCache"]["share"]["configs"]);
|
|
|
2930 |
|
|
|
2931 |
#初始化要傳遞的訊息
|
|
|
2932 |
$msg=array();
|
|
|
2933 |
|
|
|
2934 |
#設置 msg content
|
|
|
2935 |
$msg["content"]=$client["rawContent"];
|
| 226 |
liveuser |
2936 |
|
| 3 |
liveuser |
2937 |
#設置 msg status
|
|
|
2938 |
$msg["status"]="true";
|
| 226 |
liveuser |
2939 |
|
| 3 |
liveuser |
2940 |
#設置執行正常
|
|
|
2941 |
$result["status"]="true";
|
|
|
2942 |
|
|
|
2943 |
#回傳給用戶 - start
|
| 226 |
liveuser |
2944 |
|
| 3 |
liveuser |
2945 |
#寫入回應的內容
|
|
|
2946 |
fwrite($conf["socket"],json_encode($msg).PHP_EOL);
|
| 226 |
liveuser |
2947 |
|
| 3 |
liveuser |
2948 |
#結束回應
|
|
|
2949 |
fwrite($conf["socket"],PHP_EOL.PHP_EOL);
|
| 226 |
liveuser |
2950 |
|
| 3 |
liveuser |
2951 |
#關閉socket連線,將回應輸出.
|
|
|
2952 |
fclose($conf["socket"]);
|
| 226 |
liveuser |
2953 |
|
| 3 |
liveuser |
2954 |
#回傳給用戶 - end
|
|
|
2955 |
|
|
|
2956 |
#回傳結果
|
|
|
2957 |
return $result;
|
| 226 |
liveuser |
2958 |
|
| 3 |
liveuser |
2959 |
}#function addOnProcessFuncForClientCacheDaemon end
|
| 226 |
liveuser |
2960 |
|
| 3 |
liveuser |
2961 |
/*
|
|
|
2962 |
#函式說明:
|
|
|
2963 |
#給clientCacheDaemon用的funcToRunWhenIdle,處理來自config::client產生的cache內容,若過期就更新,若跟cache檔案不同就更新檔案,若有cache檔案但尚未cache住就cache之.
|
|
|
2964 |
#回傳結果:
|
|
|
2965 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2966 |
#$result["error"],錯誤訊息陣列.
|
|
|
2967 |
#$result["function"],當前執行的函數名稱.
|
|
|
2968 |
#$result["warning"],警告訊息陣列.
|
|
|
2969 |
#必填參數:
|
|
|
2970 |
#$conf["client"],陣列,用戶的socket.
|
|
|
2971 |
#$conf["client"]=array();
|
|
|
2972 |
#$conf["info"],陣列,sock跟cache file path資訊.
|
|
|
2973 |
#$conf["info"]=array();
|
|
|
2974 |
#$conf["info"]["sock"],字串,unix domain socket addr.
|
|
|
2975 |
#$conf["info"]["sock"]=;
|
|
|
2976 |
#$conf["info"]["cacheFilePath"],字串,cache file path.
|
|
|
2977 |
#$conf["info"]["cacheFilePath"]=;
|
|
|
2978 |
#$conf["info"]["checkVersionInterval"],字串,距離最後一次取得資料的時間多久就要檢查是否有新資料,預設為60秒.
|
|
|
2979 |
#$conf["info"]["checkVersionInterval"]="60";
|
|
|
2980 |
#$conf["serverCache"],陣列.存放跟取得快取的陣列.
|
|
|
2981 |
#$conf["serverCache"]=array();
|
|
|
2982 |
#可省略參數:
|
|
|
2983 |
#無.
|
|
|
2984 |
#參考資料:
|
|
|
2985 |
#無.
|
|
|
2986 |
#備註:
|
|
|
2987 |
#無,
|
|
|
2988 |
*/
|
|
|
2989 |
public static function funcToRunWhenIdleForClientCacheDaemon(&$conf){
|
| 226 |
liveuser |
2990 |
|
| 3 |
liveuser |
2991 |
$result=array();
|
|
|
2992 |
|
|
|
2993 |
#取得當前執行的函數名稱
|
|
|
2994 |
$result["function"]=__FUNCTION__;
|
|
|
2995 |
|
|
|
2996 |
#取得參數
|
|
|
2997 |
$result["argu"]=$conf;
|
|
|
2998 |
|
|
|
2999 |
#如果 $conf 不為陣列
|
|
|
3000 |
if(gettype($conf)!="array"){
|
|
|
3001 |
|
|
|
3002 |
#設置執行失敗
|
|
|
3003 |
$result["status"]="false";
|
|
|
3004 |
|
|
|
3005 |
#設置執行錯誤訊息
|
|
|
3006 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3007 |
|
|
|
3008 |
#如果傳入的參數為 null
|
|
|
3009 |
if(is_null($conf)){
|
|
|
3010 |
|
|
|
3011 |
#設置執行錯誤訊息
|
|
|
3012 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3013 |
|
|
|
3014 |
}#if end
|
|
|
3015 |
|
|
|
3016 |
#回傳結果
|
|
|
3017 |
return $result;
|
|
|
3018 |
|
|
|
3019 |
}#if end
|
| 226 |
liveuser |
3020 |
|
| 3 |
liveuser |
3021 |
#函式說明:
|
|
|
3022 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
3023 |
#回傳結果:
|
|
|
3024 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3025 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
3026 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
3027 |
#$result["function"],當前執行的函式名稱.
|
|
|
3028 |
#$result["argu"],設置給予的參數.
|
|
|
3029 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3030 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3031 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3032 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3033 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3034 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3035 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3036 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3037 |
#必填參數:
|
|
|
3038 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3039 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3040 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3041 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3042 |
#可省略參數:
|
|
|
3043 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3044 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","info","serverCache");
|
|
|
3045 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3046 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
|
|
|
3047 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3048 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3049 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3050 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("info");
|
|
|
3051 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3052 |
#$conf["canBeEmpty"]=array();
|
|
|
3053 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3054 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
3055 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3056 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","request");
|
|
|
3057 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3058 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("resource","array");
|
|
|
3059 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3060 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
3061 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3062 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3063 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3064 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3065 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
3066 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
3067 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3068 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3069 |
#參考資料:
|
|
|
3070 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3071 |
#備註:
|
|
|
3072 |
#無.
|
|
|
3073 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3074 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3075 |
|
| 3 |
liveuser |
3076 |
#如果執行失敗
|
|
|
3077 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
3078 |
|
| 3 |
liveuser |
3079 |
#設置錯誤識別
|
|
|
3080 |
$result["status"]="false";
|
| 226 |
liveuser |
3081 |
|
| 3 |
liveuser |
3082 |
#設置錯誤訊息
|
|
|
3083 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3084 |
|
| 3 |
liveuser |
3085 |
#回傳結果
|
|
|
3086 |
return $result;
|
| 226 |
liveuser |
3087 |
|
| 3 |
liveuser |
3088 |
}#if end
|
| 226 |
liveuser |
3089 |
|
| 3 |
liveuser |
3090 |
#如果檢查不通過
|
|
|
3091 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
3092 |
|
| 3 |
liveuser |
3093 |
#設置錯誤識別
|
|
|
3094 |
$result["status"]="false";
|
| 226 |
liveuser |
3095 |
|
| 3 |
liveuser |
3096 |
#設置錯誤訊息
|
|
|
3097 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3098 |
|
| 3 |
liveuser |
3099 |
#回傳結果
|
|
|
3100 |
return $result;
|
| 226 |
liveuser |
3101 |
|
| 3 |
liveuser |
3102 |
}#if end
|
| 226 |
liveuser |
3103 |
|
| 3 |
liveuser |
3104 |
#debug
|
|
|
3105 |
#var_dump(__LINE__,$conf);
|
| 226 |
liveuser |
3106 |
|
| 3 |
liveuser |
3107 |
#函式說明:
|
|
|
3108 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
3109 |
#回傳結果:
|
|
|
3110 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3111 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
3112 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
3113 |
#$result["function"],當前執行的函式名稱.
|
|
|
3114 |
#$result["argu"],設置給予的參數.
|
|
|
3115 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3116 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3117 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3118 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3119 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3120 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3121 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3122 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3123 |
#必填參數:
|
|
|
3124 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3125 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["info"];
|
|
|
3126 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3127 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3128 |
#可省略參數:
|
|
|
3129 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3130 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sock","cacheFilePath","checkVersionInterval");
|
|
|
3131 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3132 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
3133 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3134 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3135 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3136 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("sock");
|
|
|
3137 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3138 |
#$conf["canBeEmpty"]=array();
|
|
|
3139 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3140 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock");
|
|
|
3141 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3142 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","request");
|
|
|
3143 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3144 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("resource","array");
|
|
|
3145 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3146 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
3147 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3148 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3149 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3150 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3151 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
3152 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
3153 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3154 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3155 |
#參考資料:
|
|
|
3156 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3157 |
#備註:
|
|
|
3158 |
#無.
|
|
|
3159 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3160 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3161 |
|
| 3 |
liveuser |
3162 |
#如果執行失敗
|
|
|
3163 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
3164 |
|
| 3 |
liveuser |
3165 |
#設置錯誤識別
|
|
|
3166 |
$result["status"]="false";
|
| 226 |
liveuser |
3167 |
|
| 3 |
liveuser |
3168 |
#設置錯誤訊息
|
|
|
3169 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3170 |
|
| 3 |
liveuser |
3171 |
#回傳結果
|
|
|
3172 |
return $result;
|
| 226 |
liveuser |
3173 |
|
| 3 |
liveuser |
3174 |
}#if end
|
| 226 |
liveuser |
3175 |
|
| 3 |
liveuser |
3176 |
#如果檢查不通過
|
|
|
3177 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
3178 |
|
| 3 |
liveuser |
3179 |
#設置錯誤識別
|
|
|
3180 |
$result["status"]="false";
|
| 226 |
liveuser |
3181 |
|
| 3 |
liveuser |
3182 |
#設置錯誤訊息
|
|
|
3183 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3184 |
|
| 3 |
liveuser |
3185 |
#回傳結果
|
|
|
3186 |
return $result;
|
| 226 |
liveuser |
3187 |
|
| 3 |
liveuser |
3188 |
}#if end
|
| 226 |
liveuser |
3189 |
|
| 3 |
liveuser |
3190 |
#另存 cacheFilePath
|
|
|
3191 |
$cacheFilePath=$conf["info"]["cacheFilePath"];
|
| 226 |
liveuser |
3192 |
|
| 3 |
liveuser |
3193 |
#另存 checkVersionInterval
|
|
|
3194 |
$checkVersionInterval=$conf["info"]["checkVersionInterval"];
|
| 226 |
liveuser |
3195 |
|
| 3 |
liveuser |
3196 |
#檢查之前執行的 config:client - start
|
| 226 |
liveuser |
3197 |
|
| 3 |
liveuser |
3198 |
#如果有儲存之前執行的 config:client
|
|
|
3199 |
if(isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"])){
|
| 226 |
liveuser |
3200 |
|
|
|
3201 |
#針對每個 proc
|
| 3 |
liveuser |
3202 |
foreach($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"] as $index => $porc){
|
| 226 |
liveuser |
3203 |
|
| 3 |
liveuser |
3204 |
#如果程序已經結束
|
|
|
3205 |
if($porc["proc_get_status"]["running"]===false){
|
| 226 |
liveuser |
3206 |
|
| 3 |
liveuser |
3207 |
#如果程序正常結束
|
|
|
3208 |
if($porc["proc_get_status"]["exitcode"]===0){
|
| 226 |
liveuser |
3209 |
|
| 3 |
liveuser |
3210 |
#取得輸出
|
|
|
3211 |
$clientConfigRes=stream_get_contents($porc["content"]);
|
| 226 |
liveuser |
3212 |
|
| 3 |
liveuser |
3213 |
#set json string content
|
|
|
3214 |
$conf["serverCache"]["clientSide"]["share"]["configs"][$porc["server"]][$proc["postName"]]["content"]=$clientConfigRes;
|
| 226 |
liveuser |
3215 |
|
| 3 |
liveuser |
3216 |
}#if end
|
| 226 |
liveuser |
3217 |
|
| 3 |
liveuser |
3218 |
#移除之
|
|
|
3219 |
unset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]);
|
| 226 |
liveuser |
3220 |
|
| 3 |
liveuser |
3221 |
}#if end
|
| 226 |
liveuser |
3222 |
|
| 3 |
liveuser |
3223 |
#反之
|
|
|
3224 |
else {
|
| 226 |
liveuser |
3225 |
|
| 3 |
liveuser |
3226 |
#更新 proc_get_status
|
|
|
3227 |
$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][$index]["proc_get_status"]=proc_get_status($porc["process"]);
|
| 226 |
liveuser |
3228 |
|
| 3 |
liveuser |
3229 |
}#else end
|
| 226 |
liveuser |
3230 |
|
| 3 |
liveuser |
3231 |
}#foreach end
|
| 226 |
liveuser |
3232 |
|
| 3 |
liveuser |
3233 |
#儲存 procs 的元素數量
|
|
|
3234 |
$procsCount=count($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"]);
|
| 226 |
liveuser |
3235 |
|
| 3 |
liveuser |
3236 |
#如果有proc尚未結束
|
|
|
3237 |
if($procsCount>0){
|
| 226 |
liveuser |
3238 |
|
| 3 |
liveuser |
3239 |
#提示之
|
|
|
3240 |
echo "尚有 ".$procsCount." 個取得 config 的程序執行中".PHP_EOL;
|
| 226 |
liveuser |
3241 |
|
| 3 |
liveuser |
3242 |
#設置執行正常
|
|
|
3243 |
$result["status"]="true";
|
| 226 |
liveuser |
3244 |
|
| 3 |
liveuser |
3245 |
#回傳結果
|
|
|
3246 |
return $result;
|
| 226 |
liveuser |
3247 |
|
| 3 |
liveuser |
3248 |
}#if end
|
| 226 |
liveuser |
3249 |
|
| 3 |
liveuser |
3250 |
}#if end
|
| 226 |
liveuser |
3251 |
|
| 3 |
liveuser |
3252 |
#檢查之前執行的 config:client - end
|
| 226 |
liveuser |
3253 |
|
| 3 |
liveuser |
3254 |
#檢查有每個 cache 檔案,若沒有對應的 clientCache,則 cache 之. - start
|
| 226 |
liveuser |
3255 |
|
| 3 |
liveuser |
3256 |
#函式說明:
|
|
|
3257 |
#取得目錄底下的詳細資訊.
|
|
|
3258 |
#回傳結果:
|
|
|
3259 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3260 |
#$result["error"],錯誤訊息.
|
|
|
3261 |
#$result["function"],當前執行的函數名稱.
|
|
|
3262 |
#$result["size"],該清單的大小,單位為bytes.
|
|
|
3263 |
#$result["dataCount"],該清單的長度.
|
|
|
3264 |
#$result["content"],指定目錄底下的所有檔案資訊.
|
|
|
3265 |
#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
|
|
|
3266 |
#$result["content"][$i]["nType"],第$i個節點類型.
|
|
|
3267 |
#$result["content"][$i]["permission"],第$i個節點權限.
|
|
|
3268 |
#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
|
|
|
3269 |
#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
|
|
|
3270 |
#$result["content"][$i]["bytes"],第$i個節點大小.
|
|
|
3271 |
#$result["content"][$i]["date"],第$i個節點最後變更日期.
|
|
|
3272 |
#$result["content"][$i]["time"],第$i個節點最後異動時間.
|
|
|
3273 |
#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
|
|
|
3274 |
#$result["content"][$i]["timezone"],第$i個節點的時區.
|
|
|
3275 |
#$result["content"][$i]["name"],第$i個節點的名稱.
|
|
|
3276 |
#必填參數:
|
|
|
3277 |
#$conf["path"],字串,要檢視的路徑.
|
|
|
3278 |
$conf["fileAccess::ls"]["path"]=$cacheFilePath;
|
|
|
3279 |
#可省略參數:
|
|
|
3280 |
#無.
|
|
|
3281 |
#參考資料:
|
|
|
3282 |
#https://www.businessweekly.com.tw/careers/Blog/14307
|
|
|
3283 |
#備註:
|
|
|
3284 |
#清單要不包含 "."開頭 跟 "~" 開頭
|
|
|
3285 |
$ls=fileAccess::ls($conf["fileAccess::ls"]);
|
|
|
3286 |
unset($conf["fileAccess::ls"]);
|
| 226 |
liveuser |
3287 |
|
| 3 |
liveuser |
3288 |
#如果執行失敗
|
|
|
3289 |
if($ls["status"]==="false"){
|
| 226 |
liveuser |
3290 |
|
| 3 |
liveuser |
3291 |
#設置錯誤識別
|
|
|
3292 |
$result["status"]="false";
|
| 226 |
liveuser |
3293 |
|
| 3 |
liveuser |
3294 |
#設置錯誤訊息
|
|
|
3295 |
$result["error"]=$ls;
|
| 226 |
liveuser |
3296 |
|
| 3 |
liveuser |
3297 |
#debug
|
|
|
3298 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3299 |
|
| 3 |
liveuser |
3300 |
#回傳結果
|
|
|
3301 |
return $result;
|
| 226 |
liveuser |
3302 |
|
| 3 |
liveuser |
3303 |
}#if end
|
| 226 |
liveuser |
3304 |
|
| 3 |
liveuser |
3305 |
#針對每個節點
|
|
|
3306 |
foreach($ls["content"] as $nodeInfo){
|
| 226 |
liveuser |
3307 |
|
| 3 |
liveuser |
3308 |
#檔案名稱
|
|
|
3309 |
#$nodeInfo["name"]
|
| 226 |
liveuser |
3310 |
|
| 3 |
liveuser |
3311 |
#已經chche後的檔案陣列
|
|
|
3312 |
#$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]
|
| 226 |
liveuser |
3313 |
|
| 3 |
liveuser |
3314 |
#如果沒有已經cache的項目
|
|
|
3315 |
if(!isset($conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"])){
|
| 226 |
liveuser |
3316 |
|
| 3 |
liveuser |
3317 |
#初始化之
|
|
|
3318 |
$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"]=array();
|
| 226 |
liveuser |
3319 |
|
| 3 |
liveuser |
3320 |
}#if end
|
| 226 |
liveuser |
3321 |
|
| 3 |
liveuser |
3322 |
#函式說明:
|
|
|
3323 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
3324 |
#回傳結果:
|
|
|
3325 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
3326 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
3327 |
#$result["error"],錯誤訊息
|
|
|
3328 |
#$result["function"],當前執行的函數名稱
|
|
|
3329 |
#$result["argv"],使用的參數
|
|
|
3330 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
3331 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
3332 |
#必填參數:
|
|
|
3333 |
#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
|
|
|
3334 |
$conf["search::getEqualVar"]["conditionElement"]=$nodeInfo["name"];
|
|
|
3335 |
#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
|
|
|
3336 |
$conf["search::getEqualVar"]["compareElements"]=$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"];
|
|
|
3337 |
#可省略參數:
|
|
|
3338 |
#無.
|
|
|
3339 |
#參考資料:
|
|
|
3340 |
#無.
|
|
|
3341 |
#備註:
|
|
|
3342 |
#無.
|
|
|
3343 |
$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
|
|
|
3344 |
unset($conf["search::getEqualVar"]);
|
| 226 |
liveuser |
3345 |
|
| 3 |
liveuser |
3346 |
#debug
|
|
|
3347 |
#var_dump(__LINE__,$getEqualVar);
|
| 226 |
liveuser |
3348 |
|
| 3 |
liveuser |
3349 |
#如果執行失敗
|
|
|
3350 |
if($getEqualVar["status"]==="false"){
|
| 226 |
liveuser |
3351 |
|
| 3 |
liveuser |
3352 |
#設置錯誤識別
|
|
|
3353 |
$result["status"]="false";
|
| 226 |
liveuser |
3354 |
|
| 3 |
liveuser |
3355 |
#設置錯誤訊息
|
|
|
3356 |
$result["error"]=$getEqualVar;
|
| 226 |
liveuser |
3357 |
|
| 3 |
liveuser |
3358 |
#debug
|
|
|
3359 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3360 |
|
| 3 |
liveuser |
3361 |
#回傳結果
|
|
|
3362 |
return $result;
|
| 226 |
liveuser |
3363 |
|
| 3 |
liveuser |
3364 |
}#if end
|
| 226 |
liveuser |
3365 |
|
| 3 |
liveuser |
3366 |
#如果已經cache過
|
|
|
3367 |
if($getEqualVar["founded"]==="true"){
|
| 226 |
liveuser |
3368 |
|
| 3 |
liveuser |
3369 |
#換下個檔案
|
|
|
3370 |
continue;
|
| 226 |
liveuser |
3371 |
|
| 3 |
liveuser |
3372 |
}#if end
|
| 226 |
liveuser |
3373 |
|
| 3 |
liveuser |
3374 |
#debug
|
|
|
3375 |
#var_dump(__LINE__,$getEqualVar);
|
| 226 |
liveuser |
3376 |
|
| 3 |
liveuser |
3377 |
#如果是檔案
|
|
|
3378 |
if($nodeInfo["nType"]==="-"){
|
| 226 |
liveuser |
3379 |
|
| 3 |
liveuser |
3380 |
#debug
|
|
|
3381 |
#var_dump(__LINE__,"檢測尚未cache的檔案",$nodeInfo);
|
| 226 |
liveuser |
3382 |
|
| 3 |
liveuser |
3383 |
#判斷是否為cache檔案,範例:"client::config-cache-".urlencode($conf["request"]["postName"])." from ".urlencode($conf["request"]["server"]).".json";
|
|
|
3384 |
#函式說明:
|
|
|
3385 |
#檢查字串是否符合指定格式
|
|
|
3386 |
#回傳結果:
|
|
|
3387 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3388 |
#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.
|
|
|
3389 |
#$result["content"],詳細結果訊息陣列,若passed為"false"則會有該內容.
|
|
|
3390 |
#$result["newInputArgu"],剩下尚未檢驗格式的input.
|
|
|
3391 |
#$result["function"],當前執行的函數.
|
|
|
3392 |
#$result["error"],涵式錯誤訊息陣列.
|
|
|
3393 |
#必填參數:
|
|
|
3394 |
#$conf["input"],字串,要檢查格式的字串.
|
|
|
3395 |
$conf["variableCheck::checkStringFormat"]["input"]=$nodeInfo["name"];
|
|
|
3396 |
#可省略參數:
|
|
|
3397 |
#$conf["equalWith"],字串,輸入字串是否等於該參數內容.
|
|
|
3398 |
#$conf["variableCheck::checkStringFormat"]["equalWith"]=".json";
|
|
|
3399 |
#$conf["startWith"],字串,開頭要是什麼字串內容.
|
|
|
3400 |
$conf["variableCheck::checkStringFormat"]["startWith"]="client::config-cache-";
|
|
|
3401 |
#$conf["endWith"],字串,結尾要是什麼字串內容.
|
|
|
3402 |
$conf["variableCheck::checkStringFormat"]["endWith"]=".json";
|
|
|
3403 |
#$conf["centerWith"],字串,非開頭(預設無,若有指定startWith參數,則為該參數內容)跟結尾(預設無,若有指定endWith參數,則為該參數內容)的內容中要有什麼字串.
|
|
|
3404 |
$conf["variableCheck::checkStringFormat"]["centerWith"]=" from https";
|
|
|
3405 |
#$conf["length"],字串整數,字串的長度要多少(bytes).
|
|
|
3406 |
#$conf["length"]="";
|
|
|
3407 |
#$conf["lengthGrapheme"],字串整數,字串的長度要多少字位(grapheme).
|
|
|
3408 |
#$conf["lengthGrapheme"]="";
|
|
|
3409 |
#$conf["section"],字串陣列,元素數量代表,輸入字串的格式可以區分成多少段.每個元素為本函式的參數陣列剔除input跟section參數.
|
|
|
3410 |
#$conf["section"]=array();
|
|
|
3411 |
#參考資料:
|
|
|
3412 |
#grapheme_strlen=>https://www.php.net/manual/en/function.grapheme-strlen.php
|
|
|
3413 |
#grapheme/字位/可以書寫的最小單位=>https://zh.wikipedia.org/zh-tw/%E5%AD%97%E4%BD%8D
|
|
|
3414 |
#grapheme_substr=>https://www.php.net/manual/en/function.grapheme-substr.php
|
|
|
3415 |
#備註:
|
|
|
3416 |
#無.
|
|
|
3417 |
$checkStringFormat=variableCheck::checkStringFormat($conf["variableCheck::checkStringFormat"]);
|
|
|
3418 |
unset($conf["variableCheck::checkStringFormat"]);
|
| 226 |
liveuser |
3419 |
|
| 3 |
liveuser |
3420 |
#debug
|
|
|
3421 |
#var_dump(__LINE__,$checkStringFormat);
|
| 226 |
liveuser |
3422 |
|
| 3 |
liveuser |
3423 |
#如果執行失敗
|
|
|
3424 |
if($checkStringFormat["status"]==="false"){
|
| 226 |
liveuser |
3425 |
|
| 3 |
liveuser |
3426 |
#設置錯誤識別
|
|
|
3427 |
$result["status"]="false";
|
| 226 |
liveuser |
3428 |
|
| 3 |
liveuser |
3429 |
#設置錯誤訊息
|
|
|
3430 |
$result["error"]=$checkStringFormat;
|
| 226 |
liveuser |
3431 |
|
| 3 |
liveuser |
3432 |
#debug
|
|
|
3433 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3434 |
|
| 3 |
liveuser |
3435 |
#回傳結果
|
|
|
3436 |
return $result;
|
| 226 |
liveuser |
3437 |
|
| 3 |
liveuser |
3438 |
}#if end
|
| 226 |
liveuser |
3439 |
|
| 3 |
liveuser |
3440 |
#如果是符合的暫存檔案
|
|
|
3441 |
if($checkStringFormat["passed"]==="true"){
|
| 226 |
liveuser |
3442 |
|
| 3 |
liveuser |
3443 |
#解析對應的 postName 與 server - start
|
| 226 |
liveuser |
3444 |
|
| 3 |
liveuser |
3445 |
#函式說明:
|
|
|
3446 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3447 |
#回傳結果:
|
|
|
3448 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3449 |
#$result["error"],錯誤訊息陣列.
|
|
|
3450 |
#$result["warning"],警告訊息鎮列.
|
|
|
3451 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3452 |
#$result["function"],當前執行的函數名稱.
|
|
|
3453 |
#$result["argu"],使用的參數.
|
|
|
3454 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3455 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3456 |
#必填參數:
|
|
|
3457 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3458 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$nodeInfo["name"];
|
|
|
3459 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3460 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="client::config-cache-";
|
|
|
3461 |
#可省略參數:
|
|
|
3462 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3463 |
#$conf["recursive"]="true";
|
|
|
3464 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
3465 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
3466 |
#參考資料:
|
|
|
3467 |
#無.
|
|
|
3468 |
#備註:
|
|
|
3469 |
#無.
|
|
|
3470 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3471 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3472 |
|
| 3 |
liveuser |
3473 |
#如果執行失敗
|
|
|
3474 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3475 |
|
| 3 |
liveuser |
3476 |
#設置錯誤識別
|
|
|
3477 |
$result["status"]="false";
|
| 226 |
liveuser |
3478 |
|
| 3 |
liveuser |
3479 |
#設置錯誤訊息
|
|
|
3480 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
3481 |
|
| 3 |
liveuser |
3482 |
#debug
|
|
|
3483 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3484 |
|
| 3 |
liveuser |
3485 |
#回傳結果
|
|
|
3486 |
return $result;
|
| 226 |
liveuser |
3487 |
|
| 3 |
liveuser |
3488 |
}#if end
|
| 226 |
liveuser |
3489 |
|
| 3 |
liveuser |
3490 |
#如果沒有關鍵字
|
|
|
3491 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
3492 |
|
| 3 |
liveuser |
3493 |
#設置錯誤識別
|
|
|
3494 |
$result["status"]="false";
|
| 226 |
liveuser |
3495 |
|
| 3 |
liveuser |
3496 |
#設置錯誤訊息
|
|
|
3497 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
3498 |
|
| 3 |
liveuser |
3499 |
#debug
|
|
|
3500 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3501 |
|
| 3 |
liveuser |
3502 |
#回傳結果
|
|
|
3503 |
return $result;
|
| 226 |
liveuser |
3504 |
|
| 3 |
liveuser |
3505 |
}#if end
|
| 226 |
liveuser |
3506 |
|
| 3 |
liveuser |
3507 |
#函式說明:
|
|
|
3508 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3509 |
#回傳結果:
|
|
|
3510 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3511 |
#$result["error"],錯誤訊息陣列.
|
|
|
3512 |
#$result["warning"],警告訊息鎮列.
|
|
|
3513 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3514 |
#$result["function"],當前執行的函數名稱.
|
|
|
3515 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3516 |
#$result["content"],處理好的的字串內容.
|
|
|
3517 |
#$result["argu"],使用的參數.
|
|
|
3518 |
#必填參數:
|
|
|
3519 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3520 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
|
|
|
3521 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3522 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".json";
|
|
|
3523 |
#可省略參數:
|
|
|
3524 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3525 |
$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
|
|
|
3526 |
#參考資料:
|
|
|
3527 |
#無.
|
|
|
3528 |
#備註:
|
|
|
3529 |
#無.
|
|
|
3530 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3531 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 226 |
liveuser |
3532 |
|
| 3 |
liveuser |
3533 |
#如果執行失敗
|
|
|
3534 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3535 |
|
| 3 |
liveuser |
3536 |
#設置錯誤識別
|
|
|
3537 |
$result["status"]="false";
|
| 226 |
liveuser |
3538 |
|
| 3 |
liveuser |
3539 |
#設置錯誤訊息
|
|
|
3540 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
3541 |
|
| 3 |
liveuser |
3542 |
#debug
|
|
|
3543 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3544 |
|
| 3 |
liveuser |
3545 |
#回傳結果
|
|
|
3546 |
return $result;
|
| 226 |
liveuser |
3547 |
|
| 3 |
liveuser |
3548 |
}#if end
|
| 226 |
liveuser |
3549 |
|
| 3 |
liveuser |
3550 |
#如果沒有關鍵字
|
|
|
3551 |
if($delStrAfterKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
3552 |
|
| 3 |
liveuser |
3553 |
#設置錯誤識別
|
|
|
3554 |
$result["status"]="false";
|
| 226 |
liveuser |
3555 |
|
| 3 |
liveuser |
3556 |
#設置錯誤訊息
|
|
|
3557 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
3558 |
|
| 3 |
liveuser |
3559 |
#debug
|
|
|
3560 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3561 |
|
| 3 |
liveuser |
3562 |
#回傳結果
|
|
|
3563 |
return $result;
|
| 226 |
liveuser |
3564 |
|
| 3 |
liveuser |
3565 |
}#if end
|
| 226 |
liveuser |
3566 |
|
| 3 |
liveuser |
3567 |
#另存postName與server的字串
|
|
|
3568 |
$postNameAndServerStr=$delStrAfterKeyWord["content"];
|
| 226 |
liveuser |
3569 |
|
| 3 |
liveuser |
3570 |
#用 " from " 來切割
|
|
|
3571 |
#函式說明:
|
|
|
3572 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
3573 |
#回傳結果:
|
|
|
3574 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3575 |
#$result["error"],錯誤訊息陣列
|
|
|
3576 |
#$result["function"],當前執行的函數名稱.
|
|
|
3577 |
#$result["argu"],使用的參數.
|
|
|
3578 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
3579 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
3580 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
3581 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
3582 |
#必填參數:
|
|
|
3583 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3584 |
$conf["stringProcess::spiltString"]["stringIn"]=$postNameAndServerStr;
|
|
|
3585 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
3586 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" from ";
|
|
|
3587 |
#可省略參數:
|
|
|
3588 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
3589 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
3590 |
#參考資料:
|
|
|
3591 |
#無.
|
|
|
3592 |
#備註:
|
|
|
3593 |
#無.
|
|
|
3594 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
3595 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
3596 |
|
| 3 |
liveuser |
3597 |
#如果執行失敗
|
|
|
3598 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
3599 |
|
| 3 |
liveuser |
3600 |
#設置錯誤識別
|
|
|
3601 |
$result["status"]="false";
|
| 226 |
liveuser |
3602 |
|
| 3 |
liveuser |
3603 |
#設置錯誤訊息
|
|
|
3604 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3605 |
|
| 3 |
liveuser |
3606 |
#debug
|
|
|
3607 |
var_dump(__LINE__,$resutl);
|
| 226 |
liveuser |
3608 |
|
| 3 |
liveuser |
3609 |
#回傳結果
|
|
|
3610 |
return $result;
|
| 226 |
liveuser |
3611 |
|
| 3 |
liveuser |
3612 |
}#if end
|
| 226 |
liveuser |
3613 |
|
| 3 |
liveuser |
3614 |
#如果沒有應該要存在的關鍵字
|
|
|
3615 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
3616 |
|
| 3 |
liveuser |
3617 |
#設置錯誤識別
|
|
|
3618 |
$result["status"]="false";
|
| 226 |
liveuser |
3619 |
|
| 3 |
liveuser |
3620 |
#設置錯誤訊息
|
|
|
3621 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3622 |
|
| 3 |
liveuser |
3623 |
#debug
|
|
|
3624 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3625 |
|
| 3 |
liveuser |
3626 |
#回傳結果
|
|
|
3627 |
return $result;
|
| 226 |
liveuser |
3628 |
|
| 3 |
liveuser |
3629 |
}#if end
|
| 226 |
liveuser |
3630 |
|
| 3 |
liveuser |
3631 |
#如果沒有切割出2兩段以上
|
|
|
3632 |
if($spiltString["dataCounts"]<2){
|
| 226 |
liveuser |
3633 |
|
| 3 |
liveuser |
3634 |
#設置錯誤識別
|
|
|
3635 |
$result["status"]="false";
|
| 226 |
liveuser |
3636 |
|
| 3 |
liveuser |
3637 |
#設置錯誤訊息
|
|
|
3638 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3639 |
|
| 3 |
liveuser |
3640 |
#debug
|
|
|
3641 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3642 |
|
| 3 |
liveuser |
3643 |
#回傳結果
|
|
|
3644 |
return $result;
|
| 226 |
liveuser |
3645 |
|
| 3 |
liveuser |
3646 |
}#if end
|
| 226 |
liveuser |
3647 |
|
| 3 |
liveuser |
3648 |
#取得解析好的來源(urlencoded)
|
|
|
3649 |
$server=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
|
| 226 |
liveuser |
3650 |
|
| 3 |
liveuser |
3651 |
#函式說明:
|
|
|
3652 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3653 |
#回傳結果:
|
|
|
3654 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3655 |
#$result["error"],錯誤訊息陣列.
|
|
|
3656 |
#$result["warning"],警告訊息鎮列.
|
|
|
3657 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3658 |
#$result["function"],當前執行的函數名稱.
|
|
|
3659 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3660 |
#$result["content"],處理好的的字串內容.
|
|
|
3661 |
#$result["argu"],使用的參數.
|
|
|
3662 |
#必填參數:
|
|
|
3663 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3664 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$postNameAndServerStr;
|
|
|
3665 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3666 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" from ".$server;
|
|
|
3667 |
#可省略參數:
|
|
|
3668 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3669 |
$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
|
|
|
3670 |
#參考資料:
|
|
|
3671 |
#無.
|
|
|
3672 |
#備註:
|
|
|
3673 |
#無.
|
|
|
3674 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3675 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 226 |
liveuser |
3676 |
|
| 3 |
liveuser |
3677 |
#如果執行失敗
|
|
|
3678 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3679 |
|
| 3 |
liveuser |
3680 |
#設置錯誤識別
|
|
|
3681 |
$result["status"]="false";
|
| 226 |
liveuser |
3682 |
|
| 3 |
liveuser |
3683 |
#設置錯誤訊息
|
|
|
3684 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
3685 |
|
| 3 |
liveuser |
3686 |
#debug
|
|
|
3687 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3688 |
|
| 3 |
liveuser |
3689 |
#回傳結果
|
|
|
3690 |
return $result;
|
| 226 |
liveuser |
3691 |
|
| 3 |
liveuser |
3692 |
}#if end
|
| 226 |
liveuser |
3693 |
|
| 3 |
liveuser |
3694 |
#如果沒有關鍵字
|
|
|
3695 |
if($delStrAfterKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
3696 |
|
| 3 |
liveuser |
3697 |
#設置錯誤識別
|
|
|
3698 |
$result["status"]="false";
|
| 226 |
liveuser |
3699 |
|
| 3 |
liveuser |
3700 |
#設置錯誤訊息
|
|
|
3701 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
3702 |
|
| 3 |
liveuser |
3703 |
#debug
|
|
|
3704 |
var_dump(__LINE__,$resutl);
|
| 226 |
liveuser |
3705 |
|
| 3 |
liveuser |
3706 |
#回傳結果
|
|
|
3707 |
return $result;
|
| 226 |
liveuser |
3708 |
|
| 3 |
liveuser |
3709 |
}#if end
|
| 226 |
liveuser |
3710 |
|
| 3 |
liveuser |
3711 |
#另存postName與server的字串
|
|
|
3712 |
$postName=$delStrAfterKeyWord["content"];
|
| 226 |
liveuser |
3713 |
|
| 3 |
liveuser |
3714 |
#解析對應的 postName 與 server - end
|
| 226 |
liveuser |
3715 |
|
| 3 |
liveuser |
3716 |
#如果對應該cache檔案的cache不存在
|
|
|
3717 |
if(!isset($conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName])){
|
| 226 |
liveuser |
3718 |
|
| 3 |
liveuser |
3719 |
#讀取其json
|
|
|
3720 |
#函式說明:
|
|
|
3721 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
3722 |
#回傳的變數說明:
|
|
|
3723 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
3724 |
#$result["error"],錯誤訊息提示.
|
|
|
3725 |
#$result["warning"],警告訊息.
|
|
|
3726 |
#$result["function"],當前執行的函數名稱.
|
|
|
3727 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
3728 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
3729 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
3730 |
#$result["base64data"],為檔案的base64內容.
|
|
|
3731 |
#$result["mimeType"],為檔案的mime type.
|
|
|
3732 |
#必填參數:
|
|
|
3733 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
3734 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$cacheFilePath.$nodeInfo["name"];
|
|
|
3735 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3736 |
$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
3737 |
#可省略參數:
|
|
|
3738 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
3739 |
$conf["fileAccess::getFileContent"]["web"]="false";
|
|
|
3740 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
3741 |
$conf["fileAccess::getFileContent"]["createIfnotExist"]="false";
|
|
|
3742 |
#參考資料:
|
|
|
3743 |
#file(),取得檔案內容的行數.
|
|
|
3744 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
3745 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
3746 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
3747 |
#參考資料:
|
|
|
3748 |
#無.
|
|
|
3749 |
#備註:
|
|
|
3750 |
#無.
|
|
|
3751 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
3752 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
3753 |
|
| 3 |
liveuser |
3754 |
#如果執行失敗
|
|
|
3755 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
3756 |
|
| 3 |
liveuser |
3757 |
#設置錯誤識別
|
|
|
3758 |
$result["status"]="false";
|
| 226 |
liveuser |
3759 |
|
| 3 |
liveuser |
3760 |
#設置錯誤訊息
|
|
|
3761 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
3762 |
|
| 3 |
liveuser |
3763 |
#debug
|
|
|
3764 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3765 |
|
| 3 |
liveuser |
3766 |
#回傳結果
|
|
|
3767 |
return $result;
|
| 226 |
liveuser |
3768 |
|
| 3 |
liveuser |
3769 |
}#if end
|
|
|
3770 |
|
|
|
3771 |
#debug
|
|
|
3772 |
#var_dump(__LINE__,$getFileContent);
|
|
|
3773 |
|
|
|
3774 |
#set json string content
|
|
|
3775 |
$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["content"]=$getFileContent["fullContent"];
|
| 226 |
liveuser |
3776 |
|
| 3 |
liveuser |
3777 |
#設置已經有 cache 成檔案
|
|
|
3778 |
$conf["serverCache"]["clientSide"]["share"]["configs"][urldecode($server)][$postName]["cachedFile"]="true";
|
| 226 |
liveuser |
3779 |
|
| 3 |
liveuser |
3780 |
#set cached file
|
|
|
3781 |
$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]=$nodeInfo["name"];
|
| 226 |
liveuser |
3782 |
|
| 3 |
liveuser |
3783 |
#debug
|
|
|
3784 |
#var_dump(__LINE__,$conf["serverCache"]);
|
| 226 |
liveuser |
3785 |
|
| 3 |
liveuser |
3786 |
}#if end
|
| 226 |
liveuser |
3787 |
|
| 3 |
liveuser |
3788 |
}#if end
|
| 226 |
liveuser |
3789 |
|
| 3 |
liveuser |
3790 |
}#if end
|
| 226 |
liveuser |
3791 |
|
| 3 |
liveuser |
3792 |
}#foreach end
|
| 226 |
liveuser |
3793 |
|
| 3 |
liveuser |
3794 |
#檢查有每個 cache 檔案,若沒有對應的 clientCache,則cache 之. - end
|
| 226 |
liveuser |
3795 |
|
| 3 |
liveuser |
3796 |
#檢查每個 clientCache 若過期則更新之. - start
|
| 226 |
liveuser |
3797 |
|
| 3 |
liveuser |
3798 |
#如果沒有 $conf["serverCache"]["clientSide"]["share"]
|
|
|
3799 |
if(!isset($conf["serverCache"]["clientSide"]["share"])){
|
| 226 |
liveuser |
3800 |
|
| 3 |
liveuser |
3801 |
#初始化之
|
|
|
3802 |
$conf["serverCache"]["clientSide"]["share"]["configs"]=array();
|
| 226 |
liveuser |
3803 |
|
| 3 |
liveuser |
3804 |
}#if end
|
| 226 |
liveuser |
3805 |
|
| 3 |
liveuser |
3806 |
#針對每個 client site 的 share configs 變數
|
|
|
3807 |
foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
|
| 226 |
liveuser |
3808 |
|
| 3 |
liveuser |
3809 |
#針對該site每個config資訊
|
|
|
3810 |
foreach($postNames as $configName => $configVal){
|
| 226 |
liveuser |
3811 |
|
| 3 |
liveuser |
3812 |
#如果沒有最後更新時間
|
|
|
3813 |
if(!isset($postNames["time"])){
|
| 226 |
liveuser |
3814 |
|
| 3 |
liveuser |
3815 |
#設置最後更新時間
|
|
|
3816 |
$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["time"]=time();
|
| 226 |
liveuser |
3817 |
|
| 3 |
liveuser |
3818 |
#換下一個 postName
|
|
|
3819 |
continue;
|
| 226 |
liveuser |
3820 |
|
| 3 |
liveuser |
3821 |
}#if end
|
| 226 |
liveuser |
3822 |
|
| 3 |
liveuser |
3823 |
#如果過期了
|
|
|
3824 |
if( time()-$postNames["time"]>$checkVersionInterval ){
|
| 226 |
liveuser |
3825 |
|
| 3 |
liveuser |
3826 |
#嘗試從網路取得config
|
|
|
3827 |
#函式說明:
|
|
|
3828 |
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
|
|
|
3829 |
#回傳結果:
|
|
|
3830 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
3831 |
#$result["error"],錯誤訊息陣列.
|
|
|
3832 |
#$result["function"],當前執行的函數名稱.
|
|
|
3833 |
#$result["rawContent"],得到的原始訊息.
|
|
|
3834 |
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
3835 |
#必填參數:
|
|
|
3836 |
#$conf["server"],字串,組態服務設定服務的網址
|
|
|
3837 |
$conf["config::client"]["server"]=$serverUrl;
|
|
|
3838 |
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
|
|
|
3839 |
$conf["config::client"]["postName"]=$configName;
|
|
|
3840 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3841 |
$conf["config::client"]["fileArgu"]=__FILE__;
|
|
|
3842 |
#可省略參數:
|
|
|
3843 |
#$conf["cache"],字串,預設為"true",代表會啟用cache服務;反之為"false".
|
|
|
3844 |
$conf["config::client"]["cache"]="false";
|
|
|
3845 |
#$conf["clientCacheDaemonSock"],字串,提供cache服務的 unix domain socket 檔案位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock";.
|
|
|
3846 |
#$conf["clientCacheDaemonSock"]="";
|
|
|
3847 |
#$conf["inBg"],字串,預設為"false",代表在前景執行;反之為"true"代表在背景中執行,會強制將"cache"參數設為"false".
|
|
|
3848 |
$conf["config::client"]["inBg"]="true";
|
|
|
3849 |
#參考資料:
|
|
|
3850 |
#無.
|
|
|
3851 |
#備註:
|
|
|
3852 |
#目前僅能跟server函式提供的服務對接.
|
|
|
3853 |
$client=config::client($conf["config::client"]);
|
|
|
3854 |
unset($conf["config::client"]);
|
| 226 |
liveuser |
3855 |
|
| 3 |
liveuser |
3856 |
#若從網路取得成功
|
|
|
3857 |
if($client["status"]==="true"){
|
| 226 |
liveuser |
3858 |
|
| 3 |
liveuser |
3859 |
#另存來源
|
|
|
3860 |
$client["content"]["server"]=$serverUrl;
|
| 226 |
liveuser |
3861 |
|
| 3 |
liveuser |
3862 |
#另存 configName
|
|
|
3863 |
$client["content"]["postName"]=$configName;
|
| 226 |
liveuser |
3864 |
|
| 3 |
liveuser |
3865 |
#儲存起來下次再看跑完沒
|
|
|
3866 |
$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["procs"][]=$client["content"];
|
| 226 |
liveuser |
3867 |
|
| 3 |
liveuser |
3868 |
#換處理下個 configName
|
|
|
3869 |
continue;
|
| 226 |
liveuser |
3870 |
|
|
|
3871 |
}#if end
|
|
|
3872 |
|
| 3 |
liveuser |
3873 |
#執行到這邊代表從網路取得失敗
|
| 226 |
liveuser |
3874 |
|
| 3 |
liveuser |
3875 |
#將事件記錄起來
|
|
|
3876 |
var_dump(__FILE__,__LINE__,$client);
|
| 226 |
liveuser |
3877 |
|
| 3 |
liveuser |
3878 |
}#if end
|
| 226 |
liveuser |
3879 |
|
| 3 |
liveuser |
3880 |
}#foreach end
|
| 226 |
liveuser |
3881 |
|
| 3 |
liveuser |
3882 |
}#foreach end
|
| 226 |
liveuser |
3883 |
|
| 3 |
liveuser |
3884 |
#檢查每個 clientCache 若過期則更新之. - end
|
| 226 |
liveuser |
3885 |
|
| 3 |
liveuser |
3886 |
#檢查每個 clientCache 若無對應 cache file 則產生之. - start
|
| 226 |
liveuser |
3887 |
|
| 3 |
liveuser |
3888 |
#針對每個 client site 的 share configs 變數
|
|
|
3889 |
foreach($conf["serverCache"]["clientSide"]["share"]["configs"] as $serverUrl => $postNames){
|
| 226 |
liveuser |
3890 |
|
| 3 |
liveuser |
3891 |
#針對該site每個postName資訊
|
|
|
3892 |
foreach($postNames as $configName => $configVal){
|
| 226 |
liveuser |
3893 |
|
| 3 |
liveuser |
3894 |
#expected cache file name
|
|
|
3895 |
#$cacheFilePath."client::config-cache-".$configName." from ".$serverUrl.".json";
|
| 226 |
liveuser |
3896 |
|
| 3 |
liveuser |
3897 |
#realistic cache file name
|
|
|
3898 |
#$cacheFilePath."client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
|
| 226 |
liveuser |
3899 |
|
| 3 |
liveuser |
3900 |
#函式說明:
|
|
|
3901 |
#檢查多個檔案與資料夾是否存在.
|
|
|
3902 |
#回傳的結果:
|
|
|
3903 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
3904 |
#$result["error"],錯誤訊息陣列.
|
|
|
3905 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
3906 |
#$result["argu"],使用的參數.
|
|
|
3907 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
3908 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
3909 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
3910 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
3911 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
3912 |
#必填參數:
|
|
|
3913 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
3914 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cacheFilePath."client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json");
|
|
|
3915 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3916 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
3917 |
#可省略參數:
|
|
|
3918 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
3919 |
$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
|
|
|
3920 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
3921 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
3922 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
3923 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
3924 |
#參考資料:
|
|
|
3925 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
3926 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
3927 |
#備註:
|
|
|
3928 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
3929 |
#$result["varName"][$i]結果未實作
|
|
|
3930 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
3931 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
3932 |
|
| 3 |
liveuser |
3933 |
#如果執行失敗
|
|
|
3934 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
3935 |
|
| 3 |
liveuser |
3936 |
#設置錯誤識別
|
|
|
3937 |
$result["status"]="false";
|
| 226 |
liveuser |
3938 |
|
| 3 |
liveuser |
3939 |
#設置錯誤訊息
|
|
|
3940 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
3941 |
|
| 3 |
liveuser |
3942 |
#debug
|
|
|
3943 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
3944 |
|
| 3 |
liveuser |
3945 |
#回傳結果
|
|
|
3946 |
return $result;
|
| 226 |
liveuser |
3947 |
|
| 3 |
liveuser |
3948 |
}#if end
|
| 226 |
liveuser |
3949 |
|
| 3 |
liveuser |
3950 |
#如果 cache file 不存在
|
|
|
3951 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
3952 |
|
| 3 |
liveuser |
3953 |
#函式說明:
|
|
|
3954 |
#將字串寫入到檔案
|
|
|
3955 |
#回傳結果:
|
|
|
3956 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
3957 |
#$result["error"],錯誤訊息陣列.
|
|
|
3958 |
#$result["function"],當前執行的函數名稱.
|
|
|
3959 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
3960 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
3961 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
3962 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
3963 |
#$result["argu"],使用的參數.
|
|
|
3964 |
#必填參數:
|
|
|
3965 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3966 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
3967 |
#可省略參數:
|
|
|
3968 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
3969 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$cacheFilePath."client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
|
|
|
3970 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
3971 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]=$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["content"];
|
|
|
3972 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
3973 |
#$conf["writeMethod"]="a";
|
|
|
3974 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
3975 |
#$conf["checkRepeat"]="";
|
|
|
3976 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
3977 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
3978 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
3979 |
#$conf["repeatNameRule"]="";
|
|
|
3980 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
3981 |
$conf["fileAccess::writeTextIntoFile"]["web"]="false";
|
|
|
3982 |
#參考資料:
|
|
|
3983 |
#無.
|
|
|
3984 |
#備註:
|
|
|
3985 |
#無.
|
|
|
3986 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
3987 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
| 226 |
liveuser |
3988 |
|
| 3 |
liveuser |
3989 |
#如果執行失敗
|
|
|
3990 |
if($writeTextIntoFile["status"]==="false"){
|
| 226 |
liveuser |
3991 |
|
| 3 |
liveuser |
3992 |
#設置錯誤識別
|
|
|
3993 |
$result["status"]="false";
|
| 226 |
liveuser |
3994 |
|
| 3 |
liveuser |
3995 |
#設置錯誤訊息
|
|
|
3996 |
$result["error"]=$writeTextIntoFile;
|
| 226 |
liveuser |
3997 |
|
| 3 |
liveuser |
3998 |
#debug
|
|
|
3999 |
var_dump(__LINE__,$result);
|
| 226 |
liveuser |
4000 |
|
| 3 |
liveuser |
4001 |
#回傳結果
|
|
|
4002 |
return $result;
|
| 226 |
liveuser |
4003 |
|
| 3 |
liveuser |
4004 |
}#if end
|
| 226 |
liveuser |
4005 |
|
| 3 |
liveuser |
4006 |
#設置已經有 cache 成檔案
|
|
|
4007 |
$conf["serverCache"]["clientSide"]["share"]["configs"][$serverUrl][$configName]["cachedFile"]="true";
|
| 226 |
liveuser |
4008 |
|
| 3 |
liveuser |
4009 |
#set cached file
|
|
|
4010 |
$conf["serverCache"]["serverSide"]["config::funcToRunWhenIdleForClientCacheDaemon"]["cachedFile"][]="client::config-cache-".urlencode($configName)." from ".urlencode($serverUrl).".json";
|
| 226 |
liveuser |
4011 |
|
| 3 |
liveuser |
4012 |
}#if end
|
| 226 |
liveuser |
4013 |
|
| 3 |
liveuser |
4014 |
}#foreach end
|
| 226 |
liveuser |
4015 |
|
| 3 |
liveuser |
4016 |
}#foreach end
|
| 226 |
liveuser |
4017 |
|
| 3 |
liveuser |
4018 |
#檢查每個 clientCache 若無對應 cache file 則產生之. - end
|
| 226 |
liveuser |
4019 |
|
| 3 |
liveuser |
4020 |
#設置執行正常
|
|
|
4021 |
$result["status"]="true";
|
| 226 |
liveuser |
4022 |
|
| 3 |
liveuser |
4023 |
#回傳結果
|
|
|
4024 |
return $result;
|
| 226 |
liveuser |
4025 |
|
| 3 |
liveuser |
4026 |
}#function funcToRunWhenIdleForClientCacheDaemon end
|
| 226 |
liveuser |
4027 |
|
| 3 |
liveuser |
4028 |
/*
|
|
|
4029 |
#函式說明:
|
|
|
4030 |
#處理來自config::client有使用cache的要求,其為常駐的unix domain socket
|
|
|
4031 |
#回傳結果:
|
|
|
4032 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
4033 |
#$result["error"],錯誤訊息陣列.
|
|
|
4034 |
#$result["function"],當前執行的函數名稱.
|
|
|
4035 |
#必填參數:
|
|
|
4036 |
#無.
|
|
|
4037 |
#可省略參數:
|
|
|
4038 |
#$conf["sock"],字串,unix doamin socket的位置,預設為套件根目錄底下的"var/config::client/clientCacheDaemon.sock".
|
|
|
4039 |
#$conf["sock"]="";
|
|
|
4040 |
#$conf["cacheFilePath"],字串,cache的檔案位置,預設為套件根目錄底下的"var/config::client/",
|
|
|
4041 |
#$conf["cacheFilePath"]="";
|
|
|
4042 |
#$conf["checkVersionInterval"],字串,距離最後一次取得資料的時間多久就要檢查是否有新資料,預設為60秒.
|
|
|
4043 |
#$conf["checkVersionInterval"]="60";
|
|
|
4044 |
#參考資料:
|
|
|
4045 |
#無.
|
|
|
4046 |
#備註:
|
|
|
4047 |
#無,
|
|
|
4048 |
*/
|
|
|
4049 |
public static function clientCacheDaemon(&$conf){
|
| 226 |
liveuser |
4050 |
|
| 3 |
liveuser |
4051 |
#初始化要回傳的結果
|
|
|
4052 |
$result=array();
|
|
|
4053 |
|
|
|
4054 |
#取得當前執行的函數名稱
|
|
|
4055 |
$result["function"]=__FUNCTION__;
|
|
|
4056 |
|
|
|
4057 |
#取得參數
|
|
|
4058 |
$result["argu"]=$conf;
|
|
|
4059 |
|
|
|
4060 |
#如果 $conf 不為陣列
|
|
|
4061 |
if(gettype($conf)!="array"){
|
|
|
4062 |
|
|
|
4063 |
#設置執行失敗
|
|
|
4064 |
$result["status"]="false";
|
|
|
4065 |
|
|
|
4066 |
#設置執行錯誤訊息
|
|
|
4067 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4068 |
|
|
|
4069 |
#如果傳入的參數為 null
|
|
|
4070 |
if(is_null($conf)){
|
|
|
4071 |
|
|
|
4072 |
#設置執行錯誤訊息
|
|
|
4073 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4074 |
|
|
|
4075 |
}#if end
|
|
|
4076 |
|
|
|
4077 |
#回傳結果
|
|
|
4078 |
return $result;
|
|
|
4079 |
|
|
|
4080 |
}#if end
|
| 226 |
liveuser |
4081 |
|
| 3 |
liveuser |
4082 |
#函式說明:
|
|
|
4083 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
4084 |
#回傳結果:
|
|
|
4085 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4086 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
4087 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
4088 |
#$result["function"],當前執行的函式名稱.
|
|
|
4089 |
#$result["argu"],設置給予的參數.
|
|
|
4090 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4091 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4092 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4093 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4094 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4095 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4096 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4097 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4098 |
#必填參數:
|
|
|
4099 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4100 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4101 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4102 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4103 |
#可省略參數:
|
|
|
4104 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4105 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
4106 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4107 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
4108 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4109 |
#$conf["canBeEmptyString"]="false";
|
|
|
4110 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4111 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4112 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4113 |
#$conf["canBeEmpty"]=array();
|
|
|
4114 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4115 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock","cacheFilePath","checkVersionInterval");
|
|
|
4116 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4117 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","cacheFilePath","checkVersionInterval");
|
|
|
4118 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4119 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
4120 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4121 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"60");
|
|
|
4122 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4123 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4124 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4125 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4126 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
4127 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
4128 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4129 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4130 |
#參考資料:
|
|
|
4131 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4132 |
#備註:
|
|
|
4133 |
#無.
|
|
|
4134 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4135 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4136 |
|
| 3 |
liveuser |
4137 |
#如果執行失敗
|
|
|
4138 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4139 |
|
| 3 |
liveuser |
4140 |
#設置錯誤識別
|
|
|
4141 |
$result["status"]="false";
|
| 226 |
liveuser |
4142 |
|
| 3 |
liveuser |
4143 |
#設置錯誤訊息
|
|
|
4144 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4145 |
|
| 3 |
liveuser |
4146 |
#回傳結果
|
|
|
4147 |
return $result;
|
| 226 |
liveuser |
4148 |
|
| 3 |
liveuser |
4149 |
}#if end
|
| 226 |
liveuser |
4150 |
|
| 3 |
liveuser |
4151 |
#如果檢查不通過
|
|
|
4152 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4153 |
|
| 3 |
liveuser |
4154 |
#設置錯誤識別
|
|
|
4155 |
$result["status"]="false";
|
| 226 |
liveuser |
4156 |
|
| 3 |
liveuser |
4157 |
#設置錯誤訊息
|
|
|
4158 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4159 |
|
| 3 |
liveuser |
4160 |
#回傳結果
|
|
|
4161 |
return $result;
|
| 226 |
liveuser |
4162 |
|
| 3 |
liveuser |
4163 |
}#if end
|
| 226 |
liveuser |
4164 |
|
| 3 |
liveuser |
4165 |
#函式說明:
|
|
|
4166 |
#取得目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
4167 |
#回傳結果:
|
|
|
4168 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
4169 |
#$result["error"],錯誤訊息.
|
|
|
4170 |
#$result["function"],檔前執行的函數名稱.
|
|
|
4171 |
#$result["content"],目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
4172 |
#$result["serverIp"],取得伺服器ip.
|
|
|
4173 |
#$result["scheme"],取得與伺服器連線所使用的通訊協定.
|
|
|
4174 |
#必填參數:
|
|
|
4175 |
$conf["csInformation::getPathOfThisPhpFile"]["type"]="pathOnly";#想要取得的路徑類型,"full"代表完整路徑,"pathOnly"代表只要路徑,"lastLayer"代表上一層目錄的名稱
|
|
|
4176 |
#必填參數:
|
|
|
4177 |
#無.
|
|
|
4178 |
#可省略參數:
|
|
|
4179 |
#無.
|
|
|
4180 |
#參考資料:
|
|
|
4181 |
#http://blog.longwin.com.tw/2009/01/php-get-directory-file-path-dirname-2008/
|
|
|
4182 |
#備註:
|
|
|
4183 |
#無.
|
|
|
4184 |
$getPathOfThisPhpFile=csInformation::getPathOfThisPhpFile($conf["csInformation::getPathOfThisPhpFile"]);
|
|
|
4185 |
unset($conf["csInformation::getPathOfThisPhpFile"]);
|
| 226 |
liveuser |
4186 |
|
| 3 |
liveuser |
4187 |
#如果執行失敗
|
|
|
4188 |
if($getPathOfThisPhpFile["status"]=="false"){
|
| 226 |
liveuser |
4189 |
|
| 3 |
liveuser |
4190 |
#設置錯誤識別
|
|
|
4191 |
$result["status"]="false";
|
| 226 |
liveuser |
4192 |
|
| 3 |
liveuser |
4193 |
#設置錯誤訊息
|
|
|
4194 |
$result["error"]=$getPathOfThisPhpFile;
|
| 226 |
liveuser |
4195 |
|
| 3 |
liveuser |
4196 |
#回傳結果
|
|
|
4197 |
return $result;
|
| 226 |
liveuser |
4198 |
|
| 3 |
liveuser |
4199 |
}#if end
|
| 226 |
liveuser |
4200 |
|
| 3 |
liveuser |
4201 |
#如果沒有設定 sock
|
|
|
4202 |
if(!isset($conf["sock"])){
|
| 226 |
liveuser |
4203 |
|
| 3 |
liveuser |
4204 |
#設置預設的cache檔案名稱
|
|
|
4205 |
$conf["sock"]=$getPathOfThisPhpFile["content"]."var/config::client/clientCacheDaemon.sock";
|
| 226 |
liveuser |
4206 |
|
| 3 |
liveuser |
4207 |
}#if end
|
| 226 |
liveuser |
4208 |
|
| 3 |
liveuser |
4209 |
#如果 無設置 cacheFilePath
|
|
|
4210 |
if(!isset($conf["cacheFilePath"])){
|
| 226 |
liveuser |
4211 |
|
|
|
4212 |
#設置預設的 cacheFilePath
|
| 3 |
liveuser |
4213 |
$conf["cacheFilePath"]=$getPathOfThisPhpFile["content"]."var/config::client/";
|
| 226 |
liveuser |
4214 |
|
| 3 |
liveuser |
4215 |
}#if end
|
| 226 |
liveuser |
4216 |
|
| 3 |
liveuser |
4217 |
#函式說明:
|
|
|
4218 |
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
|
|
|
4219 |
#回傳結果:
|
|
|
4220 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
4221 |
#$result["error"],錯誤訊息陣列.
|
|
|
4222 |
#$result["function"],當前執行的函式名稱.
|
|
|
4223 |
#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
|
|
|
4224 |
#必填參數:
|
|
|
4225 |
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
|
|
|
4226 |
$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
|
|
|
4227 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4228 |
$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
|
|
|
4229 |
#可省略參數:
|
|
|
4230 |
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
|
|
|
4231 |
#$conf["sock::unixDomainSockServer"]["changeOwner"]="root.root";
|
|
|
4232 |
#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
|
|
|
4233 |
#$conf["sock::unixDomainSockServer"]["changePermission"]="0666";
|
|
|
4234 |
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
|
|
|
4235 |
#$conf["sessionTimeout"]="300";
|
|
|
4236 |
#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
|
|
|
4237 |
$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\\config::addOnProcessFuncForClientCacheDaemon");
|
|
|
4238 |
#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
|
|
|
4239 |
$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\\config::funcToRunWhenIdleForClientCacheDaemon");
|
|
|
4240 |
#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
|
|
|
4241 |
#$conf["paramsForFuncToRunWhenIdle"]=array();
|
|
|
4242 |
#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
4243 |
$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("sock"=>$conf["sock"],"cacheFilePath"=>$conf["cacheFilePath"],"checkVersionInterval"=>$conf["checkVersionInterval"]);
|
|
|
4244 |
#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
|
|
|
4245 |
#$conf["shutdownStrAddr"]="";
|
|
|
4246 |
#參考資料:
|
|
|
4247 |
#http://php.net/manual/en/function.stream-socket-server.php
|
|
|
4248 |
#備註:
|
|
|
4249 |
#無.
|
|
|
4250 |
$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
|
|
|
4251 |
unset($conf["sock::unixDomainSockServer"]);
|
| 226 |
liveuser |
4252 |
|
| 3 |
liveuser |
4253 |
#如果執行失敗
|
|
|
4254 |
if($unixDomainSockServer["status"]==="false"){
|
| 226 |
liveuser |
4255 |
|
| 3 |
liveuser |
4256 |
#設置錯誤識別
|
|
|
4257 |
$result["status"]="false";
|
| 226 |
liveuser |
4258 |
|
| 3 |
liveuser |
4259 |
#設置錯誤訊息
|
|
|
4260 |
$result["error"]=$unixDomainSockServer;
|
| 226 |
liveuser |
4261 |
|
| 3 |
liveuser |
4262 |
#回傳結果
|
|
|
4263 |
return $result;
|
| 226 |
liveuser |
4264 |
|
| 3 |
liveuser |
4265 |
}#if end
|
| 226 |
liveuser |
4266 |
|
| 3 |
liveuser |
4267 |
}#function clientCacheDaemon end
|
| 226 |
liveuser |
4268 |
|
| 3 |
liveuser |
4269 |
}#class config end
|
|
|
4270 |
|
| 226 |
liveuser |
4271 |
?>
|