Rev 239 | Blame | Compare with Previous | Last modification | View Log | RSS feed
QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2026 MIN ZHI, CHENThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.檔案目錄結構:etc/qbpwcf -dir存放設定檔的路徑usr/bin -dir存放可執行檔/usr/lib/sysusers/php-qbpwcf.conf記錄rpm包安裝時需要自動建立的使用者與群組資訊usr/lib64/qbpwcf/cgi -dir存放 cgi 格式的腳本檔案.usr/lib64/qbpwcf -dir存放本套件用到到函式庫usr/lib64/qbpwcf/composer -dir用來存放 composer 工具的地方usr/lib64/qbpwcf/fonts -dir存放字體的路徑usr/lib64/qbpwcf/img -dir用來存放圖片的地方usr/lib64/qbpwcf/javaScript -dir存放用來產生javaScript給外部瀏覽器使用的目錄usr/lib64/qbpwcf/json -dir存放用來接受回應後只回傳json的頁面usr/lib64/qbpwcf/tcpdf -dir存放 tcdpf 套件的地方usr/lib64/qbpwcf/unserialize -dirunserialize post data then output json.usr/lib64/qbpwcf/webExtension -dir存放 webExtension 的目錄usr/lib64/qbpwcf/*.php提供各種功能的php檔案usr/lib64/qbpwcf/*-soap.php提供各種soap服務的php檔案usr/share/qbpwcf/sample/db -dir存放需要使用資料庫的套件sql與寫入與讀取資料庫資料的方法.usr/share/qbpwcf/free-lib -dir存放開源的函式庫usr/share/qbpwcf/non-free-lib -dir存放不開源或不得任意散布的函式庫usr/share/qbpwcf/sample -dir提供各類別底下個別函式的執行範例usr/share/qbpwcf/legencyTestCase -dir提供各類別底下個別函式的舊的執行範例etc/systemd/system -dir存放 service 設定檔var/qbpwcf/tmp -dir暫存目錄gpl.txtGPL條款說明index.php顯示 Release Note 檔案內容的頁面install.php安裝本套件的php腳本License版權宣告README本文件Release Note、Release_Note版本異動記錄由於版權關係,因此以下檔案需自行下載與安裝:usr/share/qbpwcf/free_lib/bootstrap-3.3.6-distusr/share/qbpwcf/free_lib/jquery-2.2.2.min.jsusr/share/qbpwcf/free_lib/notify.min.jsusr/share/qbpwcf/free_lib/Chart.jsusr/share/qbpwcf/free_lib/ckeditorusr/share/qbpwcf/free_lib/webrtcusr/share/qbpwcf/free_lib/apache-hiveusr/share/qbpwcf/free_lib/lMatrixusr/share/qbpwcf/non-free-lib/amchart/amcharts_3.18.6.freeusr/share/qbpwcf/non-free-lib/amchart/amcharts_3.19.6.freeusr/share/qbpwcf/non-free-lib/amchart/ammap_3.19.6.freeusr/share/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["argu"],使用的參數.#$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變數須為陣列形態";#如果傳入的參數為 nullif(is_null($conf)){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end}//function haveArgu end建立不含有必填參數的涵式一開始的寫法可以如下:/*#函式說明:#...#回傳結果:#$result["status"],"true"代表移除成功,"false"代表移除失敗.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["content"],主要期望的回傳內容.#必填參數:#無.#可省略參數:#$conf["key"],字串,名為"key"的參數,預設為"index".#$conf["key"]="index";#$conf["fileArgu"],字串,__FILE__的內容,預設為__FILE__.#$conf["fileArgu"]=__FILE__;#參考資料:#無.#備註:#無*/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變數須為陣列形態";#如果傳入的參數為 nullif(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 的路徑,可以放置以下 內容:#使用命名空間qbpwcfnamespace qbpwcf;#取得 lib pathexec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);#如果執行失敗if($status!==0){#debugvar_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){#debugvar_dump(__LINE__,$output);#結束執行,回傳shell 1.exit(1);}#if end#設置 include pathset_include_path($output[0].PATH_SEPARATOR.get_include_path());#匯入外部套件require_once("allInOne.php");建立 usr/bin/libexec 底下的非 folderOfUsrLib.php 程式時,建議開頭要先取得 lib 的路徑,可以放置以下 內容:#使用命名空間qbpwcfnamespace qbpwcf;#取得 lib pathexec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/folderOfUsrLib.php"),$output,$status);#如果執行失敗if($status!==0){#debugvar_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");#使用命名空間 qbpwcfnamespace qbpwcf;#設定要使用的參數陣列$argArray["key"]=$value;#要使用的類別與函式跟參數className::function($argArray);#移除用好的參數unset($argArray);#存取物件的key時,若要用變數來表示,則請勿使用 $object->$var["key"] 的方式來指定,會被誤認為 ($object->$var)["key"].#可改成以下寫法:#將要存取的key另存為單一變數.$objectKey=$var["key"];#用單一變數作為 $object 底下的 $key.$object->$objectKey;參考資料:以下網址為google提供的javascript整合套件,據說比JQuery更省資源https://developers.google.com/speed/libraries/devguide?hl=zh-twPHP 設計模式學習手冊 (Learning PHP Design Patterns)http://www.tenlong.com.tw/items/9862767707?item_id=609455Dependency Manager for PHPhttps://getcomposer.org/Autoloading Standardhttps://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md取得函數所接受到的參數數量http://php.net/manual/en/function.func-num-args.php