| 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 |
應用qrCode的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class qrCode{
|
|
|
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 |
#貼上可以設定網址的qrCode
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#$result["content"],qrCode圖片語法.
|
|
|
106 |
#必填的參數:
|
|
|
107 |
#conf["webAddress"],字串,不須輸入 http://
|
|
|
108 |
$conf["webAddress"]="";
|
|
|
109 |
*/
|
|
|
110 |
function show($conf){
|
|
|
111 |
|
|
|
112 |
#初始化要回傳的結果
|
|
|
113 |
$result=array();
|
|
|
114 |
|
|
|
115 |
#儲存當前執行的函數
|
|
|
116 |
$result["function"]=__FUNCTION__;
|
|
|
117 |
|
|
|
118 |
#如果 $conf 不為陣列
|
|
|
119 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
120 |
|
| 3 |
liveuser |
121 |
#設置執行失敗
|
|
|
122 |
$result["status"]="false";
|
| 226 |
liveuser |
123 |
|
| 3 |
liveuser |
124 |
#設置執行錯誤訊息
|
|
|
125 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
126 |
|
|
|
127 |
#如果傳入的參數為 null
|
|
|
128 |
if($conf==null){
|
| 226 |
liveuser |
129 |
|
| 3 |
liveuser |
130 |
#設置執行錯誤訊息
|
|
|
131 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
132 |
|
| 3 |
liveuser |
133 |
}#if end
|
|
|
134 |
|
|
|
135 |
#回傳結果
|
|
|
136 |
return $result;
|
| 226 |
liveuser |
137 |
|
| 3 |
liveuser |
138 |
}#if end
|
| 226 |
liveuser |
139 |
|
| 3 |
liveuser |
140 |
#檢查參數
|
|
|
141 |
#函式說明:
|
|
|
142 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
143 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
144 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
145 |
#$result["function"],當前執行的函式名稱.
|
|
|
146 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
147 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
148 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
149 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
150 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
151 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
152 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
153 |
#必填寫的參數:
|
|
|
154 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
155 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
156 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
157 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("webAddress");
|
| 226 |
liveuser |
158 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
159 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
160 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
161 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
162 |
#可以省略的參數:
|
|
|
163 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
164 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
165 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
166 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("customSettings");
|
| 226 |
liveuser |
167 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
168 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
|
|
|
169 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
170 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
171 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
172 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
173 |
#參考資料來源:
|
|
|
174 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
175 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
176 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
177 |
|
| 3 |
liveuser |
178 |
#如果檢查失敗
|
|
|
179 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
180 |
|
| 3 |
liveuser |
181 |
#設置錯誤識別
|
|
|
182 |
$result["status"]="false";
|
| 226 |
liveuser |
183 |
|
| 3 |
liveuser |
184 |
#設置錯誤訊息
|
|
|
185 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
186 |
|
| 3 |
liveuser |
187 |
#回傳結果
|
|
|
188 |
return $result;
|
| 226 |
liveuser |
189 |
|
| 3 |
liveuser |
190 |
}#if end
|
| 226 |
liveuser |
191 |
|
| 3 |
liveuser |
192 |
#如果檢查不通過
|
|
|
193 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
194 |
|
| 3 |
liveuser |
195 |
#設置錯誤識別
|
|
|
196 |
$result["status"]="false";
|
| 226 |
liveuser |
197 |
|
| 3 |
liveuser |
198 |
#設置錯誤訊息
|
|
|
199 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
200 |
|
| 3 |
liveuser |
201 |
#回傳結果
|
|
|
202 |
return $result;
|
| 226 |
liveuser |
203 |
|
| 3 |
liveuser |
204 |
}#if end
|
|
|
205 |
|
|
|
206 |
#放置qrCode圖片的網址
|
|
|
207 |
$result["content"]="<img src=\"http://qrcode.kaywa.com/img.php?s=8&d=http%3A%2F%2F".$conf["webAddress"]."\" alt=\"qrcode\" />";
|
| 226 |
liveuser |
208 |
|
| 3 |
liveuser |
209 |
#設置執行正常
|
|
|
210 |
$result["status"]="true";
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
#回傳結果
|
|
|
213 |
return $result;
|
| 226 |
liveuser |
214 |
|
| 3 |
liveuser |
215 |
}#function show end
|
|
|
216 |
|
|
|
217 |
}#class qrCode end
|
| 226 |
liveuser |
218 |
|
| 3 |
liveuser |
219 |
?>
|