Subversion Repositories php-qbpwcf

Rev

Rev 39 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
39 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
226 liveuser 6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
39 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/>.
226 liveuser 22
 
39 liveuser 23
*/
24
 
25
#指派命名空間
26
namespace qbpwcf;
27
 
28
#取得 lib path
29
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
30
 
31
#如果執行失敗
32
if($status!==0){
33
 
34
	#debug
35
	var_dump(__LINE__,$output);
36
 
37
	#結束執行,回傳shell 1.
38
	exit(1);
39
 
40
	}#if end
41
 
42
#儲存lib path
43
$folderOfUsrLib=$output[0];
44
 
45
#以該檔案的實際位置的 lib path 為 include path 首位
46
$output=array();
47
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
48
 
49
#如果執行失敗
50
if($status!==0){
51
 
52
	#debug
53
	var_dump(__LINE__,$output);
54
 
55
	#結束執行,回傳shell 1.
56
	exit(1);
57
 
58
	}#if end
59
 
226 liveuser 60
#設置 include path
39 liveuser 61
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
62
 
63
#匯入外部套件
64
include("allInOne.php");
65
 
66
#說明函式
67
function help(){
68
 
69
	#印出指令說明
226 liveuser 70
	echo "Usage of ".basename(__FILE__).":".PHP_EOL;
39 liveuser 71
	echo "--input [utf7 imap string to decode] 代表要解碼的 uft7 imap 字串".PHP_EOL;
226 liveuser 72
 
39 liveuser 73
	#結束執行
74
	exit;
75
 
76
	}#function help end
77
 
78
#函式說明:
79
#解析參數.
80
#回傳結果:
81
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
82
#$reuslt["error"],執行不正常結束的錯訊息陣列.
83
#$result["function"],當前執行的函式名稱.
84
#$result["content"],解析好的參數陣列.
85
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
86
#$result["program"],字串,執行的程式名稱.
87
#必填參數:
88
#無
89
#可省略參數:
90
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
91
$conf["helpFunc"]="help";
92
#備註:
93
#僅能在命令列底下執行.
94
#建議:
95
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
96
$parseArgu=cmd::parseArgu($conf);
97
unset($conf);
98
 
99
#如果解析參數失敗
100
if($parseArgu["status"]==="false"){
101
 
102
	#印出結果
103
	var_dump($parseArgu);
226 liveuser 104
 
39 liveuser 105
	#結束執行,回傳shell 1,代表異常.
106
	exit(1);
226 liveuser 107
 
39 liveuser 108
	}#if end
109
 
110
#檢查參數
111
#函式說明:
112
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
113
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
114
#$reuslt["error"],執行不正常結束的錯訊息陣列.
115
#$result["function"],當前執行的函式名稱.
116
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
117
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
118
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
119
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
120
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
121
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
122
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
123
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
124
#必填寫的參數:
125
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
126
$conf["varInput"]=&$parseArgu["content"];
127
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
128
$conf["referenceVarKey"]="variableCheck::checkArguments";
129
#可以省略的參數:
130
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
131
$conf["mustBeFilledVariableName"]=array("input");
132
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
133
$conf["mustBeFilledVariableType"]=array("array");
134
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
135
#$conf["canBeEmptyString"]="false";
136
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
137
#$conf["canNotBeEmpty"]=array();
138
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
139
#$conf["canBeEmpty"]=array();
140
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
141
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
142
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
143
#$conf["skipableVariableName"]=array("input");
144
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
145
#$conf["skipableVariableType"]=array("array");
146
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
147
#$conf["skipableVarDefaultValue"]=array(null);
148
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
149
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
150
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
151
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
152
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
153
#$conf["arrayCountEqualCheck"][]=array();
154
#參考資料來源:
155
#array_keys=>http://php.net/manual/en/function.array-keys.php
156
$checkArguments=variableCheck::checkArguments($conf);
157
unset($conf);
158
 
159
#若執行失敗
160
if($checkArguments["status"]==="false"){
161
 
162
	#印出結果
163
	var_dump($checkArguments);
226 liveuser 164
 
39 liveuser 165
	#結束執行,回傳shell 1,代表異常.
166
	exit(1);
167
 
168
	}#if end
169
 
170
#若檢查不通過
171
if($checkArguments["passed"]==="false"){
172
 
173
	#提示用法
174
	help();
226 liveuser 175
 
39 liveuser 176
	#結束執行
177
	exit;
178
 
179
	}#if end
180
 
181
#函式說明:
182
#將mutf7的字串轉成uft8
183
#回傳結果:
184
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
185
#$result["error"],錯誤訊息陣列.
186
#$result["function"],當前執行的函數名稱.
187
#$result["content"],轉好的字串.
188
#必填參數:
189
#$conf["stringIn"],字串,要處理的字串.
190
$conf["stringIn"]=$parseArgu["content"]["input"][0];
191
#可省略參數:
192
#無.
193
#參考資料:
194
#https://www.php.net/manual/en/function.mb-convert-encoding.php
195
#https://www.php.net/manual/en/mbstring.supported-encodings.php
196
#備註:
197
#無.
198
$utf7_imap_to_utf8=stringProcess::utf7_imap_to_utf8($conf);
199
unset($conf);
200
 
201
#若執行失敗
202
if($utf7_imap_to_utf8["status"]==="false"){
203
 
204
	#印出結果
205
	var_dump($utf7_imap_to_utf8);
226 liveuser 206
 
39 liveuser 207
	#結束執行,回傳shell 1,代表異常.
208
	exit(1);
209
 
210
	}#if end
226 liveuser 211
 
39 liveuser 212
#印出解好的內容
226 liveuser 213
echo $utf7_imap_to_utf8["content"];