Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
2 liveuser 1
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 2
    Copyright (C) 2014~2026 MIN ZHI, CHEN
2 liveuser 3
 
4
    This file is part of QBPWCF.
5
 
6
    QBPWCF is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    QBPWCF is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
18
 
19
檔案目錄結構:
20
 
123 liveuser 21
etc/qbpwcf -dir
22
存放設定檔的路徑
23
 
226 liveuser 24
usr/bin -dir
123 liveuser 25
存放可執行檔
26
 
27
/usr/lib/sysusers/php-qbpwcf.conf
28
記錄rpm包安裝時需要自動建立的使用者與群組資訊
29
 
30
usr/lib64/qbpwcf/cgi -dir
2 liveuser 31
存放 cgi 格式的腳本檔案.
32
 
123 liveuser 33
usr/lib64/qbpwcf -dir
34
存放本套件用到到函式庫
35
 
36
usr/lib64/qbpwcf/composer -dir
2 liveuser 37
用來存放 composer 工具的地方
38
 
123 liveuser 39
usr/lib64/qbpwcf/fonts -dir
2 liveuser 40
存放字體的路徑
41
 
123 liveuser 42
usr/lib64/qbpwcf/img -dir
2 liveuser 43
用來存放圖片的地方
44
 
123 liveuser 45
usr/lib64/qbpwcf/javaScript -dir
2 liveuser 46
存放用來產生javaScript給外部瀏覽器使用的目錄
47
 
123 liveuser 48
usr/lib64/qbpwcf/json -dir
2 liveuser 49
存放用來接受回應後只回傳json的頁面
50
 
123 liveuser 51
usr/lib64/qbpwcf/tcpdf -dir
52
存放 tcdpf 套件的地方
2 liveuser 53
 
123 liveuser 54
usr/lib64/qbpwcf/unserialize -dir
55
unserialize post data then output json.
2 liveuser 56
 
123 liveuser 57
usr/lib64/qbpwcf/webExtension -dir
58
存放 webExtension 的目錄
2 liveuser 59
 
