Subversion Repositories php-qbpwcf

Rev

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