Subversion Repositories qbpwcf-lib(archive)

Rev

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

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