123 liveuser 60
usr/lib64/qbpwcf/*.php
61
提供各種功能的php檔案
2 liveuser 62
 
123 liveuser 63
usr/lib64/qbpwcf/*-soap.php
64
提供各種soap服務的php檔案
2 liveuser 65
 
123 liveuser 66
usr/share/qbpwcf/sample/db -dir
67
存放需要使用資料庫的套件sql與寫入與讀取資料庫資料的方法.
2 liveuser 68
 
123 liveuser 69
usr/share/qbpwcf/free-lib -dir
70
存放開源的函式庫
2 liveuser 71
 
123 liveuser 72
usr/share/qbpwcf/non-free-lib -dir
73
存放不開源或不得任意散布的函式庫
2 liveuser 74
 
123 liveuser 75
usr/share/qbpwcf/sample -dir
76
提供各類別底下個別函式的執行範例
2 liveuser 77
 
123 liveuser 78
usr/share/qbpwcf/legencyTestCase -dir
79
提供各類別底下個別函式的舊的執行範例
2 liveuser 80
 
123 liveuser 81
etc/systemd/system -dir
82
存放 service 設定檔
2 liveuser 83
 
123 liveuser 84
var/qbpwcf/tmp -dir
85
暫存目錄
2 liveuser 86
 
87
gpl.txt
88
GPL條款說明
89
 
90
index.php
91
顯示 Release Note 檔案內容的頁面
92
 
93
install.php
94
安裝本套件的php腳本
95
 
96
License
97
版權宣告
98
 
99
README
100
本文件
101
 
123 liveuser 102
Release Note、Release_Note
2 liveuser 103
版本異動記錄
104
 
105
由於版權關係,因此以下檔案需自行下載與安裝:
106
 
123 liveuser 107
usr/share/qbpwcf/free_lib/bootstrap-3.3.6-dist
108
usr/share/qbpwcf/free_lib/jquery-2.2.2.min.js
109
usr/share/qbpwcf/free_lib/notify.min.js
110
usr/share/qbpwcf/free_lib/Chart.js
111
usr/share/qbpwcf/free_lib/ckeditor
112
usr/share/qbpwcf/free_lib/webrtc
113
usr/share/qbpwcf/free_lib/apache-hive
114
usr/share/qbpwcf/free_lib/lMatrix
115
usr/share/qbpwcf/non-free-lib/amchart/amcharts_3.18.6.free
116
usr/share/qbpwcf/non-free-lib/amchart/amcharts_3.19.6.free
117
usr/share/qbpwcf/non-free-lib/amchart/ammap_3.19.6.free
118
usr/share/qbpwcf/non-free-lib/amchart/amstockchart_3.19.6.free
2 liveuser 119
 
120
如何使用GPL授權
121
http://www.gnu.org/licenses/gpl-howto.html
122
 
123
命名空間的宣告與使用
124
http://oomusou.io/php/php-namespace/
125
http://php.net/manual/en/language.namespaces.importing.php
126
 
127
該套件開發規範:
128
 
129
建議函式執行遇到錯誤時要加上回傳 $result["functionName"] 代表出錯的是哪個函式
130
取得當前執行的function,可用預先定義的 __FUNCTION__ .
131
參考資料來源:
132
http://php.net/manual/en/language.constants.predefined.php
133
 
134
各函式使用參數前,應當要先檢查參數是否為陣列,這樣可以避免,參數名稱使用錯誤的問題,無法debug.尤其當該函式只有一個參數時,若無該檢查機制,將會難以deBug.
135
 
136
作為對外部類別開放存取的函式,應該要宣告為public static function fName().
137
作為僅對類別自己存取的函式,應該要宣告為private static function fName().
138
 
139
建立含有參數的函式一開始的寫法可以如下:
140
 
141
/*
142
#函式說明:
143
#...
144
#回傳結果:
145
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
146
#$result["error"],錯誤訊息陣列.
321 liveuser 147
#$result["warning"],警告訊息陣列.
2 liveuser 148
#$result["function"],當前執行的函數名稱.
219 liveuser 149
#$result["argu"],使用的參數.
2 liveuser 150
#$result["content"],主要期望的回傳內容.
151
#必填參數:
152
#$conf["key"],字串,名為"key"的參數.
153
$conf["key"]="";
154
#$conf["fileArgu"],字串,__FILE__的內容.
155
$conf["fileArgu"]=__FILE__;
156
#可省略參數:
157
#無
158
#參考資料:
159
#無.
160
#備註:
161
#無
162
*/
163
function haveArgu(&conf){
164
 
165
	#初始化要回傳的結果
166
	$result=array();
167
 
168
	#取得當前執行的函數名稱
169
	$result["function"]=__FUNCTION__;
170
 
171
	#如果沒有參數
172
	if(func_num_args()==0){
173
 
174
		#設置執行失敗
175
		$result["status"]="false";
176
 
177
		#設置執行錯誤訊息
178
		$result["error"]="函數".$result["function"]."需要參數";
179
 
180
		#回傳結果
181
		return $result;
182
 
183
		}#if end
184
 
185
	/* 請依據實際狀況使用
186
	#涵式說明:
187
	#判斷當前環境為web還是cmd
188
	#回傳結果:
189
	#$result,"web"或"cmd"
190
	if(csInformation::getEnv()==="web"){
191
 
192
		#設置執行失敗
193
		$result["status"]="false";
194
 
195
		#設置執行錯誤訊息
196
		$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
197
 
198
		#回傳結果
199
		return $result;
200
 
201
		}#if end
202
	*/
203
 
204
	#取得參數
205
	$result["argu"]=$conf;
206
 
207
	#如果 $conf 不為陣列
208
	if(gettype($conf)!=="array"){
209
 
210
		#設置執行失敗
211
		$result["status"]="false";
212
 
213
		#設置執行錯誤訊息
214
		$result["error"][]="\$conf變數須為陣列形態";
215
 
216
		#如果傳入的參數為 null
217
		if(is_null($conf)){
218
 
219
			#設置執行錯誤訊息
220
			$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
221
 
222
			}#if end
223
 
224
		#回傳結果
225
		return $result;
226
 
227
		}#if end
226 liveuser 228
 
2 liveuser 229
	}//function haveArgu end
