Subversion Repositories php-qbpwcf

Rev

Rev 123 | Rev 226 | 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.
2
    Copyright (C) 2015~2025 Min-Jhin,Chen
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
 
24
usr/bin -dir 
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"],錯誤訊息陣列.
147
#$result["function"],當前執行的函數名稱.
219 liveuser 148
#$result["argu"],使用的參數.
2 liveuser 149
#$result["content"],主要期望的回傳內容.
150
#必填參數:
151
#$conf["key"],字串,名為"key"的參數.
152
$conf["key"]="";
153
#$conf["fileArgu"],字串,__FILE__的內容.
154
$conf["fileArgu"]=__FILE__;
155
#可省略參數:
156
#無
157
#參考資料:
158
#無.
159
#備註:
160
#無
161
*/
162
function haveArgu(&conf){
163
 
164
	#初始化要回傳的結果
165
	$result=array();
166
 
167
	#取得當前執行的函數名稱
168
	$result["function"]=__FUNCTION__;
169
 
170
	#如果沒有參數
171
	if(func_num_args()==0){
172
 
173
		#設置執行失敗
174
		$result["status"]="false";
175
 
176
		#設置執行錯誤訊息
177
		$result["error"]="函數".$result["function"]."需要參數";
178
 
179
		#回傳結果
180
		return $result;
181
 
182
		}#if end
183
 
184
	/* 請依據實際狀況使用
185
	#涵式說明:
186
	#判斷當前環境為web還是cmd
187
	#回傳結果:
188
	#$result,"web"或"cmd"
189
	if(csInformation::getEnv()==="web"){
190
 
191
		#設置執行失敗
192
		$result["status"]="false";
193
 
194
		#設置執行錯誤訊息
195
		$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
196
 
197
		#回傳結果
198
		return $result;
199
 
200
		}#if end
201
	*/
202
 
203
	#取得參數
204
	$result["argu"]=$conf;
205
 
206
	#如果 $conf 不為陣列
207
	if(gettype($conf)!=="array"){
208
 
209
		#設置執行失敗
210
		$result["status"]="false";
211
 
212
		#設置執行錯誤訊息
213
		$result["error"][]="\$conf變數須為陣列形態";
214
 
215
		#如果傳入的參數為 null
216
		if(is_null($conf)){
217
 
218
			#設置執行錯誤訊息
219
			$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
220
 
221
			}#if end
222
 
223
		#回傳結果
224
		return $result;
225
 
226
		}#if end
47 liveuser 227
 
2 liveuser 228
	}//function haveArgu end
229
 
230
建立不含有必填參數的涵式一開始的寫法可以如下:
231
 
219 liveuser 232
/*
233
#函式說明:
234
#...
235
#回傳結果:
236
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
237
#$result["error"],錯誤訊息陣列.
238
#$result["function"],當前執行的函數名稱.
239
#$result["argu"],使用的參數.
240
#$result["content"],主要期望的回傳內容.
241
#必填參數:
242
#無.
243
#可省略參數:
244
#$conf["key"],字串,名為"key"的參數,預設為"index".
245
#$conf["key"]="index";
246
#$conf["fileArgu"],字串,__FILE__的內容,預設為__FILE__.
247
#$conf["fileArgu"]=__FILE__;
248
#參考資料:
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
建立不含參數的涵式一開始的寫法可以如下:
307
function noArgu(){
308
 
309
	#初始化要回傳的結果
310
	$result=array();
311
 
312
	#取得當前執行的函數名稱
313
	$result["function"]=__FUNCTION__;
314
 
315
	/* 請依據實際狀況使用
316
	#涵式說明:
317
	#判斷當前環境為web還是cmd
318
	#回傳結果:
319
	#$result,"web"或"cmd"
320
	if(csInformation::getEnv()=="web"){
321
 
322
		#設置執行失敗
323
		$result["status"]="false";
324
 
325
		#設置執行錯誤訊息
326
		$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
327
 
328
		#回傳結果
329
		return $result;
330
 
331
		}#if end
332
	*/
333
 
334
	}
335
 
336
當有以下變數宣告時
337
$conf["A"]["B"]["a"]=123;
338
$conf["A"]["B"]["b"]=123;
339
$conf["A"]["B"]["c"]=123;
340
卸除$conf["A"]["B"]參數時,應卸除,$conf["A"],這樣才能卸除乾淨。
341
 
342
參數的陣列名稱,應儘量改用成$conf[a.b.c],而非$conf[a][b][c],這樣才能方便處理與應用。
343
 
344
若要撰寫要放到/usr/bin底下的執行檔可將原本的php code 用 php -r '' 包住,不用<?php ?>符號。
345
 
346
建立 usr/bin 底下的程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
347
#使用命名空間qbpwcf
348
namespace qbpwcf;
349
 
350
#取得 lib path
351
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
352
 
353
#如果執行失敗
354
if($status!==0){
355
 
356
	#debug
357
	var_dump(__LINE__,$output);
358
 
359
	#結束執行,回傳shell 1.
360
	exit(1);
361
 
362
	}#if end
363
 
364
#儲存lib path
365
$folderOfUsrLib=$output[0];
366
 
367
#以該檔案的實際位置的 lib path 為 include path 首位
368
$output=array();
369
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$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
#設置 include path 
383
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
384
 
385
#匯入外部套件
386
require_once("allInOne.php");
387
 
388
建立 usr/bin/libexec 底下的非 folderOfUsrLib.php 程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
389
#使用命名空間qbpwcf
390
namespace qbpwcf;
391
 
392
#取得 lib path
393
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/folderOfUsrLib.php"),$output,$status);
394
 
395
#如果執行失敗
396
if($status!==0){
397
 
398
	#debug
399
	var_dump($cmd,$ouput,$status);
400
 
401
	#結束執行,回傳shell 1.
402
	exit(1);
403
 
404
	}#if end
405
 
406
#儲存lib path
407
$folderOfUsrLib=$output[0];
408
 
409
#以該檔案的實際位置的 lib path 為 include path 首位
410
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../".$folderOfUsrLib."/qbpwcf);pwd;",$output,$status);
411
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
412
 
413
#匯入外部套件
414
require_once("allInOne.php");
415
 
416
#使用本套件的方式?若本套件是按照預設安裝,則php程式可如下開頭:
417
require_once("/usr/lib64/qbpwcf/allInOne.php");
418
 
419
#使用命名空間 qbpwcf
420
namespace qbpwcf;
421
 
422
#設定要使用的參數陣列
423
$argArray["key"]=$value;
424
 
425
#要使用的類別與函式跟參數
426
className::function($argArray);
427
 
428
#移除用好的參數
429
unset($argArray);
430
 
431
參考資料:
432
 
433
以下網址為google提供的javascript整合套件,據說比JQuery更省資源
434
https://developers.google.com/speed/libraries/devguide?hl=zh-tw
435
 
436
PHP 設計模式學習手冊 (Learning PHP Design Patterns)
437
http://www.tenlong.com.tw/items/9862767707?item_id=609455
438
 
439
Dependency Manager for PHP
440
https://getcomposer.org/
441
 
442
Autoloading Standard
443
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
444
 
445
取得函數所接受到的參數數量
446
http://php.net/manual/en/function.func-num-args.php