| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
|
|
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 |
跟 xml 處理的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class xml{
|
|
|
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){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
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){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函式名稱.
|
|
|
105 |
#$result["founded"],是否有抓到xml檔案,"true"代表有抓到,"false"代表沒有抓到.
|
|
|
106 |
#$result["content"],xml的物件內容.
|
|
|
107 |
#$result["argu"],所使用的參數.
|
|
|
108 |
#必填參數:
|
|
|
109 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
110 |
$conf["xmlPosition"]="";
|
|
|
111 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
112 |
$conf["fileArgu"]=__FILE__;
|
|
|
113 |
#可省略參數:
|
|
|
114 |
#無.
|
|
|
115 |
#參考資料來源:
|
|
|
116 |
#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
|
|
|
117 |
#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
|
|
|
118 |
#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
|
|
|
119 |
#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
|
|
|
120 |
#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
|
|
|
121 |
#備註:
|
|
|
122 |
#無.
|
|
|
123 |
*/
|
|
|
124 |
public static function getContent(&$conf){
|
|
|
125 |
|
|
|
126 |
#初始化要回傳的結果
|
|
|
127 |
$result=array();
|
|
|
128 |
|
|
|
129 |
#設置當其函數名稱
|
|
|
130 |
$result["function"]=__FUNCTION__;
|
|
|
131 |
|
|
|
132 |
#如果 $conf 不為陣列
|
|
|
133 |
if(gettype($conf)!="array"){
|
|
|
134 |
|
|
|
135 |
#設置執行失敗
|
|
|
136 |
$result["status"]="false";
|
|
|
137 |
|
|
|
138 |
#設置執行錯誤訊息
|
|
|
139 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
140 |
|
|
|
141 |
#如果傳入的參數為 null
|
|
|
142 |
if($conf==null){
|
|
|
143 |
|
|
|
144 |
#設置執行錯誤訊息
|
|
|
145 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
146 |
|
|
|
147 |
}#if end
|
|
|
148 |
|
|
|
149 |
#回傳結果
|
|
|
150 |
return $result;
|
|
|
151 |
|
|
|
152 |
}#if end
|
|
|
153 |
|
|
|
154 |
#取得參數
|
|
|
155 |
$result["argu"]=$conf;
|
|
|
156 |
|
|
|
157 |
#檢查參數
|
|
|
158 |
#函式說明:
|
|
|
159 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
160 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
161 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
162 |
#$result["function"],當前執行的函式名稱.
|
|
|
163 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
164 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
165 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
166 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
167 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
168 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
169 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
170 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
171 |
#必填寫的參數:
|
|
|
172 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
173 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
174 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
175 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","xmlPosition");
|
|
|
176 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
177 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
178 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
179 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
180 |
#可以省略的參數:
|
|
|
181 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
182 |
#$conf["canBeEmptyString"]="false";
|
|
|
183 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
184 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
185 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
186 |
#$conf["skipableVariableName"]=array();
|
|
|
187 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
188 |
#$conf["skipableVariableType"]=array();
|
|
|
189 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
190 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
191 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
192 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
193 |
#參考資料來源:
|
|
|
194 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
195 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
196 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
197 |
|
|
|
198 |
#如果檢查失敗
|
|
|
199 |
if($checkArguments["status"]=="false"){
|
|
|
200 |
|
|
|
201 |
#設置錯誤識別
|
|
|
202 |
$result["status"]="false";
|
|
|
203 |
|
|
|
204 |
#設置錯誤訊息
|
|
|
205 |
$result["error"]=$checkArguments;
|
|
|
206 |
|
|
|
207 |
#回傳結果
|
|
|
208 |
return $result;
|
|
|
209 |
|
|
|
210 |
}#if end
|
|
|
211 |
|
|
|
212 |
#如果檢查不通過
|
|
|
213 |
if($checkArguments["passed"]=="false"){
|
|
|
214 |
|
|
|
215 |
#設置錯誤識別
|
|
|
216 |
$result["status"]="false";
|
|
|
217 |
|
|
|
218 |
#設置錯誤訊息
|
|
|
219 |
$result["error"]=$checkArguments;
|
|
|
220 |
|
|
|
221 |
#回傳結果
|
|
|
222 |
return $result;
|
|
|
223 |
|
|
|
224 |
}#if end
|
|
|
225 |
|
|
|
226 |
#函數說明:
|
|
|
227 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
228 |
#回傳結果:
|
|
|
229 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
230 |
#$result["error"],錯誤訊息陣列.
|
|
|
231 |
#$result["function"],函數名稱.
|
|
|
232 |
#$result["argu"],使用的參數.
|
|
|
233 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
234 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
235 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
|
|
|
236 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
237 |
#必填參數:
|
|
|
238 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
239 |
$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["xmlPosition"];
|
|
|
240 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
241 |
$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
|
|
|
242 |
#可省略參數:
|
|
|
243 |
#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境.
|
|
|
244 |
$conf["fileAccess::getInternetAddressV2"]["web"]="false";
|
|
|
245 |
#備註:
|
|
|
246 |
#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
|
|
|
247 |
$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
|
|
|
248 |
unset($conf["fileAccess::getInternetAddressV2"]);
|
|
|
249 |
|
|
|
250 |
#如果轉換位置失敗
|
|
|
251 |
if($getInternetAddressV2["status"]=="false"){
|
|
|
252 |
|
|
|
253 |
#設置執行不正常
|
|
|
254 |
$result["status"]="false";
|
|
|
255 |
|
|
|
256 |
#設置執行錯誤
|
|
|
257 |
$result["error"]=$getInternetAddressV2;
|
|
|
258 |
|
|
|
259 |
#回傳結果
|
|
|
260 |
return $result;
|
|
|
261 |
|
|
|
262 |
}#if end
|
|
|
263 |
|
|
|
264 |
#取得轉換好的絕對位置
|
|
|
265 |
$conf["xmlPosition"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
|
|
|
266 |
|
|
|
267 |
#檢查xml檔案是否存在
|
|
|
268 |
#函式說明:檢查多個檔案與資料夾是否存在.
|
|
|
269 |
#回傳的結果:
|
|
|
270 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
271 |
#$result["error"],錯誤訊息陣列.
|
|
|
272 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
273 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
274 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
275 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
276 |
#必填的參數:
|
|
|
277 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["xmlPosition"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
278 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
279 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
280 |
#參考資料來源:
|
|
|
281 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
282 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
283 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
284 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
285 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
286 |
|
|
|
287 |
#如果檢查檔案是否存在失敗
|
|
|
288 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
289 |
|
|
|
290 |
#設置錯誤識別
|
|
|
291 |
$result["status"]="false";
|
|
|
292 |
|
|
|
293 |
#設置錯誤訊息
|
|
|
294 |
$result["error"]=$checkMultiFileExist;
|
|
|
295 |
|
|
|
296 |
#回傳結果
|
|
|
297 |
return $result;
|
|
|
298 |
|
|
|
299 |
}#if end
|
|
|
300 |
|
|
|
301 |
#如果xml檔案不存在
|
|
|
302 |
if($checkMultiFileExist["varExist"][0]==="false"){
|
|
|
303 |
|
|
|
304 |
#設置錯誤識別
|
|
|
305 |
$result["status"]="false";
|
|
|
306 |
|
|
|
307 |
#設置錯誤訊息
|
|
|
308 |
$result["error"][]="檔案路徑為「".$checkMultiFileExist["varName"][0]."」的xml檔案不存在!";
|
|
|
309 |
|
|
|
310 |
#設置沒有找到 xml 檔案
|
|
|
311 |
$result["founded"]="false";
|
|
|
312 |
|
|
|
313 |
#回傳結果
|
|
|
314 |
return $result;
|
|
|
315 |
|
|
|
316 |
}#if end
|
|
|
317 |
|
|
|
318 |
#啟用 xml 的錯誤處理
|
|
|
319 |
libxml_use_internal_errors(true);
|
|
|
320 |
|
|
|
321 |
#讀取目標xml檔案
|
|
|
322 |
$xml = simplexml_load_file($conf["xmlPosition"]);
|
|
|
323 |
|
|
|
324 |
#如果讀取 xml 檔案失敗
|
|
|
325 |
if($xml===false){
|
|
|
326 |
|
|
|
327 |
#設置錯誤識別
|
|
|
328 |
$result["status"]="false";
|
|
|
329 |
|
|
|
330 |
#設置錯誤訊息
|
|
|
331 |
$result["error"][]="讀取xml檔案失敗!";
|
|
|
332 |
|
|
|
333 |
#解析讀取xml所得到的每個錯誤
|
|
|
334 |
foreach (libxml_get_errors() as $error){
|
|
|
335 |
|
|
|
336 |
#取得每個錯誤訊息
|
|
|
337 |
$result["error"][]=$error;
|
|
|
338 |
|
|
|
339 |
}#foreache end
|
|
|
340 |
|
|
|
341 |
#回傳結果
|
|
|
342 |
return $result;
|
|
|
343 |
|
|
|
344 |
}#if end
|
|
|
345 |
|
|
|
346 |
#取得 xml 的內容
|
|
|
347 |
$result["content"]=$xml;
|
|
|
348 |
|
|
|
349 |
#設置有找到 xml 檔案
|
|
|
350 |
$result["founded"]="true";
|
|
|
351 |
|
|
|
352 |
#設置執行正常
|
|
|
353 |
$result["status"]="true";
|
|
|
354 |
|
|
|
355 |
#回傳抓取到的解果
|
|
|
356 |
return $result;
|
|
|
357 |
|
|
|
358 |
}#function getContent end
|
|
|
359 |
|
|
|
360 |
/*
|
|
|
361 |
#函式說明:
|
|
|
362 |
#取得xml特定標籤的內容
|
|
|
363 |
#回傳結果:
|
|
|
364 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
365 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
366 |
#$result["warning"],警告訊息陣列.
|
|
|
367 |
#$result["function"],當前執行的函式名稱.
|
|
|
368 |
#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
|
|
|
369 |
#$result["content"],xml物件的標籤內容.
|
|
|
370 |
#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
|
|
|
371 |
#必填參數:
|
|
|
372 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
373 |
$conf["xmlPosition"]="";
|
|
|
374 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
375 |
$conf["fileArgu"]=__FILE__;
|
|
|
376 |
#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
|
|
|
377 |
$conf["tag"]=array("");
|
|
|
378 |
#可省略參數:
|
|
|
379 |
#無.
|
|
|
380 |
#備註:
|
|
|
381 |
#無.
|
|
|
382 |
*/
|
|
|
383 |
static function getTagInfo(&$conf){
|
|
|
384 |
|
|
|
385 |
#初始化要回傳的結果
|
|
|
386 |
$result=array();
|
|
|
387 |
|
|
|
388 |
#取得當前執行的函數名稱
|
|
|
389 |
$result["function"]=__FUNCTION__;
|
|
|
390 |
|
|
|
391 |
#如果沒有參數
|
|
|
392 |
if(func_num_args()==0){
|
|
|
393 |
|
|
|
394 |
#設置執行失敗
|
|
|
395 |
$result["status"]="false";
|
|
|
396 |
|
|
|
397 |
#設置執行錯誤訊息
|
|
|
398 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
399 |
|
|
|
400 |
#回傳結果
|
|
|
401 |
return $result;
|
|
|
402 |
|
|
|
403 |
}#if end
|
|
|
404 |
|
|
|
405 |
#取得參數
|
|
|
406 |
$result["argu"]=$conf;
|
|
|
407 |
|
|
|
408 |
#如果 $conf 不為陣列
|
|
|
409 |
if(gettype($conf)!="array"){
|
|
|
410 |
|
|
|
411 |
#設置執行失敗
|
|
|
412 |
$result["status"]="false";
|
|
|
413 |
|
|
|
414 |
#設置執行錯誤訊息
|
|
|
415 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
416 |
|
|
|
417 |
#如果傳入的參數為 null
|
|
|
418 |
if($conf==null){
|
|
|
419 |
|
|
|
420 |
#設置執行錯誤訊息
|
|
|
421 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
422 |
|
|
|
423 |
}#if end
|
|
|
424 |
|
|
|
425 |
#回傳結果
|
|
|
426 |
return $result;
|
|
|
427 |
|
|
|
428 |
}#if end
|
|
|
429 |
|
|
|
430 |
#檢查參數
|
|
|
431 |
#函式說明:
|
|
|
432 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
433 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
434 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
435 |
#$result["function"],當前執行的函式名稱.
|
|
|
436 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
437 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
438 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
439 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
440 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
441 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
442 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
443 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
444 |
#必填寫的參數:
|
|
|
445 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
446 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
447 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
448 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlPosition","fileArgu","tag");
|
|
|
449 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
450 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
451 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
452 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
453 |
#可以省略的參數:
|
|
|
454 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
455 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
456 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
457 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
458 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
459 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","conf","commentsArray");
|
|
|
460 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
461 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array");
|
|
|
462 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
463 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"));
|
|
|
464 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
465 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
466 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
467 |
#參考資料來源:
|
|
|
468 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
469 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
470 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
471 |
|
|
|
472 |
#如果檢查參數失敗
|
|
|
473 |
if($checkArguments["status"]==="false"){
|
|
|
474 |
|
|
|
475 |
#設置執行不正常
|
|
|
476 |
$result["status"]="false";
|
|
|
477 |
|
|
|
478 |
#設置執行錯誤
|
|
|
479 |
$result["error"]=$checkArguments;
|
|
|
480 |
|
|
|
481 |
#回傳結果
|
|
|
482 |
return $result;
|
|
|
483 |
|
|
|
484 |
}#if end
|
|
|
485 |
|
|
|
486 |
#如果檢查參數不通過
|
|
|
487 |
if($checkArguments["passed"]==="false"){
|
|
|
488 |
|
|
|
489 |
#設置執行不正常
|
|
|
490 |
$result["status"]="false";
|
|
|
491 |
|
|
|
492 |
#設置執行錯誤
|
|
|
493 |
$result["error"]=$checkArguments;
|
|
|
494 |
|
|
|
495 |
#回傳結果
|
|
|
496 |
return $result;
|
|
|
497 |
|
|
|
498 |
}#if end
|
|
|
499 |
|
|
|
500 |
#過濾 $conf["tag"] 陣列元素的 「::」 字元
|
|
|
501 |
#函式說明:
|
|
|
502 |
#處理多個字串避免網頁出錯
|
|
|
503 |
#回傳的結果:
|
|
|
504 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
505 |
#$result["function"],當前執行的函數.
|
|
|
506 |
#$result["error"],錯誤訊息
|
|
|
507 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
508 |
#必填的參數:
|
|
|
509 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$conf["tag"];#爲要處理的字串陣列
|
|
|
510 |
#可省略的參數:
|
|
|
511 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("<",">","=","//","'","$","%","&","|","/*","*","#","\"",":");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
512 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
513 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
514 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
515 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
516 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
517 |
|
|
|
518 |
#如果修正標籤名稱失敗
|
|
|
519 |
if($correctMutiStrCharacter["status"]==="false"){
|
|
|
520 |
|
|
|
521 |
#設置執行不正常
|
|
|
522 |
$result["status"]="false";
|
|
|
523 |
|
|
|
524 |
#設置執行錯誤
|
|
|
525 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
526 |
|
|
|
527 |
#回傳結果
|
|
|
528 |
return $result;
|
|
|
529 |
|
|
|
530 |
}#if end
|
|
|
531 |
|
|
|
532 |
#取得修正好的tag名稱
|
|
|
533 |
$result["tag"]=$conf["tag"]=$correctMutiStrCharacter["processedStrArray"];
|
|
|
534 |
|
|
|
535 |
#函數說明:
|
|
|
536 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
537 |
#回傳結果:
|
|
|
538 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
539 |
#$result["error"],錯誤訊息陣列.
|
|
|
540 |
#$result["function"],函數名稱.
|
|
|
541 |
#$result["argu"],使用的參數.
|
|
|
542 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
543 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
544 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
|
|
|
545 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
546 |
#必填參數:
|
|
|
547 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
548 |
$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["xmlPosition"];
|
|
|
549 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
550 |
$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
|
|
|
551 |
#可省略參數:
|
|
|
552 |
#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
|
|
|
553 |
$conf["fileAccess::getInternetAddressV2"]["web"]="false";
|
|
|
554 |
#備註:
|
|
|
555 |
#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
|
|
|
556 |
$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
|
|
|
557 |
unset($conf["fileAccess::getInternetAddressV2"]);
|
|
|
558 |
|
|
|
559 |
#如果轉換位置失敗
|
|
|
560 |
if($getInternetAddressV2["status"]==="false"){
|
|
|
561 |
|
|
|
562 |
#設置執行不正常
|
|
|
563 |
$result["status"]="false";
|
|
|
564 |
|
|
|
565 |
#設置執行錯誤
|
|
|
566 |
$result["error"]=$getInternetAddressV2;
|
|
|
567 |
|
|
|
568 |
#回傳結果
|
|
|
569 |
return $result;
|
|
|
570 |
|
|
|
571 |
}#if end
|
|
|
572 |
|
|
|
573 |
#取得轉換好的絕對位置
|
|
|
574 |
$conf["xmlPosition"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
|
|
|
575 |
|
|
|
576 |
#函式說明:
|
|
|
577 |
#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
|
|
|
578 |
#回傳結果:
|
|
|
579 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
580 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
581 |
#$result["function"],當前執行的函式名稱.
|
|
|
582 |
#$result["founded"],是否有抓到xml檔案,"true"代表有抓到,"false"代表沒有抓到.
|
|
|
583 |
#$result["content"],xml的物件內容.
|
|
|
584 |
#必填參數:
|
|
|
585 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
586 |
$conf["xml::getContent"]["xmlPosition"]=$conf["xmlPosition"];
|
|
|
587 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
588 |
$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
589 |
#參考資料來源:
|
|
|
590 |
#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
|
|
|
591 |
#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
|
|
|
592 |
#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
|
|
|
593 |
#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
|
|
|
594 |
#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
|
|
|
595 |
$getContent=xml::getContent($conf["xml::getContent"]);
|
|
|
596 |
unset($conf["xml::getContent"]);
|
|
|
597 |
|
|
|
598 |
#如果取得 xml 內容失敗
|
|
|
599 |
if($getContent["status"]==="false"){
|
|
|
600 |
|
|
|
601 |
#設置執行不正常
|
|
|
602 |
$result["status"]="false";
|
|
|
603 |
|
|
|
604 |
#設置執行錯誤
|
|
|
605 |
$result["error"]=$getContent;
|
|
|
606 |
|
|
|
607 |
#回傳結果
|
|
|
608 |
return $result;
|
|
|
609 |
|
|
|
610 |
}#if end
|
|
|
611 |
|
|
|
612 |
#儲存目前所指的tag內容
|
|
|
613 |
$tagPointer="";
|
|
|
614 |
|
|
|
615 |
#針對每層 $conf["tag"]
|
|
|
616 |
foreach($conf["tag"] as $tag){
|
|
|
617 |
|
|
|
618 |
#過濾標籤
|
|
|
619 |
|
|
|
620 |
#如果 $tagPointer 為 ""
|
|
|
621 |
if($tagPointer===""){
|
|
|
622 |
|
|
|
623 |
#如果 $tag 存在
|
|
|
624 |
if(isset($getContent["content"]->$tag)){
|
|
|
625 |
|
|
|
626 |
#取得tag的pointer
|
|
|
627 |
$tagPointer=$getContent["content"]->$tag;
|
|
|
628 |
|
|
|
629 |
}#if end
|
|
|
630 |
|
|
|
631 |
#反之
|
|
|
632 |
else{
|
|
|
633 |
|
|
|
634 |
#設置執行不正常
|
|
|
635 |
$result["status"]="true";
|
|
|
636 |
|
|
|
637 |
#設置執行錯誤
|
|
|
638 |
$result["warning"][]="標籤 ".$tag." 不存在";
|
|
|
639 |
|
|
|
640 |
#設置tag不存在
|
|
|
641 |
$result["tagExist"]="false";
|
|
|
642 |
|
|
|
643 |
#回傳結果
|
|
|
644 |
return $result;
|
|
|
645 |
|
|
|
646 |
}#else end
|
|
|
647 |
|
|
|
648 |
}#if end
|
|
|
649 |
|
|
|
650 |
#如果標籤不存在
|
|
|
651 |
else if(isset($tagPointer->$tag)){
|
|
|
652 |
|
|
|
653 |
#取得tag pointer
|
|
|
654 |
$tagPointer=$tagPointer->$tag;
|
|
|
655 |
|
|
|
656 |
}#if end
|
|
|
657 |
|
|
|
658 |
#反之標籤存在
|
|
|
659 |
else{
|
|
|
660 |
|
|
|
661 |
#設置執行不正常
|
|
|
662 |
$result["status"]="true";
|
|
|
663 |
|
|
|
664 |
#設置執行錯誤
|
|
|
665 |
$result["warning"][]="標籤 ".$tag." 不存在";
|
|
|
666 |
|
|
|
667 |
#設置tag不存在
|
|
|
668 |
$result["tagExist"]="false";
|
|
|
669 |
|
|
|
670 |
#回傳結果
|
|
|
671 |
return $result;
|
|
|
672 |
|
|
|
673 |
}#else end
|
|
|
674 |
|
|
|
675 |
}#foreach end
|
|
|
676 |
|
|
|
677 |
#設置tag存在
|
|
|
678 |
$result["tagExist"]="true";
|
|
|
679 |
|
|
|
680 |
#設置tag內容
|
|
|
681 |
$result["content"]=$tagPointer;
|
|
|
682 |
|
|
|
683 |
#設置執行正常
|
|
|
684 |
$result["status"]="true";
|
|
|
685 |
|
|
|
686 |
#回傳結果
|
|
|
687 |
return $result;
|
|
|
688 |
|
|
|
689 |
}#function getTagInfo end
|
|
|
690 |
|
|
|
691 |
/*
|
|
|
692 |
#函式說明:
|
|
|
693 |
#建立空的xml檔案
|
|
|
694 |
#回傳結果:
|
|
|
695 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
696 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
697 |
#$result["function"],當前執行的函式名稱.
|
|
|
698 |
#$result["content"],xml檔案的路徑.
|
|
|
699 |
#必填參數:
|
|
|
700 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
701 |
$conf["xmlPosition"]="";
|
|
|
702 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
703 |
$conf["fileArgu"]=__FILE__;
|
|
|
704 |
#可省略參數:
|
|
|
705 |
#無.
|
|
|
706 |
#參考資料:
|
|
|
707 |
#simplexmlelement=>http://php.net/manual/en/simplexmlelement.asxml.php
|
|
|
708 |
#備註:
|
|
|
709 |
#無.
|
|
|
710 |
*/
|
|
|
711 |
static function createEmptyXml(&$conf){
|
|
|
712 |
|
|
|
713 |
#初始化要回傳的結果
|
|
|
714 |
$result=array();
|
|
|
715 |
|
|
|
716 |
#取得當前執行的函數名稱
|
|
|
717 |
$result["function"]=__FUNCTION__;
|
|
|
718 |
|
|
|
719 |
#如果沒有參數
|
|
|
720 |
if(func_num_args()==0){
|
|
|
721 |
|
|
|
722 |
#設置執行失敗
|
|
|
723 |
$result["status"]="false";
|
|
|
724 |
|
|
|
725 |
#設置執行錯誤訊息
|
|
|
726 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
727 |
|
|
|
728 |
#回傳結果
|
|
|
729 |
return $result;
|
|
|
730 |
|
|
|
731 |
}#if end
|
|
|
732 |
|
|
|
733 |
#取得參數
|
|
|
734 |
$result["argu"]=$conf;
|
|
|
735 |
|
|
|
736 |
#如果 $conf 不為陣列
|
|
|
737 |
if(gettype($conf)!="array"){
|
|
|
738 |
|
|
|
739 |
#設置執行失敗
|
|
|
740 |
$result["status"]="false";
|
|
|
741 |
|
|
|
742 |
#設置執行錯誤訊息
|
|
|
743 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
744 |
|
|
|
745 |
#如果傳入的參數為 null
|
|
|
746 |
if($conf==null){
|
|
|
747 |
|
|
|
748 |
#設置執行錯誤訊息
|
|
|
749 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
750 |
|
|
|
751 |
}#if end
|
|
|
752 |
|
|
|
753 |
#回傳結果
|
|
|
754 |
return $result;
|
|
|
755 |
|
|
|
756 |
}#if end
|
|
|
757 |
|
|
|
758 |
#檢查參數
|
|
|
759 |
#函式說明:
|
|
|
760 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
761 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
762 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
763 |
#$result["function"],當前執行的函式名稱.
|
|
|
764 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
765 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
766 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
767 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
768 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
769 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
770 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
771 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
772 |
#必填寫的參數:
|
|
|
773 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
774 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
775 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
776 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlPosition","fileArgu");
|
|
|
777 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
778 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
779 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
780 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
781 |
#可以省略的參數:
|
|
|
782 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
783 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
784 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
785 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
786 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
787 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","conf","commentsArray");
|
|
|
788 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
789 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array");
|
|
|
790 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
791 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"));
|
|
|
792 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
793 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
794 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
795 |
#參考資料來源:
|
|
|
796 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
797 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
798 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
799 |
|
|
|
800 |
#如果檢查參數失敗
|
|
|
801 |
if($checkArguments["status"]=="false"){
|
|
|
802 |
|
|
|
803 |
#設置執行不正常
|
|
|
804 |
$result["status"]="false";
|
|
|
805 |
|
|
|
806 |
#設置執行錯誤
|
|
|
807 |
$result["error"]=$checkArguments;
|
|
|
808 |
|
|
|
809 |
#回傳結果
|
|
|
810 |
return $result;
|
|
|
811 |
|
|
|
812 |
}#if end
|
|
|
813 |
|
|
|
814 |
#如果檢查參數不通過
|
|
|
815 |
if($checkArguments["passed"]=="false"){
|
|
|
816 |
|
|
|
817 |
#設置執行不正常
|
|
|
818 |
$result["status"]="false";
|
|
|
819 |
|
|
|
820 |
#設置執行錯誤
|
|
|
821 |
$result["error"]=$checkArguments;
|
|
|
822 |
|
|
|
823 |
#回傳結果
|
|
|
824 |
return $result;
|
|
|
825 |
|
|
|
826 |
}#if end
|
|
|
827 |
|
|
|
828 |
#轉換路徑為絕對路徑
|
|
|
829 |
#函數說明:
|
|
|
830 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
831 |
#回傳結果:
|
|
|
832 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
833 |
#$result["error"],錯誤訊息陣列.
|
|
|
834 |
#$result["function"],函數名稱.
|
|
|
835 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
836 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
837 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
838 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
839 |
#必填參數:
|
|
|
840 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
841 |
$conf["csInformation::getInternetAddress"]["address"]=$conf["xmlPosition"];
|
|
|
842 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
843 |
$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
844 |
#可省略參數:
|
|
|
845 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
846 |
$conf["csInformation::getInternetAddress"]["userDir"]="true";
|
|
|
847 |
#備註:
|
|
|
848 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
849 |
$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);
|
|
|
850 |
unset($conf["csInformation::getInternetAddress"]);
|
|
|
851 |
|
|
|
852 |
#如果轉換位置失敗
|
|
|
853 |
if($getInternetAddress["status"]=="false"){
|
|
|
854 |
|
|
|
855 |
#設置執行不正常
|
|
|
856 |
$result["status"]="false";
|
|
|
857 |
|
|
|
858 |
#設置執行錯誤
|
|
|
859 |
$result["error"]=$getInternetAddress;
|
|
|
860 |
|
|
|
861 |
#回傳結果
|
|
|
862 |
return $result;
|
|
|
863 |
|
|
|
864 |
}#if end
|
|
|
865 |
|
|
|
866 |
#取得轉換好的絕對位置
|
|
|
867 |
$conf["xmlPosition"]=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
868 |
|
|
|
869 |
#建立xml樣本
|
|
|
870 |
$xmlStr = <<<XML
|
|
|
871 |
<root></root>
|
|
|
872 |
XML;
|
|
|
873 |
|
|
|
874 |
#建立xml物件
|
|
|
875 |
$xml = new \SimpleXMLElement($xmlStr);
|
|
|
876 |
|
|
|
877 |
#轉換成xml字串
|
|
|
878 |
$xml=$xml->asXML();
|
|
|
879 |
|
|
|
880 |
#檢查xml檔有存在
|
|
|
881 |
#函式說明:檢查多個檔案與資料夾是否存在.
|
|
|
882 |
#回傳的結果:
|
|
|
883 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
884 |
#$result["error"],錯誤訊息陣列.
|
|
|
885 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
886 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
887 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
888 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
|
|
|
889 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
890 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
891 |
#必填參數:
|
|
|
892 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
893 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["xmlPosition"]);
|
|
|
894 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
895 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
896 |
#可省略參數
|
|
|
897 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
898 |
#$conf["disableWebSearch"]="false";
|
|
|
899 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
900 |
#$conf["userDir"]="true";
|
|
|
901 |
#參考資料來源:
|
|
|
902 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
903 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
904 |
#備註:
|
|
|
905 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
906 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
907 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
908 |
|
|
|
909 |
#如果檢查xml檔是否存在失敗
|
|
|
910 |
if($checkMultiFileExist["status"]=="false"){
|
|
|
911 |
|
|
|
912 |
#設置執行不正常
|
|
|
913 |
$result["status"]="false";
|
|
|
914 |
|
|
|
915 |
#設置執行錯誤
|
|
|
916 |
$result["error"]=$checkMultiFileExist;
|
|
|
917 |
|
|
|
918 |
#回傳結果
|
|
|
919 |
return $result;
|
|
|
920 |
|
|
|
921 |
}#if end
|
|
|
922 |
|
|
|
923 |
#如果xml檔不存在
|
|
|
924 |
if($checkMultiFileExist["allExist"]=="false"){
|
|
|
925 |
|
|
|
926 |
#建立xml檔的路徑
|
|
|
927 |
#函式說明:
|
|
|
928 |
#確保路徑存在.
|
|
|
929 |
#回傳的結果:
|
|
|
930 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
931 |
#$result["error"],錯誤訊息陣列.
|
|
|
932 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
933 |
#$result["path"],建立好的路徑字串.
|
|
|
934 |
#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
|
|
|
935 |
#必填的參數:
|
|
|
936 |
#$conf["path"],要檢查的路徑
|
|
|
937 |
$conf["fileAccess::validatePath"]["path"]=$conf["xmlPosition"];
|
|
|
938 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
939 |
$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
940 |
#可省略參數:
|
|
|
941 |
#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
|
|
|
942 |
$conf["fileAccess::validatePath"]["haveFileName"]="true";
|
|
|
943 |
#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
|
|
|
944 |
#$conf["dirPermission"]="";
|
|
|
945 |
$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
|
|
|
946 |
unset($conf["fileAccess::validatePath"]);
|
|
|
947 |
|
|
|
948 |
#如果確保xml檔路徑失敗
|
|
|
949 |
if($validatePath["status"]=="false"){
|
|
|
950 |
|
|
|
951 |
#設置執行不正常
|
|
|
952 |
$result["status"]="false";
|
|
|
953 |
|
|
|
954 |
#設置執行錯誤
|
|
|
955 |
$result["error"]=$validatePath;
|
|
|
956 |
|
|
|
957 |
#回傳結果
|
|
|
958 |
return $result;
|
|
|
959 |
|
|
|
960 |
}#if end
|
|
|
961 |
|
|
|
962 |
#建立xml檔
|
|
|
963 |
#函式說明:
|
|
|
964 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
965 |
#回傳的結果:
|
|
|
966 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
967 |
#$result["error"],錯誤訊息陣列.
|
|
|
968 |
#$result["function"],當前執行的函數名稱.
|
|
|
969 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
970 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
971 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
972 |
#必填的參數:
|
|
|
973 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
974 |
$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$conf["xmlPosition"];
|
|
|
975 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
976 |
$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
977 |
$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
|
|
|
978 |
unset($conf["fileAccess::createFileAfterCheck"]);
|
|
|
979 |
|
|
|
980 |
#如果建立xml檔案失敗
|
|
|
981 |
if($createFileAfterCheck["status"]=="false"){
|
|
|
982 |
|
|
|
983 |
#設置執行不正常
|
|
|
984 |
$result["status"]="false";
|
|
|
985 |
|
|
|
986 |
#設置執行錯誤
|
|
|
987 |
$result["error"]=$createFileAfterCheck;
|
|
|
988 |
|
|
|
989 |
#回傳結果
|
|
|
990 |
return $result;
|
|
|
991 |
|
|
|
992 |
}#if end
|
|
|
993 |
|
|
|
994 |
#取得建立好的檔案路徑與名稱
|
|
|
995 |
$conf["xmlPosition"]=$createFileAfterCheck["createdFilePathAndName"];
|
|
|
996 |
|
|
|
997 |
#寫入xml檔案
|
|
|
998 |
#函式說明:
|
|
|
999 |
#將字串寫入到檔案
|
|
|
1000 |
#回傳的結果:
|
|
|
1001 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
1002 |
#$result["error"],錯誤訊息陣列.
|
|
|
1003 |
#$result["function"],當前執行的函數名稱
|
|
|
1004 |
#必填的參數:
|
|
|
1005 |
$conf["xml::writeTextIntoFile"]["fileName"]=$conf["xmlPosition"];#爲要編輯的檔案名稱
|
|
|
1006 |
$conf["xml::writeTextIntoFile"]["inputString"]=$xml;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
1007 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1008 |
$conf["xml::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1009 |
#可省略的參數:
|
|
|
1010 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
1011 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["xml::writeTextIntoFile"]);
|
|
|
1012 |
unset($conf["xml::writeTextIntoFile"]);
|
|
|
1013 |
|
|
|
1014 |
#如果寫入xml資料到xml檔案裡面失敗
|
|
|
1015 |
if($writeTextIntoFile["status"]=="false"){
|
|
|
1016 |
|
|
|
1017 |
#設置執行不正常
|
|
|
1018 |
$result["status"]="false";
|
|
|
1019 |
|
|
|
1020 |
#設置執行錯誤
|
|
|
1021 |
$result["error"]=$createFileAfterCheck;
|
|
|
1022 |
|
|
|
1023 |
#回傳結果
|
|
|
1024 |
return $result;
|
|
|
1025 |
|
|
|
1026 |
}#if end
|
|
|
1027 |
|
|
|
1028 |
#設置執行正常
|
|
|
1029 |
$result["status"]="true";
|
|
|
1030 |
|
|
|
1031 |
#設置xml檔案的路徑
|
|
|
1032 |
$result["content"]=$conf["xmlPosition"];
|
|
|
1033 |
|
|
|
1034 |
#回傳結果
|
|
|
1035 |
return $result;
|
|
|
1036 |
|
|
|
1037 |
}#if end
|
|
|
1038 |
|
|
|
1039 |
#反之xml檔案已經存在
|
|
|
1040 |
else{
|
|
|
1041 |
|
|
|
1042 |
#設置執行失敗
|
|
|
1043 |
$result["status"]="false";
|
|
|
1044 |
|
|
|
1045 |
#設置錯誤訊息
|
|
|
1046 |
$result["error"][]="xml檔案 ".$conf["xmlPosition"]." 已經存在!";
|
|
|
1047 |
|
|
|
1048 |
#回傳結果
|
|
|
1049 |
return $result;
|
|
|
1050 |
|
|
|
1051 |
}#else end
|
|
|
1052 |
|
|
|
1053 |
}#function createEmptyXml end
|
|
|
1054 |
|
|
|
1055 |
/*
|
|
|
1056 |
#函式說明:
|
|
|
1057 |
#在目標層級新增標籤與內容
|
|
|
1058 |
#回傳結果:
|
|
|
1059 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1060 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1061 |
#$result["function"],當前執行的函式名稱.
|
|
|
1062 |
#必填參數:
|
|
|
1063 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1064 |
$conf["xmlPosition"]="";
|
|
|
1065 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1066 |
$conf["fileArgu"]=__FILE__;
|
|
|
1067 |
#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
|
|
|
1068 |
$conf["tag"]=array("");
|
|
|
1069 |
#$conf["tagValue"],字串,目標標籤的內容要放什麼.
|
|
|
1070 |
$conf["tagValue"]="";
|
|
|
1071 |
#可省略參數:
|
|
|
1072 |
#無.
|
|
|
1073 |
#參考資料:
|
|
|
1074 |
#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
|
|
|
1075 |
#備註:
|
|
|
1076 |
#物件的名稱如果是多維陣列變數,則會出錯,請改用變數儲存.
|
|
|
1077 |
*/
|
|
|
1078 |
static function addTag(&$conf){
|
|
|
1079 |
|
|
|
1080 |
#初始化要回傳的結果
|
|
|
1081 |
$result=array();
|
|
|
1082 |
|
|
|
1083 |
#取得當前執行的函數名稱
|
|
|
1084 |
$result["function"]=__FUNCTION__;
|
|
|
1085 |
|
|
|
1086 |
#如果沒有參數
|
|
|
1087 |
if(func_num_args()==0){
|
|
|
1088 |
|
|
|
1089 |
#設置執行失敗
|
|
|
1090 |
$result["status"]="false";
|
|
|
1091 |
|
|
|
1092 |
#設置執行錯誤訊息
|
|
|
1093 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1094 |
|
|
|
1095 |
#回傳結果
|
|
|
1096 |
return $result;
|
|
|
1097 |
|
|
|
1098 |
}#if end
|
|
|
1099 |
|
|
|
1100 |
#取得參數
|
|
|
1101 |
$result["argu"]=$conf;
|
|
|
1102 |
|
|
|
1103 |
#如果 $conf 不為陣列
|
|
|
1104 |
if(gettype($conf)!="array"){
|
|
|
1105 |
|
|
|
1106 |
#設置執行失敗
|
|
|
1107 |
$result["status"]="false";
|
|
|
1108 |
|
|
|
1109 |
#設置執行錯誤訊息
|
|
|
1110 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1111 |
|
|
|
1112 |
#如果傳入的參數為 null
|
|
|
1113 |
if($conf==null){
|
|
|
1114 |
|
|
|
1115 |
#設置執行錯誤訊息
|
|
|
1116 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1117 |
|
|
|
1118 |
}#if end
|
|
|
1119 |
|
|
|
1120 |
#回傳結果
|
|
|
1121 |
return $result;
|
|
|
1122 |
|
|
|
1123 |
}#if end
|
|
|
1124 |
|
|
|
1125 |
#檢查參數
|
|
|
1126 |
#函式說明:
|
|
|
1127 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1128 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1129 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1130 |
#$result["function"],當前執行的函式名稱.
|
|
|
1131 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1132 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1133 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1134 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1135 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1136 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1137 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1138 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1139 |
#必填寫的參數:
|
|
|
1140 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1141 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1142 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1143 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlPosition","fileArgu","tag");
|
|
|
1144 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1145 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
1146 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1147 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1148 |
#可以省略的參數:
|
|
|
1149 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1150 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1151 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1152 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1153 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1154 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("tagValue");
|
|
|
1155 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1156 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1157 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1158 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
1159 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1160 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1161 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1162 |
#參考資料來源:
|
|
|
1163 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1164 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1165 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1166 |
|
|
|
1167 |
#如果檢查參數失敗
|
|
|
1168 |
if($checkArguments["status"]=="false"){
|
|
|
1169 |
|
|
|
1170 |
#設置執行不正常
|
|
|
1171 |
$result["status"]="false";
|
|
|
1172 |
|
|
|
1173 |
#設置執行錯誤
|
|
|
1174 |
$result["error"]=$checkArguments;
|
|
|
1175 |
|
|
|
1176 |
#回傳結果
|
|
|
1177 |
return $result;
|
|
|
1178 |
|
|
|
1179 |
}#if end
|
|
|
1180 |
|
|
|
1181 |
#如果檢查參數不通過
|
|
|
1182 |
if($checkArguments["passed"]=="false"){
|
|
|
1183 |
|
|
|
1184 |
#設置執行不正常
|
|
|
1185 |
$result["status"]="false";
|
|
|
1186 |
|
|
|
1187 |
#設置執行錯誤
|
|
|
1188 |
$result["error"]=$checkArguments;
|
|
|
1189 |
|
|
|
1190 |
#回傳結果
|
|
|
1191 |
return $result;
|
|
|
1192 |
|
|
|
1193 |
}#if end
|
|
|
1194 |
|
|
|
1195 |
#轉換路徑為絕對路徑
|
|
|
1196 |
#函數說明:
|
|
|
1197 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
1198 |
#回傳結果:
|
|
|
1199 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
1200 |
#$result["error"],錯誤訊息陣列.
|
|
|
1201 |
#$result["function"],函數名稱.
|
|
|
1202 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
1203 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
1204 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
1205 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
1206 |
#必填參數:
|
|
|
1207 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
1208 |
$conf["csInformation::getInternetAddress"]["address"]=$conf["xmlPosition"];
|
|
|
1209 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
1210 |
$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1211 |
#可省略參數:
|
|
|
1212 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
1213 |
$conf["csInformation::getInternetAddress"]["userDir"]="true";
|
|
|
1214 |
#備註:
|
|
|
1215 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
1216 |
$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);
|
|
|
1217 |
unset($conf["csInformation::getInternetAddress"]);
|
|
|
1218 |
|
|
|
1219 |
#如果轉換位置失敗
|
|
|
1220 |
if($getInternetAddress["status"]=="false"){
|
|
|
1221 |
|
|
|
1222 |
#設置執行不正常
|
|
|
1223 |
$result["status"]="false";
|
|
|
1224 |
|
|
|
1225 |
#設置執行錯誤
|
|
|
1226 |
$result["error"]=$getInternetAddress;
|
|
|
1227 |
|
|
|
1228 |
#回傳結果
|
|
|
1229 |
return $result;
|
|
|
1230 |
|
|
|
1231 |
}#if end
|
|
|
1232 |
|
|
|
1233 |
#取得轉換好的絕對位置
|
|
|
1234 |
$conf["xmlPosition"]=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
1235 |
|
|
|
1236 |
#函式說明:
|
|
|
1237 |
#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
|
|
|
1238 |
#回傳結果:
|
|
|
1239 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1240 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1241 |
#$result["function"],當前執行的函式名稱.
|
|
|
1242 |
#$result["content"],xml的物件內容.
|
|
|
1243 |
#必填參數:
|
|
|
1244 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1245 |
$conf["xml::getContent"]["xmlPosition"]=$conf["xmlPosition"];
|
|
|
1246 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1247 |
$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1248 |
#參考資料來源:
|
|
|
1249 |
#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
|
|
|
1250 |
#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
|
|
|
1251 |
#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
|
|
|
1252 |
#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
|
|
|
1253 |
#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
|
|
|
1254 |
$getContent=xml::getContent($conf["xml::getContent"]);
|
|
|
1255 |
unset($conf["xml::getContent"]);
|
|
|
1256 |
|
|
|
1257 |
#如果取得 xml 內容失敗
|
|
|
1258 |
if($getContent["status"]=="false"){
|
|
|
1259 |
|
|
|
1260 |
#設置執行不正常
|
|
|
1261 |
$result["status"]="false";
|
|
|
1262 |
|
|
|
1263 |
#設置執行錯誤
|
|
|
1264 |
$result["error"]=$getContent;
|
|
|
1265 |
|
|
|
1266 |
#回傳結果
|
|
|
1267 |
return $result;
|
|
|
1268 |
|
|
|
1269 |
}#if end
|
|
|
1270 |
|
|
|
1271 |
#儲存xml的內容
|
|
|
1272 |
$xmlContent=$getContent["content"];
|
|
|
1273 |
|
|
|
1274 |
#過濾 $conf["tag"] 陣列元素的 「::」 字元
|
|
|
1275 |
#函式說明:
|
|
|
1276 |
#處理多個字串避免網頁出錯
|
|
|
1277 |
#回傳的結果:
|
|
|
1278 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1279 |
#$result["function"],當前執行的函數.
|
|
|
1280 |
#$result["error"],錯誤訊息
|
|
|
1281 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1282 |
#必填的參數:
|
|
|
1283 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$conf["tag"];#爲要處理的字串陣列
|
|
|
1284 |
#可省略的參數:
|
|
|
1285 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("<",">","=","//","'","$","%","&","|","/*","*","#","\"",":");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1286 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1287 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1288 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1289 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1290 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1291 |
|
|
|
1292 |
#如果修正標籤名稱失敗
|
|
|
1293 |
if($correctMutiStrCharacter["status"]==="false"){
|
|
|
1294 |
|
|
|
1295 |
#設置執行不正常
|
|
|
1296 |
$result["status"]="false";
|
|
|
1297 |
|
|
|
1298 |
#設置執行錯誤
|
|
|
1299 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
1300 |
|
|
|
1301 |
#回傳結果
|
|
|
1302 |
return $result;
|
|
|
1303 |
|
|
|
1304 |
}#if end
|
|
|
1305 |
|
|
|
1306 |
#取得修正好的tag名稱
|
|
|
1307 |
$conf["tag"]=$correctMutiStrCharacter["processedStrArray"];
|
|
|
1308 |
|
|
|
1309 |
#暫存tag pointer
|
|
|
1310 |
$tagPointer=&$xmlContent;
|
|
|
1311 |
|
|
|
1312 |
#儲存每一層用到的物件參考
|
|
|
1313 |
$thisLeyer=array(&$tagPointer);
|
|
|
1314 |
|
|
|
1315 |
#針對每層 $conf["tag"]
|
|
|
1316 |
for($i=0;$i<count($conf["tag"]);$i++){
|
|
|
1317 |
|
|
|
1318 |
#避免指標後面的陣列變數解析錯誤
|
|
|
1319 |
$tagName=$conf["tag"][$i];
|
|
|
1320 |
|
|
|
1321 |
#如果是最後一層
|
|
|
1322 |
if($i===count($conf["tag"])-1){
|
|
|
1323 |
|
|
|
1324 |
#如果這層是物件
|
|
|
1325 |
if(gettype($thisLeyer[count($thisLeyer)-1])==="object"){
|
|
|
1326 |
|
|
|
1327 |
#這層有幾個元素就執行幾次
|
|
|
1328 |
for($j=0;$j<count($thisLeyer[count($thisLeyer)-1]);$j++){
|
|
|
1329 |
|
|
|
1330 |
#如果下一層tag已經存在
|
|
|
1331 |
if(isset($thisLeyer[count($thisLeyer)-1][$j]->$tagName)){
|
|
|
1332 |
|
|
|
1333 |
#檢查其值是否跟要新增的標籤數值一樣
|
|
|
1334 |
if($conf["tagValue"]===(string)$thisLeyer[count($thisLeyer)-1][$j]->$tagName){
|
|
|
1335 |
|
|
|
1336 |
#找下一層
|
|
|
1337 |
continue;
|
|
|
1338 |
|
|
|
1339 |
}#if end
|
|
|
1340 |
|
|
|
1341 |
}#if end
|
|
|
1342 |
|
|
|
1343 |
}#for end
|
|
|
1344 |
|
|
|
1345 |
#新增標籤
|
|
|
1346 |
$thisLeyer[count($thisLeyer)-1]->addChild($tagName,$conf["tagValue"]);
|
|
|
1347 |
|
|
|
1348 |
}#if end
|
|
|
1349 |
|
|
|
1350 |
#如果下一層tag已經存在
|
|
|
1351 |
if(isset($thisLeyer[count($thisLeyer)-1]->$tagName)){
|
|
|
1352 |
|
|
|
1353 |
#檢查其值是否跟要新增的標籤數值一樣
|
|
|
1354 |
if($conf["tagValue"]===(string)$thisLeyer[count($thisLeyer)-1]->$tagName){
|
|
|
1355 |
|
|
|
1356 |
#取得該層tag
|
|
|
1357 |
$thisLeyer[]=&$thisLeyer[count($thisLeyer)-1]->$tagName;
|
|
|
1358 |
|
|
|
1359 |
#跳到下一輪
|
|
|
1360 |
continue;
|
|
|
1361 |
|
|
|
1362 |
}#if end
|
|
|
1363 |
|
|
|
1364 |
}#if end
|
|
|
1365 |
|
|
|
1366 |
#反之下一層不存在
|
|
|
1367 |
else{
|
|
|
1368 |
|
|
|
1369 |
#新增標籤
|
|
|
1370 |
$thisLeyer[count($thisLeyer)-1]->addChild($tagName,$conf["tagValue"]);
|
|
|
1371 |
|
|
|
1372 |
}#else end
|
|
|
1373 |
|
|
|
1374 |
}#if end
|
|
|
1375 |
|
|
|
1376 |
#反之不是最後一層
|
|
|
1377 |
else{
|
|
|
1378 |
|
|
|
1379 |
#如果這層是物件
|
|
|
1380 |
if(gettype($thisLeyer[count($thisLeyer)-1])==="object"){
|
|
|
1381 |
|
|
|
1382 |
#如果裡面沒有元素
|
|
|
1383 |
if(count($thisLeyer[count($thisLeyer)-1])===0){
|
|
|
1384 |
|
|
|
1385 |
#新增標籤
|
|
|
1386 |
$thisLeyer[count($thisLeyer)-1]->addChild($conf["tag"][$i]);
|
|
|
1387 |
|
|
|
1388 |
#取得該層
|
|
|
1389 |
$thisLeyer[]=&$thisLeyer[count($thisLeyer)-1]->$tagName;
|
|
|
1390 |
|
|
|
1391 |
}#if end
|
|
|
1392 |
|
|
|
1393 |
#反之裡面有元素
|
|
|
1394 |
else{
|
|
|
1395 |
|
|
|
1396 |
#這層有幾個元素就執行幾次
|
|
|
1397 |
for($j=0;$j<count($thisLeyer[count($thisLeyer)-1]);$j++){
|
|
|
1398 |
|
|
|
1399 |
#如果下一層tag已經存在
|
|
|
1400 |
if(isset($thisLeyer[count($thisLeyer)-1]->$tagName)){
|
|
|
1401 |
|
|
|
1402 |
#取得 tag & 進入下層
|
|
|
1403 |
$thisLeyer[]=&$thisLeyer[count($thisLeyer)-1]->$tagName;
|
|
|
1404 |
|
|
|
1405 |
#下一層
|
|
|
1406 |
continue 2;
|
|
|
1407 |
|
|
|
1408 |
}#if end
|
|
|
1409 |
|
|
|
1410 |
}#for end
|
|
|
1411 |
|
|
|
1412 |
#新增標籤
|
|
|
1413 |
$thisLeyer[count($thisLeyer)-1]->addChild($tagName);
|
|
|
1414 |
|
|
|
1415 |
#取得階層
|
|
|
1416 |
$thisLeyer[]=&$thisLeyer[count($thisLeyer)-1]->$tagName;
|
|
|
1417 |
|
|
|
1418 |
}#else end
|
|
|
1419 |
|
|
|
1420 |
}#if end
|
|
|
1421 |
|
|
|
1422 |
}#else end
|
|
|
1423 |
|
|
|
1424 |
}#foreach end
|
|
|
1425 |
|
|
|
1426 |
#儲存新的xml檔案內容
|
|
|
1427 |
$xmlContent=$xmlContent->asXML();
|
|
|
1428 |
|
|
|
1429 |
#覆寫xml檔案
|
|
|
1430 |
#函式說明:
|
|
|
1431 |
#將字串寫入到檔案
|
|
|
1432 |
#回傳的結果:
|
|
|
1433 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
1434 |
#$result["error"],錯誤訊息陣列.
|
|
|
1435 |
#$result["function"],當前執行的函數名稱
|
|
|
1436 |
#必填的參數:
|
|
|
1437 |
$conf["xml::writeTextIntoFile"]["fileName"]=$conf["xmlPosition"];#爲要編輯的檔案名稱
|
|
|
1438 |
$conf["xml::writeTextIntoFile"]["inputString"]=$xmlContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
1439 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1440 |
$conf["xml::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1441 |
#可省略的參數:
|
|
|
1442 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
1443 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["xml::writeTextIntoFile"]);
|
|
|
1444 |
unset($conf["xml::writeTextIntoFile"]);
|
|
|
1445 |
|
|
|
1446 |
#如果寫入xml資料到xml檔案裡面失敗
|
|
|
1447 |
if($writeTextIntoFile["status"]=="false"){
|
|
|
1448 |
|
|
|
1449 |
#設置執行不正常
|
|
|
1450 |
$result["status"]="false";
|
|
|
1451 |
|
|
|
1452 |
#設置執行錯誤
|
|
|
1453 |
$result["error"]=$writeTextIntoFile;
|
|
|
1454 |
|
|
|
1455 |
#回傳結果
|
|
|
1456 |
return $result;
|
|
|
1457 |
|
|
|
1458 |
}#if end
|
|
|
1459 |
|
|
|
1460 |
#設置執行正常
|
|
|
1461 |
$result["status"]="true";
|
|
|
1462 |
|
|
|
1463 |
#設置xml檔案的路徑
|
|
|
1464 |
$result["content"]=$conf["xmlPosition"];
|
|
|
1465 |
|
|
|
1466 |
#回傳結果
|
|
|
1467 |
return $result;
|
|
|
1468 |
|
|
|
1469 |
}#function addTag end
|
|
|
1470 |
|
|
|
1471 |
/*
|
|
|
1472 |
#函式說明:
|
|
|
1473 |
#更新xml標籤的內容.
|
|
|
1474 |
#回傳結果:
|
|
|
1475 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1476 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1477 |
#$result["function"],當前執行的函式名稱.
|
|
|
1478 |
#必填參數:
|
|
|
1479 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1480 |
$conf["xmlPosition"]="";
|
|
|
1481 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1482 |
$conf["fileArgu"]=__FILE__;
|
|
|
1483 |
#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
|
|
|
1484 |
$conf["tag"]=array("");
|
|
|
1485 |
#$conf["tagValue"],字串,目標標籤的內容要放什麼.
|
|
|
1486 |
$conf["tagValue"]="";
|
|
|
1487 |
#可省略參數:
|
|
|
1488 |
#無.
|
|
|
1489 |
#參考資料:
|
|
|
1490 |
#replacechild=>http://php.net/manual/en/domnode.replacechild.php
|
|
|
1491 |
#loadxml=>http://php.net/manual/en/domdocument.loadxml.php
|
|
|
1492 |
#update xml node value=>http://stackoverflow.com/questions/4748014/updating-xml-node-with-php
|
|
|
1493 |
#備註:
|
|
|
1494 |
#若有多個同名的tag,則只會對於第一個tag進行操作.
|
|
|
1495 |
*/
|
|
|
1496 |
static function updateTag(&$conf){
|
|
|
1497 |
|
|
|
1498 |
#初始化要回傳的結果
|
|
|
1499 |
$result=array();
|
|
|
1500 |
|
|
|
1501 |
#取得當前執行的函數名稱
|
|
|
1502 |
$result["function"]=__FUNCTION__;
|
|
|
1503 |
|
|
|
1504 |
#如果沒有參數
|
|
|
1505 |
if(func_num_args()==0){
|
|
|
1506 |
|
|
|
1507 |
#設置執行失敗
|
|
|
1508 |
$result["status"]="false";
|
|
|
1509 |
|
|
|
1510 |
#設置執行錯誤訊息
|
|
|
1511 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1512 |
|
|
|
1513 |
#回傳結果
|
|
|
1514 |
return $result;
|
|
|
1515 |
|
|
|
1516 |
}#if end
|
|
|
1517 |
|
|
|
1518 |
#取得參數
|
|
|
1519 |
$result["argu"]=$conf;
|
|
|
1520 |
|
|
|
1521 |
#如果 $conf 不為陣列
|
|
|
1522 |
if(gettype($conf)!="array"){
|
|
|
1523 |
|
|
|
1524 |
#設置執行失敗
|
|
|
1525 |
$result["status"]="false";
|
|
|
1526 |
|
|
|
1527 |
#設置執行錯誤訊息
|
|
|
1528 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1529 |
|
|
|
1530 |
#如果傳入的參數為 null
|
|
|
1531 |
if($conf==null){
|
|
|
1532 |
|
|
|
1533 |
#設置執行錯誤訊息
|
|
|
1534 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1535 |
|
|
|
1536 |
}#if end
|
|
|
1537 |
|
|
|
1538 |
#回傳結果
|
|
|
1539 |
return $result;
|
|
|
1540 |
|
|
|
1541 |
}#if end
|
|
|
1542 |
|
|
|
1543 |
#檢查參數
|
|
|
1544 |
#函式說明:
|
|
|
1545 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1546 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1547 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1548 |
#$result["function"],當前執行的函式名稱.
|
|
|
1549 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1550 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1551 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1552 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1553 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1554 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1555 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1556 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1557 |
#必填寫的參數:
|
|
|
1558 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1559 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1560 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1561 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlPosition","fileArgu","tag");
|
|
|
1562 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1563 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
1564 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1565 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1566 |
#可以省略的參數:
|
|
|
1567 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1568 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1569 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1570 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1571 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1572 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("tagValue");
|
|
|
1573 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1574 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1575 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1576 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
1577 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1578 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1579 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1580 |
#參考資料來源:
|
|
|
1581 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1582 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1583 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1584 |
|
|
|
1585 |
#如果檢查參數失敗
|
|
|
1586 |
if($checkArguments["status"]==="false"){
|
|
|
1587 |
|
|
|
1588 |
#設置執行不正常
|
|
|
1589 |
$result["status"]="false";
|
|
|
1590 |
|
|
|
1591 |
#設置執行錯誤
|
|
|
1592 |
$result["error"]=$checkArguments;
|
|
|
1593 |
|
|
|
1594 |
#回傳結果
|
|
|
1595 |
return $result;
|
|
|
1596 |
|
|
|
1597 |
}#if end
|
|
|
1598 |
|
|
|
1599 |
#如果檢查參數不通過
|
|
|
1600 |
if($checkArguments["passed"]==="false"){
|
|
|
1601 |
|
|
|
1602 |
#設置執行不正常
|
|
|
1603 |
$result["status"]="false";
|
|
|
1604 |
|
|
|
1605 |
#設置執行錯誤
|
|
|
1606 |
$result["error"]=$checkArguments;
|
|
|
1607 |
|
|
|
1608 |
#回傳結果
|
|
|
1609 |
return $result;
|
|
|
1610 |
|
|
|
1611 |
}#if end
|
|
|
1612 |
|
|
|
1613 |
#轉換路徑為絕對路徑
|
|
|
1614 |
#函數說明:
|
|
|
1615 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
1616 |
#回傳結果:
|
|
|
1617 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
1618 |
#$result["error"],錯誤訊息陣列.
|
|
|
1619 |
#$result["function"],函數名稱.
|
|
|
1620 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
1621 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
1622 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
1623 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
1624 |
#必填參數:
|
|
|
1625 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
1626 |
$conf["csInformation::getInternetAddress"]["address"]=$conf["xmlPosition"];
|
|
|
1627 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
1628 |
$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1629 |
#可省略參數:
|
|
|
1630 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
1631 |
$conf["csInformation::getInternetAddress"]["userDir"]="true";
|
|
|
1632 |
#備註:
|
|
|
1633 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
1634 |
$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);
|
|
|
1635 |
unset($conf["csInformation::getInternetAddress"]);
|
|
|
1636 |
|
|
|
1637 |
#如果轉換位置失敗
|
|
|
1638 |
if($getInternetAddress["status"]==="false"){
|
|
|
1639 |
|
|
|
1640 |
#設置執行不正常
|
|
|
1641 |
$result["status"]="false";
|
|
|
1642 |
|
|
|
1643 |
#設置執行錯誤
|
|
|
1644 |
$result["error"]=$getInternetAddress;
|
|
|
1645 |
|
|
|
1646 |
#回傳結果
|
|
|
1647 |
return $result;
|
|
|
1648 |
|
|
|
1649 |
}#if end
|
|
|
1650 |
|
|
|
1651 |
#取得轉換好的絕對位置
|
|
|
1652 |
$conf["xmlPosition"]=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
1653 |
|
|
|
1654 |
#函式說明:
|
|
|
1655 |
#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
|
|
|
1656 |
#回傳結果:
|
|
|
1657 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1658 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1659 |
#$result["function"],當前執行的函式名稱.
|
|
|
1660 |
#$result["content"],xml的物件內容.
|
|
|
1661 |
#必填參數:
|
|
|
1662 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1663 |
$conf["xml::getContent"]["xmlPosition"]=$conf["xmlPosition"];
|
|
|
1664 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1665 |
$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1666 |
#參考資料來源:
|
|
|
1667 |
#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
|
|
|
1668 |
#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
|
|
|
1669 |
#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
|
|
|
1670 |
#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
|
|
|
1671 |
#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
|
|
|
1672 |
$getContent=xml::getContent($conf["xml::getContent"]);
|
|
|
1673 |
unset($conf["xml::getContent"]);
|
|
|
1674 |
|
|
|
1675 |
#如果取得 xml 內容失敗
|
|
|
1676 |
if($getContent["status"]==="false"){
|
|
|
1677 |
|
|
|
1678 |
#設置執行不正常
|
|
|
1679 |
$result["status"]="false";
|
|
|
1680 |
|
|
|
1681 |
#設置執行錯誤
|
|
|
1682 |
$result["error"]=$getContent;
|
|
|
1683 |
|
|
|
1684 |
#回傳結果
|
|
|
1685 |
return $result;
|
|
|
1686 |
|
|
|
1687 |
}#if end
|
|
|
1688 |
|
|
|
1689 |
#儲存暫存的xml檔案內容
|
|
|
1690 |
$xmlContent=$getContent["content"];
|
|
|
1691 |
|
|
|
1692 |
#過濾 $conf["tag"] 陣列元素的 「::」 字元
|
|
|
1693 |
#函式說明:
|
|
|
1694 |
#處理多個字串避免網頁出錯
|
|
|
1695 |
#回傳的結果:
|
|
|
1696 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1697 |
#$result["function"],當前執行的函數.
|
|
|
1698 |
#$result["error"],錯誤訊息
|
|
|
1699 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1700 |
#必填的參數:
|
|
|
1701 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$conf["tag"];#爲要處理的字串陣列
|
|
|
1702 |
#可省略的參數:
|
|
|
1703 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("<",">","=","//","'","$","%","&","|","/*","*","#","\"",":");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1704 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1705 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1706 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1707 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1708 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1709 |
|
|
|
1710 |
#如果修正標籤名稱失敗
|
|
|
1711 |
if($correctMutiStrCharacter["status"]==="false"){
|
|
|
1712 |
|
|
|
1713 |
#設置執行不正常
|
|
|
1714 |
$result["status"]="false";
|
|
|
1715 |
|
|
|
1716 |
#設置執行錯誤
|
|
|
1717 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
1718 |
|
|
|
1719 |
#回傳結果
|
|
|
1720 |
return $result;
|
|
|
1721 |
|
|
|
1722 |
}#if end
|
|
|
1723 |
|
|
|
1724 |
#取得修正好的tag名稱
|
|
|
1725 |
$conf["tag"]=$correctMutiStrCharacter["processedStrArray"];
|
|
|
1726 |
|
|
|
1727 |
#針對每層 $conf["tag"]
|
|
|
1728 |
for($i=0;$i<count($conf["tag"]);$i++){
|
|
|
1729 |
|
|
|
1730 |
#如果是最後一層
|
|
|
1731 |
if($i==count($conf["tag"])-1){
|
|
|
1732 |
|
|
|
1733 |
#另存變數
|
|
|
1734 |
$key=$conf["tag"][$i];
|
|
|
1735 |
|
|
|
1736 |
#新增標籤
|
|
|
1737 |
$getContent["content"]->$key=$conf["tagValue"];
|
|
|
1738 |
|
|
|
1739 |
}#if end
|
|
|
1740 |
|
|
|
1741 |
#反之不是最後一層
|
|
|
1742 |
else{
|
|
|
1743 |
|
|
|
1744 |
#另存變數
|
|
|
1745 |
$key=$conf["tag"][$i];
|
|
|
1746 |
|
|
|
1747 |
#新增標籤
|
|
|
1748 |
$getContent["content"]=$getContent["content"]->$key;
|
|
|
1749 |
|
|
|
1750 |
}#else end
|
|
|
1751 |
|
|
|
1752 |
}#foreach end
|
|
|
1753 |
|
|
|
1754 |
#儲存新的xml檔案內容
|
|
|
1755 |
$xmlContent=$xmlContent->asXML();
|
|
|
1756 |
|
|
|
1757 |
#覆寫xml檔案
|
|
|
1758 |
#函式說明:
|
|
|
1759 |
#將字串寫入到檔案
|
|
|
1760 |
#回傳的結果:
|
|
|
1761 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
1762 |
#$result["error"],錯誤訊息陣列.
|
|
|
1763 |
#$result["function"],當前執行的函數名稱
|
|
|
1764 |
#必填的參數:
|
|
|
1765 |
$conf["xml::writeTextIntoFile"]["fileName"]=$conf["xmlPosition"];#爲要編輯的檔案名稱
|
|
|
1766 |
$conf["xml::writeTextIntoFile"]["inputString"]=$xmlContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
1767 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1768 |
$conf["xml::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1769 |
#可省略的參數:
|
|
|
1770 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
1771 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["xml::writeTextIntoFile"]);
|
|
|
1772 |
unset($conf["xml::writeTextIntoFile"]);
|
|
|
1773 |
|
|
|
1774 |
#如果寫入xml資料到xml檔案裡面失敗
|
|
|
1775 |
if($writeTextIntoFile["status"]=="false"){
|
|
|
1776 |
|
|
|
1777 |
#設置執行不正常
|
|
|
1778 |
$result["status"]="false";
|
|
|
1779 |
|
|
|
1780 |
#設置執行錯誤
|
|
|
1781 |
$result["error"]=$createFileAfterCheck;
|
|
|
1782 |
|
|
|
1783 |
#回傳結果
|
|
|
1784 |
return $result;
|
|
|
1785 |
|
|
|
1786 |
}#if end
|
|
|
1787 |
|
|
|
1788 |
#設置執行正常
|
|
|
1789 |
$result["status"]="true";
|
|
|
1790 |
|
|
|
1791 |
#設置xml檔案的路徑
|
|
|
1792 |
$result["content"]=$conf["xmlPosition"];
|
|
|
1793 |
|
|
|
1794 |
#回傳結果
|
|
|
1795 |
return $result;
|
|
|
1796 |
|
|
|
1797 |
}#function updateTag end
|
|
|
1798 |
|
|
|
1799 |
/*
|
|
|
1800 |
#函式說明:
|
|
|
1801 |
#移除xml標籤的內容.
|
|
|
1802 |
#回傳結果:
|
|
|
1803 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1804 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1805 |
#$result["function"],當前執行的函式名稱.
|
|
|
1806 |
#必填參數:
|
|
|
1807 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1808 |
$conf["xmlPosition"]="";
|
|
|
1809 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1810 |
$conf["fileArgu"]=__FILE__;
|
|
|
1811 |
#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
|
|
|
1812 |
$conf["tag"]=array("");
|
|
|
1813 |
#$conf["tagValue"],字串,目標標籤的內容要放什麼.
|
|
|
1814 |
$conf["tagValue"]="";
|
|
|
1815 |
#參考資料:
|
|
|
1816 |
#replacechild=>http://php.net/manual/en/domnode.replacechild.php
|
|
|
1817 |
#loadxml=>http://php.net/manual/en/domdocument.loadxml.php
|
|
|
1818 |
#update xml node value=>http://stackoverflow.com/questions/4748014/updating-xml-node-with-php
|
|
|
1819 |
#備註:
|
|
|
1820 |
#若有多個同名的tag,則會針對每個符合的tag進行操作.
|
|
|
1821 |
*/
|
|
|
1822 |
static function removeTag(&$conf){
|
|
|
1823 |
|
|
|
1824 |
#初始化要回傳的結果
|
|
|
1825 |
$result=array();
|
|
|
1826 |
|
|
|
1827 |
#取得當前執行的函數名稱
|
|
|
1828 |
$result["function"]=__FUNCTION__;
|
|
|
1829 |
|
|
|
1830 |
#如果沒有參數
|
|
|
1831 |
if(func_num_args()==0){
|
|
|
1832 |
|
|
|
1833 |
#設置執行失敗
|
|
|
1834 |
$result["status"]="false";
|
|
|
1835 |
|
|
|
1836 |
#設置執行錯誤訊息
|
|
|
1837 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1838 |
|
|
|
1839 |
#回傳結果
|
|
|
1840 |
return $result;
|
|
|
1841 |
|
|
|
1842 |
}#if end
|
|
|
1843 |
|
|
|
1844 |
#取得參數
|
|
|
1845 |
$result["argu"]=$conf;
|
|
|
1846 |
|
|
|
1847 |
#如果 $conf 不為陣列
|
|
|
1848 |
if(gettype($conf)!="array"){
|
|
|
1849 |
|
|
|
1850 |
#設置執行失敗
|
|
|
1851 |
$result["status"]="false";
|
|
|
1852 |
|
|
|
1853 |
#設置執行錯誤訊息
|
|
|
1854 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1855 |
|
|
|
1856 |
#如果傳入的參數為 null
|
|
|
1857 |
if($conf==null){
|
|
|
1858 |
|
|
|
1859 |
#設置執行錯誤訊息
|
|
|
1860 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1861 |
|
|
|
1862 |
}#if end
|
|
|
1863 |
|
|
|
1864 |
#回傳結果
|
|
|
1865 |
return $result;
|
|
|
1866 |
|
|
|
1867 |
}#if end
|
|
|
1868 |
|
|
|
1869 |
#檢查參數
|
|
|
1870 |
#函式說明:
|
|
|
1871 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1872 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1873 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1874 |
#$result["function"],當前執行的函式名稱.
|
|
|
1875 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1876 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1877 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1878 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1879 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1880 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1881 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1882 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1883 |
#必填寫的參數:
|
|
|
1884 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1885 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1886 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1887 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlPosition","fileArgu","tag");
|
|
|
1888 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1889 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
1890 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1891 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1892 |
#可以省略的參數:
|
|
|
1893 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1894 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1895 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1896 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1897 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1898 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("tagValue");
|
|
|
1899 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1900 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1901 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1902 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
1903 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1904 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1905 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1906 |
#參考資料來源:
|
|
|
1907 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1908 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1909 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1910 |
|
|
|
1911 |
#如果檢查參數失敗
|
|
|
1912 |
if($checkArguments["status"]=="false"){
|
|
|
1913 |
|
|
|
1914 |
#設置執行不正常
|
|
|
1915 |
$result["status"]="false";
|
|
|
1916 |
|
|
|
1917 |
#設置執行錯誤
|
|
|
1918 |
$result["error"]=$checkArguments;
|
|
|
1919 |
|
|
|
1920 |
#回傳結果
|
|
|
1921 |
return $result;
|
|
|
1922 |
|
|
|
1923 |
}#if end
|
|
|
1924 |
|
|
|
1925 |
#如果檢查參數不通過
|
|
|
1926 |
if($checkArguments["passed"]=="false"){
|
|
|
1927 |
|
|
|
1928 |
#設置執行不正常
|
|
|
1929 |
$result["status"]="false";
|
|
|
1930 |
|
|
|
1931 |
#設置執行錯誤
|
|
|
1932 |
$result["error"]=$checkArguments;
|
|
|
1933 |
|
|
|
1934 |
#回傳結果
|
|
|
1935 |
return $result;
|
|
|
1936 |
|
|
|
1937 |
}#if end
|
|
|
1938 |
|
|
|
1939 |
#轉換路徑為絕對路徑
|
|
|
1940 |
#函數說明:
|
|
|
1941 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
1942 |
#回傳結果:
|
|
|
1943 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
1944 |
#$result["error"],錯誤訊息陣列.
|
|
|
1945 |
#$result["function"],函數名稱.
|
|
|
1946 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
1947 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
1948 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
1949 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
1950 |
#必填參數:
|
|
|
1951 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
1952 |
$conf["csInformation::getInternetAddress"]["address"]=$conf["xmlPosition"];
|
|
|
1953 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
1954 |
$conf["csInformation::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1955 |
#可省略參數:
|
|
|
1956 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
1957 |
$conf["csInformation::getInternetAddress"]["userDir"]="true";
|
|
|
1958 |
#備註:
|
|
|
1959 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
1960 |
$getInternetAddress=fileAccess::getInternetAddress($conf["csInformation::getInternetAddress"]);
|
|
|
1961 |
unset($conf["csInformation::getInternetAddress"]);
|
|
|
1962 |
|
|
|
1963 |
#如果轉換位置失敗
|
|
|
1964 |
if($getInternetAddress["status"]=="false"){
|
|
|
1965 |
|
|
|
1966 |
#設置執行不正常
|
|
|
1967 |
$result["status"]="false";
|
|
|
1968 |
|
|
|
1969 |
#設置執行錯誤
|
|
|
1970 |
$result["error"]=$getInternetAddress;
|
|
|
1971 |
|
|
|
1972 |
#回傳結果
|
|
|
1973 |
return $result;
|
|
|
1974 |
|
|
|
1975 |
}#if end
|
|
|
1976 |
|
|
|
1977 |
#取得轉換好的絕對位置
|
|
|
1978 |
$conf["xmlPosition"]=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
1979 |
|
|
|
1980 |
#函式說明:
|
|
|
1981 |
#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
|
|
|
1982 |
#回傳結果:
|
|
|
1983 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1984 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1985 |
#$result["function"],當前執行的函式名稱.
|
|
|
1986 |
#$result["content"],xml的物件內容.
|
|
|
1987 |
#必填參數:
|
|
|
1988 |
#$conf["xmlPosition"],字串,xml檔案的位置.
|
|
|
1989 |
$conf["xml::getContent"]["xmlPosition"]=$conf["xmlPosition"];
|
|
|
1990 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1991 |
$conf["xml::getContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1992 |
#參考資料來源:
|
|
|
1993 |
#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
|
|
|
1994 |
#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
|
|
|
1995 |
#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
|
|
|
1996 |
#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
|
|
|
1997 |
#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
|
|
|
1998 |
$getContent=xml::getContent($conf["xml::getContent"]);
|
|
|
1999 |
unset($conf["xml::getContent"]);
|
|
|
2000 |
|
|
|
2001 |
#如果取得 xml 內容失敗
|
|
|
2002 |
if($getContent["status"]=="false"){
|
|
|
2003 |
|
|
|
2004 |
#設置執行不正常
|
|
|
2005 |
$result["status"]="false";
|
|
|
2006 |
|
|
|
2007 |
#設置執行錯誤
|
|
|
2008 |
$result["error"]=$getContent;
|
|
|
2009 |
|
|
|
2010 |
#回傳結果
|
|
|
2011 |
return $result;
|
|
|
2012 |
|
|
|
2013 |
}#if end
|
|
|
2014 |
|
|
|
2015 |
#儲存暫存的xml檔案內容
|
|
|
2016 |
$xmlContent=$getContent["content"];
|
|
|
2017 |
|
|
|
2018 |
#針對每層 $conf["tag"]
|
|
|
2019 |
for($i=0;$i<count($conf["tag"]);$i++){
|
|
|
2020 |
|
|
|
2021 |
#如果是最後一層
|
|
|
2022 |
if($i==count($conf["tag"])-1){
|
|
|
2023 |
|
|
|
2024 |
#移除標籤
|
|
|
2025 |
unset($getContent["content"]->$conf["tag"][$i]);
|
|
|
2026 |
|
|
|
2027 |
}#if end
|
|
|
2028 |
|
|
|
2029 |
#反之不是最後一層
|
|
|
2030 |
else{
|
|
|
2031 |
|
|
|
2032 |
#新增標籤
|
|
|
2033 |
$getContent["content"]=$getContent["content"]->$conf["tag"][$i];
|
|
|
2034 |
|
|
|
2035 |
}#else end
|
|
|
2036 |
|
|
|
2037 |
}#foreach end
|
|
|
2038 |
|
|
|
2039 |
#儲存新的xml檔案內容
|
|
|
2040 |
$xmlContent=$xmlContent->asXML();
|
|
|
2041 |
|
|
|
2042 |
#覆寫xml檔案
|
|
|
2043 |
#函式說明:
|
|
|
2044 |
#將字串寫入到檔案
|
|
|
2045 |
#回傳的結果:
|
|
|
2046 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
2047 |
#$result["error"],錯誤訊息陣列.
|
|
|
2048 |
#$result["function"],當前執行的函數名稱
|
|
|
2049 |
#必填的參數:
|
|
|
2050 |
$conf["xml::writeTextIntoFile"]["fileName"]=$conf["xmlPosition"];#爲要編輯的檔案名稱
|
|
|
2051 |
$conf["xml::writeTextIntoFile"]["inputString"]=$xmlContent;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
2052 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2053 |
$conf["xml::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2054 |
#可省略的參數:
|
|
|
2055 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
2056 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["xml::writeTextIntoFile"]);
|
|
|
2057 |
unset($conf["xml::writeTextIntoFile"]);
|
|
|
2058 |
|
|
|
2059 |
#如果寫入xml資料到xml檔案裡面失敗
|
|
|
2060 |
if($writeTextIntoFile["status"]=="false"){
|
|
|
2061 |
|
|
|
2062 |
#設置執行不正常
|
|
|
2063 |
$result["status"]="false";
|
|
|
2064 |
|
|
|
2065 |
#設置執行錯誤
|
|
|
2066 |
$result["error"]=$createFileAfterCheck;
|
|
|
2067 |
|
|
|
2068 |
#回傳結果
|
|
|
2069 |
return $result;
|
|
|
2070 |
|
|
|
2071 |
}#if end
|
|
|
2072 |
|
|
|
2073 |
#設置執行正常
|
|
|
2074 |
$result["status"]="true";
|
|
|
2075 |
|
|
|
2076 |
#設置xml檔案的路徑
|
|
|
2077 |
$result["content"]=$conf["xmlPosition"];
|
|
|
2078 |
|
|
|
2079 |
#回傳結果
|
|
|
2080 |
return $result;
|
|
|
2081 |
|
|
|
2082 |
}#function updateTag end
|
|
|
2083 |
|
|
|
2084 |
/*
|
|
|
2085 |
#函式說明:
|
|
|
2086 |
#解析xml字串.
|
|
|
2087 |
#回傳結果:
|
|
|
2088 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2089 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2090 |
#$result["function"],當前執行的函式名稱.
|
|
|
2091 |
#$result["content"],xml物件.
|
|
|
2092 |
#$result["xmlStr"],xml格式的內容.
|
|
|
2093 |
#必填參數:
|
|
|
2094 |
#$conf["xmlString"],字串,要解析的xml字串.
|
|
|
2095 |
#$conf["xmlString"]="";
|
|
|
2096 |
#可省略參數:
|
|
|
2097 |
#無.
|
|
|
2098 |
#參考資料:
|
|
|
2099 |
#https://www.w3schools.com/php/php_xml_simplexml_read.asp
|
|
|
2100 |
#備註:
|
|
|
2101 |
#無.
|
|
|
2102 |
*/
|
|
|
2103 |
public static function parseXMLstring(&$conf){
|
|
|
2104 |
|
|
|
2105 |
#初始化要回傳的結果
|
|
|
2106 |
$result=array();
|
|
|
2107 |
|
|
|
2108 |
#取得當前執行的函數名稱
|
|
|
2109 |
$result["function"]=__FUNCTION__;
|
|
|
2110 |
|
|
|
2111 |
#如果沒有參數
|
|
|
2112 |
if(func_num_args()==0){
|
|
|
2113 |
|
|
|
2114 |
#設置執行失敗
|
|
|
2115 |
$result["status"]="false";
|
|
|
2116 |
|
|
|
2117 |
#設置執行錯誤訊息
|
|
|
2118 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2119 |
|
|
|
2120 |
#回傳結果
|
|
|
2121 |
return $result;
|
|
|
2122 |
|
|
|
2123 |
}#if end
|
|
|
2124 |
|
|
|
2125 |
#取得參數
|
|
|
2126 |
$result["argu"]=$conf;
|
|
|
2127 |
|
|
|
2128 |
#如果 $conf 不為陣列
|
|
|
2129 |
if(gettype($conf)!="array"){
|
|
|
2130 |
|
|
|
2131 |
#設置執行失敗
|
|
|
2132 |
$result["status"]="false";
|
|
|
2133 |
|
|
|
2134 |
#設置執行錯誤訊息
|
|
|
2135 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2136 |
|
|
|
2137 |
#如果傳入的參數為 null
|
|
|
2138 |
if($conf==null){
|
|
|
2139 |
|
|
|
2140 |
#設置執行錯誤訊息
|
|
|
2141 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2142 |
|
|
|
2143 |
}#if end
|
|
|
2144 |
|
|
|
2145 |
#回傳結果
|
|
|
2146 |
return $result;
|
|
|
2147 |
|
|
|
2148 |
}#if end
|
|
|
2149 |
|
|
|
2150 |
#檢查參數
|
|
|
2151 |
#函式說明:
|
|
|
2152 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2153 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2154 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2155 |
#$result["function"],當前執行的函式名稱.
|
|
|
2156 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2157 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2158 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2159 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2160 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2161 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2162 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2163 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2164 |
#必填寫的參數:
|
|
|
2165 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2166 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2167 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2168 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("xmlString");
|
|
|
2169 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2170 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2171 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2172 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2173 |
#可以省略的參數:
|
|
|
2174 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2175 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2176 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
2177 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2178 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2179 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("tagValue");
|
|
|
2180 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2181 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2182 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2183 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
2184 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2185 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
2186 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
2187 |
#參考資料來源:
|
|
|
2188 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2189 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2190 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2191 |
|
|
|
2192 |
#如果檢查參數失敗
|
|
|
2193 |
if($checkArguments["status"]=="false"){
|
|
|
2194 |
|
|
|
2195 |
#設置執行不正常
|
|
|
2196 |
$result["status"]="false";
|
|
|
2197 |
|
|
|
2198 |
#設置執行錯誤
|
|
|
2199 |
$result["error"]=$checkArguments;
|
|
|
2200 |
|
|
|
2201 |
#回傳結果
|
|
|
2202 |
return $result;
|
|
|
2203 |
|
|
|
2204 |
}#if end
|
|
|
2205 |
|
|
|
2206 |
#如果檢查參數不通過
|
|
|
2207 |
if($checkArguments["passed"]=="false"){
|
|
|
2208 |
|
|
|
2209 |
#設置執行不正常
|
|
|
2210 |
$result["status"]="false";
|
|
|
2211 |
|
|
|
2212 |
#設置執行錯誤
|
|
|
2213 |
$result["error"]=$checkArguments;
|
|
|
2214 |
|
|
|
2215 |
#回傳結果
|
|
|
2216 |
return $result;
|
|
|
2217 |
|
|
|
2218 |
}#if end
|
|
|
2219 |
|
|
|
2220 |
#var_dump($conf["xmlString"]);exit;
|
|
|
2221 |
|
|
|
2222 |
#建立xml物件
|
|
|
2223 |
$xml=simplexml_load_string($conf["xmlString"]);
|
|
|
2224 |
|
|
|
2225 |
#設置執行正常
|
|
|
2226 |
$result["status"]="true";
|
|
|
2227 |
|
|
|
2228 |
#取得xml物件
|
|
|
2229 |
$result["content"]=$xml;
|
|
|
2230 |
|
|
|
2231 |
#取得xml格式的文字
|
|
|
2232 |
$result["xmlStr"]=$xml->asXML();
|
|
|
2233 |
|
|
|
2234 |
#回傳結果
|
|
|
2235 |
return $result;
|
|
|
2236 |
|
|
|
2237 |
}#function parseXMLstring end
|
|
|
2238 |
|
|
|
2239 |
}#class xml end
|
|
|
2240 |
|
|
|
2241 |
?>
|