Subversion Repositories php-qbpwcf

Rev

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