230
 
231
建立不含有必填參數的涵式一開始的寫法可以如下:
232
 
219 liveuser 233
#函式說明:
234
#...
235
#回傳結果:
236
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
237
#$result["error"],錯誤訊息陣列.
321 liveuser 238
#$result["warning"],警告訊息陣列.
219 liveuser 239
#$result["function"],當前執行的函數名稱.
240
#$result["argu"],使用的參數.
241
#$result["content"],主要期望的回傳內容.
242
#必填參數:
243
#無.
244
#可省略參數:
245
#$conf["key"],字串,名為"key"的參數,預設為"index".
246
#$conf["key"]="index";
247
#$conf["fileArgu"],字串,__FILE__的內容,預設為__FILE__.
248
#$conf["fileArgu"]=__FILE__;
249
#參考資料:
250
#無.
251
#備註:
252
#無
2 liveuser 253
function noMustFilledArgu(&$conf){
254
 
255
	#初始化要回傳的結果
256
	$result=array();
257
 
258
	#取得當前執行的函數名稱
259
	$result["function"]=__FUNCTION__;
260
 
261
	/* 請依據實際狀況使用
262
	#涵式說明:
263
	#判斷當前環境為web還是cmd
264
	#回傳結果:
265
	#$result,"web"或"cmd"
266
	if(csInformation::getEnv()==="web"){
267
 
268
		#設置執行失敗
269
		$result["status"]="false";
270
 
271
		#設置執行錯誤訊息
272
		$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
273
 
274
		#回傳結果
275
		return $result;
276
 
277
		}#if end
278
	*/
279
 
280
	#取得參數
281
	$result["argu"]=$conf;
282
 
283
	#如果 $conf 不為陣列
284
	if(gettype($conf)!="array"){
285
 
286
		#設置執行失敗
287
		$result["status"]="false";
288
 
289
		#設置執行錯誤訊息
290
		$result["error"][]="\$conf變數須為陣列形態";
291
 
292
		#如果傳入的參數為 null
293
		if(is_null($conf)){
294
 
295
			#設置執行錯誤訊息
296
			$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
297
 
298
			}#if end
299
 
300
		#回傳結果
301
		return $result;
302
 
303
		}#if end
304
	}
305
 
306
建立不含參數的涵式一開始的寫法可以如下:
321 liveuser 307
 
308
#函式說明:
309
#...
310
#回傳結果:
311
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
312
#$result["error"],錯誤訊息陣列.
313
#$result["warning"],警告訊息陣列.
314
#$result["function"],當前執行的函數名稱.
315
#$result["argu"],使用的參數.
316
#$result["content"],主要期望的回傳內容.
317
#必填參數:
318
#無.
319
#可省略參數:
320
#無
321
#參考資料:
322
#無.
323
#備註:
324
#無
2 liveuser 325
function noArgu(){
326
 
327
	#初始化要回傳的結果
328
	$result=array();
329
 
330
	#取得當前執行的函數名稱
331
	$result["function"]=__FUNCTION__;
332
 
333
	/* 請依據實際狀況使用
334
	#涵式說明:
335
	#判斷當前環境為web還是cmd
336
	#回傳結果:
337
	#$result,"web"或"cmd"
338
	if(csInformation::getEnv()=="web"){
339
 
340
		#設置執行失敗
341
		$result["status"]="false";
342
 
343
		#設置執行錯誤訊息
344
		$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
345
 
346
		#回傳結果
347
		return $result;
348
 
349
		}#if end
350
	*/
351
 
352
	}
353
 
