| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 223 |
liveuser |
6 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 1 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
#使用命名空間qbpwcf
|
|
|
26 |
namespace qbpwcf;
|
|
|
27 |
|
|
|
28 |
#初始化輸出
|
|
|
29 |
$output=array();
|
|
|
30 |
|
|
|
31 |
#取得 lib path
|
| 96 |
liveuser |
32 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
|
| 1 |
liveuser |
33 |
|
|
|
34 |
#如果執行失敗
|
|
|
35 |
if($status!==0){
|
|
|
36 |
|
|
|
37 |
#debug
|
|
|
38 |
var_dump(__LINE__,$output);
|
|
|
39 |
|
|
|
40 |
#結束執行,回傳shell 1.
|
|
|
41 |
exit(1);
|
|
|
42 |
|
|
|
43 |
}#if end
|
|
|
44 |
|
|
|
45 |
#儲存lib path
|
|
|
46 |
$folderOfUsrLib=$output[0];
|
|
|
47 |
|
|
|
48 |
#初始化輸出
|
|
|
49 |
$output=array();
|
|
|
50 |
|
|
|
51 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
| 96 |
liveuser |
52 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
|
| 1 |
liveuser |
53 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
54 |
|
|
|
55 |
#匯入套件
|
|
|
56 |
require_once("allInOne.php");
|
|
|
57 |
|
|
|
58 |
$var=(array)(json_decode('{"gw_primary_ids": [], "power_on": "0111E", "power_off": "10600"}'));
|
|
|
59 |
#$var="[0100]";
|
|
|
60 |
#$var=array("0100");
|
|
|
61 |
|
|
|
62 |
#函式說明:
|
|
|
63 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
64 |
#回傳結果:
|
|
|
65 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
66 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
67 |
#$result["function"],當前執行的函式名稱.
|
|
|
68 |
#$result["argu"],設置給予的參數.
|
|
|
69 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
70 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
71 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
72 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
73 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
74 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
75 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
76 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
79 |
$conf["variableCheck::checkArguments"]["varInput"]=&$var;
|
|
|
80 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
81 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
82 |
#可省略參數:
|
|
|
83 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
84 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("gw_primary_id");
|
|
|
85 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
86 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
87 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
88 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
89 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
90 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("gw_primary_ids");
|
|
|
91 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
92 |
#$conf["canBeEmpty"]=array();
|
|
|
93 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
94 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
95 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
96 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("schedule","nodes");
|
|
|
97 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
98 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
99 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
100 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
101 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
102 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
103 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
104 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
105 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
106 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
107 |
#參考資料:
|
|
|
108 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
109 |
#備註:
|
|
|
110 |
#無.
|
|
|
111 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
112 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
113 |
|
|
|
114 |
#debug
|
|
|
115 |
var_dump($checkArguments);
|
|
|
116 |
|
|
|
117 |
?>
|