Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 846 | Details | Compare with Previous | Last modification | View Log | RSS feed

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