QBPWCF, Quick Build PHP website Component base on Fedora Linux.
Copyright (C) 2015~2025 Min-Jhin,Chen
This file is part of QBPWCF.
QBPWCF is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QBPWCF is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
檔案目錄結構:
usr/${folderOfUsrLib}/qbpwcf/cgi -dir
存放 cgi 格式的腳本檔案.
usr/${folderOfUsrLib}/qbpwcf/composer -dir
用來存放 composer 工具的地方
usr/${folderOfUsrLib}/qbpwcf/db -dir
存放需要使用資料庫的套件sql與寫入與讀取資料庫資料的方法.
etc/qbpwcf -dir
存放設定檔的路徑
usr/${folderOfUsrLib}/qbpwcf/fonts -dir
存放字體的路徑
usr/${folderOfUsrLib}/qbpwcf/img -dir
用來存放圖片的地方
usr/${folderOfUsrLib}/qbpwcf/javaScript -dir
存放用來產生javaScript給外部瀏覽器使用的目錄
usr/${folderOfUsrLib}/qbpwcf/json -dir
存放用來接受回應後只回傳json的頁面
usr/${folderOfUsrLib}/qbpwcf -dir
存放本套件用到到函式庫
usr/${folderOfUsrLib}/qbpwcf/non-free-lib -dir
存放不開源或不得任意散布的函式庫
etc/systemd/system -dir
存放 service 設定檔
usr/${folderOfUsrLib}/qbpwcf/tcpdf -dir
存放 tcdpf 套件的地方
var/qbpwcf/tmp -dir
暫存目錄
usr/${folderOfUsrLib}/qbpwcf/unserialize -dir
unserialize post data then output json.
usr/${folderOfUsrLib}/qbpwcf/testCase -dir
爲存放舊版本測試案例的地方,預計會移除之.
usr -dir
放置 usr 目錄相關的檔案與目錄.
var -dir
存放執行中的資源,例如socket檔案、暫存檔案.
usr/${folderOfUsrLib}/qbpwcf/webExtension -dir
存放 webExtension 的目錄
usr/${folderOfUsrLib}/qbpwcf/*.php
提供各種功能的php檔案
usr/${folderOfUsrLib}/qbpwcf/*-soap.php
提供各種soap服務的php檔案
sample -dir
提供各類別底下個別函式的執行範例
gpl.txt
GPL條款說明
index.php
顯示 Release Note 檔案內容的頁面
install.php
安裝本套件的php腳本
License
版權宣告
README
本文件
Release Note
版本異動記錄
由於版權關係,因此以下檔案需自行下載與安裝:
usr/${folderOfUsrLib}/qbpwcf/lib/bootstrap-3.3.6-dist
usr/${folderOfUsrLib}/qbpwcf/lib/jquery-2.2.2.min.js
usr/${folderOfUsrLib}/qbpwcf/lib/notify.min.js
usr/${folderOfUsrLib}/qbpwcf/lib/Chart.js
usr/${folderOfUsrLib}/qbpwcf/lib/ckeditor
usr/${folderOfUsrLib}/qbpwcf/lib/webrtc
usr/${folderOfUsrLib}/qbpwcf/lib/apache-hive
usr/${folderOfUsrLib}/qbpwcf/lib/glMatrix
usr/${folderOfUsrLib}/qbpwcf/non-free-lib/amchart/amcharts_3.18.6.free
usr/${folderOfUsrLib}/qbpwcf/non-free-lib/amchart/amcharts_3.19.6.free
usr/${folderOfUsrLib}/qbpwcf/non-free-lib/amchart/ammap_3.19.6.free
usr/${folderOfUsrLib}/qbpwcf/non-free-lib/amchart/amstockchart_3.19.6.free
如何使用GPL授權
http://www.gnu.org/licenses/gpl-howto.html
命名空間的宣告與使用
http://oomusou.io/php/php-namespace/
http://php.net/manual/en/language.namespaces.importing.php
該套件開發規範:
建議函式執行遇到錯誤時要加上回傳 $result["functionName"] 代表出錯的是哪個函式
取得當前執行的function,可用預先定義的 __FUNCTION__ .
參考資料來源:
http://php.net/manual/en/language.constants.predefined.php
各函式使用參數前,應當要先檢查參數是否為陣列,這樣可以避免,參數名稱使用錯誤的問題,無法debug.尤其當該函式只有一個參數時,若無該檢查機制,將會難以deBug.
作為對外部類別開放存取的函式,應該要宣告為public static function fName().
作為僅對類別自己存取的函式,應該要宣告為private static function fName().
建立含有參數的函式一開始的寫法可以如下:
/*
#函式說明:
#...
#回傳結果:
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
#$result["error"],錯誤訊息陣列.
#$result["function"],當前執行的函數名稱.
#$result["content"],主要期望的回傳內容.
#必填參數:
#$conf["key"],字串,名為"key"的參數.
$conf["key"]="";
#$conf["fileArgu"],字串,__FILE__的內容.
$conf["fileArgu"]=__FILE__;
#可省略參數:
#無
#參考資料:
#無.
#備註:
#無
*/
function haveArgu(&conf){
#初始化要回傳的結果
$result=array();
#取得當前執行的函數名稱
$result["function"]=__FUNCTION__;
#如果沒有參數
if(func_num_args()==0){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"]="函數".$result["function"]."需要參數";
#回傳結果
return $result;
}#if end
/* 請依據實際狀況使用
#涵式說明:
#判斷當前環境為web還是cmd
#回傳結果:
#$result,"web"或"cmd"
if(csInformation::getEnv()==="web"){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
#回傳結果
return $result;
}#if end
*/
#取得參數
$result["argu"]=$conf;
#如果 $conf 不為陣列
if(gettype($conf)!=="array"){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"][]="\$conf變數須為陣列形態";
#如果傳入的參數為 null
if(is_null($conf)){
#設置執行錯誤訊息
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
}#if end
#回傳結果
return $result;
}#if end
}//function haveArgu end
建立不含有必填參數的涵式一開始的寫法可以如下:
function noMustFilledArgu(&$conf){
#初始化要回傳的結果
$result=array();
#取得當前執行的函數名稱
$result["function"]=__FUNCTION__;
/* 請依據實際狀況使用
#涵式說明:
#判斷當前環境為web還是cmd
#回傳結果:
#$result,"web"或"cmd"
if(csInformation::getEnv()==="web"){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
#回傳結果
return $result;
}#if end
*/
#取得參數
$result["argu"]=$conf;
#如果 $conf 不為陣列
if(gettype($conf)!="array"){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"][]="\$conf變數須為陣列形態";
#如果傳入的參數為 null
if(is_null($conf)){
#設置執行錯誤訊息
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
}#if end
#回傳結果
return $result;
}#if end
}
建立不含參數的涵式一開始的寫法可以如下:
function noArgu(){
#初始化要回傳的結果
$result=array();
#取得當前執行的函數名稱
$result["function"]=__FUNCTION__;
/* 請依據實際狀況使用
#涵式說明:
#判斷當前環境為web還是cmd
#回傳結果:
#$result,"web"或"cmd"
if(csInformation::getEnv()=="web"){
#設置執行失敗
$result["status"]="false";
#設置執行錯誤訊息
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
#回傳結果
return $result;
}#if end
*/
}
當有以下變數宣告時
$conf["A"]["B"]["a"]=123;
$conf["A"]["B"]["b"]=123;
$conf["A"]["B"]["c"]=123;
卸除$conf["A"]["B"]參數時,應卸除,$conf["A"],這樣才能卸除乾淨。
參數的陣列名稱,應儘量改用成$conf[a.b.c],而非$conf[a][b][c],這樣才能方便處理與應用。
若要撰寫要放到/usr/bin底下的執行檔可將原本的php code 用 php -r '' 包住,不用<?php ?>符號。
建立 usr/bin 底下的程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
#使用命名空間qbpwcf
namespace qbpwcf;
#取得 lib path
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
#如果執行失敗
if($status!==0){
#debug
var_dump(__LINE__,$output);
#結束執行,回傳shell 1.
exit(1);
}#if end
#儲存lib path
$folderOfUsrLib=$output[0];
#以該檔案的實際位置的 lib path 為 include path 首位
$output=array();
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
#如果執行失敗
if($status!==0){
#debug
var_dump(__LINE__,$output);
#結束執行,回傳shell 1.
exit(1);
}#if end
#設置 include path
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
#匯入外部套件
require_once("allInOne.php");
建立 usr/bin/libexec 底下的非 folderOfUsrLib.php 程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:
#使用命名空間qbpwcf
namespace qbpwcf;
#取得 lib path
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/folderOfUsrLib.php"),$output,$status);
#如果執行失敗
if($status!==0){
#debug
var_dump($cmd,$ouput,$status);
#結束執行,回傳shell 1.
exit(1);
}#if end
#儲存lib path
$folderOfUsrLib=$output[0];
#以該檔案的實際位置的 lib path 為 include path 首位
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../".$folderOfUsrLib."/qbpwcf);pwd;",$output,$status);
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
#匯入外部套件
require_once("allInOne.php");
#使用本套件的方式?若本套件是按照預設安裝,則php程式可如下開頭:
require_once("/usr/lib64/qbpwcf/allInOne.php");
#使用命名空間 qbpwcf
namespace qbpwcf;
#設定要使用的參數陣列
$argArray["key"]=$value;
#要使用的類別與函式跟參數
className::function($argArray);
#移除用好的參數
unset($argArray);
參考資料:
以下網址為google提供的javascript整合套件,據說比JQuery更省資源
https://developers.google.com/speed/libraries/devguide?hl=zh-tw
PHP 設計模式學習手冊 (Learning PHP Design Patterns)
http://www.tenlong.com.tw/items/9862767707?item_id=609455
Dependency Manager for PHP
https://getcomposer.org/
Autoloading Standard
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
取得函數所接受到的參數數量
http://php.net/manual/en/function.func-num-args.php