354
當有以下變數宣告時
355
$conf["A"]["B"]["a"]=123;
356
$conf["A"]["B"]["b"]=123;
357
$conf["A"]["B"]["c"]=123;
358
卸除$conf["A"]["B"]參數時,應卸除,$conf["A"],這樣才能卸除乾淨。
359
 
360
參數的陣列名稱,應儘量改用成$conf[a.b.c],而非$conf[a][b][c],這樣才能方便處理與應用。
361
 
362
若要撰寫要放到/usr/bin底下的執行檔可將原本的php code 用 php -r '' 包住,不用<?php ?>符號。
363
 
364
建立 usr/bin 底下的程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
365
#使用命名空間qbpwcf
366
namespace qbpwcf;
367
 
368
#取得 lib path
369
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
370
 
371
#如果執行失敗
372
if($status!==0){
373
 
374
	#debug
375
	var_dump(__LINE__,$output);
376
 
377
	#結束執行,回傳shell 1.
378
	exit(1);
379
 
380
	}#if end
381
 
382
#儲存lib path
383
$folderOfUsrLib=$output[0];
384
 
385
#以該檔案的實際位置的 lib path 為 include path 首位
386
$output=array();
387
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
388
 
389
#如果執行失敗
390
if($status!==0){
391
 
392
	#debug
393
	var_dump(__LINE__,$output);
394
 
395
	#結束執行,回傳shell 1.
396
	exit(1);
397
 
398
	}#if end
399
 
226 liveuser 400
#設置 include path
2 liveuser 401
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
402
 
403
#匯入外部套件
404
require_once("allInOne.php");
405
 
406
建立 usr/bin/libexec 底下的非 folderOfUsrLib.php 程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
407
#使用命名空間qbpwcf
408
namespace qbpwcf;
409
 
410
#取得 lib path
411
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/folderOfUsrLib.php"),$output,$status);
412
 
413
#如果執行失敗
414
if($status!==0){
415
 
416
	#debug
417
	var_dump($cmd,$ouput,$status);
418
 
419
	#結束執行,回傳shell 1.
420
	exit(1);
421
 
422
	}#if end
423
 
424
#儲存lib path
425
$folderOfUsrLib=$output[0];
426
 
427
#以該檔案的實際位置的 lib path 為 include path 首位
428
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../".$folderOfUsrLib."/qbpwcf);pwd;",$output,$status);
429
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
430
 
431
#匯入外部套件
432
require_once("allInOne.php");
433
 
434
#使用本套件的方式?若本套件是按照預設安裝,則php程式可如下開頭:
435
require_once("/usr/lib64/qbpwcf/allInOne.php");
436
 
437
#使用命名空間 qbpwcf
438
namespace qbpwcf;
439
 
440
#設定要使用的參數陣列
441
$argArray["key"]=$value;
442
 
443
#要使用的類別與函式跟參數
444
className::function($argArray);
445
 
446
#移除用好的參數
447
unset($argArray);
448
 
255 liveuser 449
#存取物件的key時,若要用變數來表示,則請勿使用 $object->$var["key"] 的方式來指定,會被誤認為 ($object->$var)["key"].
450
#可改成以下寫法:
451
 
452
#將要存取的key另存為單一變數.
453
$objectKey=$var["key"]; 
454
 
455
#用單一變數作為 $object 底下的 $key.
456
$object->$objectKey;
457
 
2 liveuser 458
參考資料:
459
 
460
以下網址為google提供的javascript整合套件,據說比JQuery更省資源
461
https://developers.google.com/speed/libraries/devguide?hl=zh-tw
462
 
463
PHP 設計模式學習手冊 (Learning PHP Design Patterns)
464
http://www.tenlong.com.tw/items/9862767707?item_id=609455
465
 
466
Dependency Manager for PHP
467
https://getcomposer.org/
468
 
469
Autoloading Standard
470
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
471
 
472
取得函數所接受到的參數數量
226 liveuser 473
http://php.net/manual/en/function.func-num-args.php