Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 748 | Rev 791 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 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/>.

檔案目錄結構:

cgi -dir
存放 cgi 格式的腳本檔案.

composer -dir
用來存放 composer 工具的地方

db -dir
存放需要使用資料庫的套件sql與寫入與讀取資料庫資料的方法.

etc -dir
存放設定檔的路徑

fonts -dir
存放字體的路徑

img -dir
用來存放圖片的地方

json -dir
存放用來接受回應後只回傳json的頁面

lib -dir
存放本套件用到到函式庫

non-free-lib -dir
存放不開源或不得任意散布的函式庫

systemd -dir
存放 service 設定檔

tcpdf -dir
存放 tcdpf 套件的地方

tmp -dir
暫存目錄

unserialize -dir
unserialize post data then output json.

testCase -dir
爲存放測試案例的地方

usr -dir
放置 usr 目錄相關的檔案與目錄.

var -dir
存放執行中的資源,例如socket檔案.

webExtension -dir
存放 webExtension 的目錄

*.php
提供各種功能的php檔案

*-soap.php
提供各種soap服務的php檔案

由於版權關係,因此以下檔案需自行下載與安裝:

lib/bootstrap-3.3.6-dist
lib/jquery-2.2.2.min.js
lib/notify.min.js
lib/Chart.js
lib/ckeditor
lib/webrtc
lib/apache-hive
lib/glMatrix
non-free-lib/amchart/amcharts_3.18.6.free
non-free-lib/amchart/amcharts_3.19.6.free
non-free-lib/amchart/ammap_3.19.6.free
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().

建立含有參數的函式一開始的寫法可以如下:

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 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 ?>符號。

參考資料:

以下網址為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