Rev 915 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2015~2024 Min-Jhin,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/>.*/namespace qbpwcf;/*類別說明:跟open document有關的類別.備註:無.*/class od{/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public function __call($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __call end/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public static function __callStatic($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __callStatic end/*#函式說明:#匯入phpodt函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無*/function importOdtLib(){#取得當前執行的函式$result["function"]=__FUNCTION__;#設定 phpodt lib 的路徑$phpOdtLibPath="lib/phpodt-0.3.3/phpodt.php";#檢查要匯入的套件是否存在#涵式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($phpOdtLibPath);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查檔案是否存在失敗if($checkMultiFileExist["status"]=="false"){#設置錯誤訊息$result["error"]=$checkMultiFileExist;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#如果檔案不存在if($checkMultiFileExist["allExist"]=="false"){#設置錯誤訊息$result["error"]=$checkMultiFileExist;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#匯入 phpodt 套件include($phpOdtLibPath);#設置執行正常$result["status"]="true";#回傳結果return $result;}#function importOdtLib end/*#函式說明:#展示建立odt檔案的功能,會產生名稱為"od::demoOdt.odt"的檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],建立的ods檔案路徑與名稱.#必填參數:#無#可省略參數:#無#參考資料:#http://php-odt.sourceforge.net/*/function demoOdt(){#取得當前執行的函式$result["function"]=__FUNCTION__;/*#函式說明:#匯入phpodt函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無*/$importLib=od::importOdtLib();#如果匯入 phpodt 函式庫失敗if($importLib["status"]=="false"){#設置錯誤訊息$result["error"]=$importLib;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#DEMO$odt=\ODT::getInstance();$p=new \Paragraph();$p->addText('Hello World!!');$odt->output('odT/demoOdt.odt');#取得檔案位置$result["content"]="odT/demoOdt.odt";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function demoOdt/*#函式說明:#匯入phpods函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無*/function importOdsLib(){#取得當前執行的函式$result["function"]=__FUNCTION__;#設定 phpods lib 的路徑$phpOdsLibPath="lib/ods-php-0.1rc1/ods.php";#檢查要匯入的套件是否存在#涵式說明:檢查多個檔案與資料夾是否存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。#必填參數:#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($phpOdsLibPath);#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;#可省略參數#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".#$conf["disableWebSearch"]="false";#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".#$conf["userDir"]="true";#參考資料來源:#http://php.net/manual/en/function.file-exists.php#http://php.net/manual/en/control-structures.foreach.php#備註:#函數file_exists檢查的路徑為檔案系統的路徑$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);unset($conf["fileAccess::checkMultiFileExist"]);#如果檢查檔案是否存在失敗if($checkMultiFileExist["status"]=="false"){#設置錯誤訊息$result["error"]=$checkMultiFileExist;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#如果檔案不存在if($checkMultiFileExist["allExist"]=="false"){#設置錯誤訊息$result["error"]=$checkMultiFileExist;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#匯入 phpodt 套件include($phpOdsLibPath);#設置執行正常$result["status"]="true";#回傳結果return $result;}#function importOdsLib end/*#函式說明:#展示建立ods檔案的功能,會出現檔案名稱為'od::demoOdf.ods'的檔案.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],建立的ods檔案路徑與名稱.#必填參數:#無#可省略參數:#無#參考資料:#https://sourceforge.net/projects/ods-php/?source=typ_redirect*/function demoOds(){/*#函式說明:#匯入phpods函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無*/$importOdsLib=od::importOdsLib();#如果載入 php ods lib 失敗if($importOdsLib["status"]=="false"){#設置錯誤訊息$result["error"]=$importLib;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#create a new ods file$object=\newOds();#add a cell to sheet 0, row 0, cell 0, with value 1 and type float$object->addCell(0,0,0,1,'float');#add a cell to sheet 0, row 0, cell 1, with value 1 and type float$object->addCell(0,0,1,2,'float');#add a cell to sheet 0, row 1, cell 0, with value 1 and type float$object->addCell(0,1,0,1,'float');#add a cell to sheet 0, row 1, cell 1, with value 1 and type float$object->addCell(0,1,1,2,'float');#save the object to a ods filesaveOds($object,'odT/demoOdf.ods');#取得檔案路徑$result["content"]="odT/demoOdf.ods";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function demoOds end/*#函式說明:#建立ods檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],建立的ods檔案路徑與名稱.#必填參數:#$conf["filePathAndName"],字串,ods檔案要存放的地方,副檔名".ods"會自動補上.$conf["filePathAndName"]="";#$conf["content"],字串陣列,要放在ods檔案裡面各sheet的內容,$conf["content"][tab][row][col]=array("Hello!","string");為第tab+1個分頁第row+1列第col+1欄的內容為"Hello!",型態為"string",型態未指定的話,則預設為"string".$conf["content"]=;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#無#參考資料:#https://sourceforge.net/projects/ods-php/?source=typ_redirect*/function createOds(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數$result["function"]=__FUNCTION__;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePathAndName","content","fileArgu");#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("alt","class");#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","");#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查失敗if($checkResult["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end#如果檢查不通過if($checkResult["passed"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$checkResult;#回傳結果return $result;}#if end/*#函式說明:#匯入phpods函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無*/$importOdsLib=od::importOdsLib();#create a new ods file$object=\newOds();#針對每個分頁foreach($conf["content"] as $tabName=>$tabContent){#如果 $tabContent 不為陣列或元素數量為0if(gettype($tabContent)!="array" || count($tabContent)==0){#結束foreach endbreak;}#if end#針對每個列foreach($tabContent as $rowName=>$rowContent){#如果 $rowContent 不為陣列或元素數量為0if(gettype($rowContent)!="array" || count($rowContent)==0){#結束foreach endbreak;}#if end#針對每個行foreach($rowContent as $colName=>$colContent){#如果 $colContent 不為陣列或元素數量為0if(gettype($colContent)!="array" || count($colContent)==0){#結束foreach endbreak;}#if end#針對每個欄位的內容for($i=0;$i<2;$i++){#如果內容元素不存在if(!isset($colContent[$i])){#如果是數值if($i==0){#設為空字串$colContent[$i]="";}#if end#反之如果是形態else if($i==1){#設為字串$colContent[$i]="string";}#if end}#if end}#for end#add a cell to sheet $tabName, row $rowName, cell $colName, with value $colContent[0] and type $colContent[1]$object->addCell($tabName,$rowName,$colName,$colContent[0],$colContent[1]);}#foreach end}#foreache end}#foreach end#確保路徑#涵式說明:#確保路徑存在.#回傳的結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#必填的參數:#$conf["path"],要檢查的路徑$conf["fileAccess::validatePath"]["path"]=$conf["filePathAndName"];#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];#可省略參數:#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".$conf["fileAccess::validatePath"]["haveFileName"]="true";#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.#$conf["dirPermission"]="";$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);unset($conf["fileAccess::validatePath"]);#如果確保路徑失敗if($validatePath["status"]=="false"){#設置錯誤狀態$result["status"]="false";#設置錯誤提示$result["error"]=$validatePath;#回傳結果return $result;}#if end#save the object to a ods filesaveOds($object,$conf["filePathAndName"].".ods");#取得ods檔案的路徑$result["content"]=$conf["filePathAndName"].".ods";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function createOds end/*#函式說明:#建立odt檔案#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["content"],建立的ods檔案路徑與名稱.#必填參數:#$conf["filePathAndName"],字串,odt檔案要存放的地方,副檔名".odt"會自動補上.$conf["filePathAndName"]="";#$conf["content"],字串陣列,要放在odt檔案裡面的內容,每個元素的內容代表一個段落.$conf["content"]=array();#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#無#參考資料:#https://sourceforge.net/projects/ods-php/?source=typ_redirect*/function createOdt(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#如果沒有參數if(func_num_args()==0){#設置執行失敗$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($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.#$result["argu"],字串陣列,目前輸入的參數名稱陣列.#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.#$result["notNeedVar"],字串陣列,多餘的參數名稱.#必填寫的參數:#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。$conf["variableCheck::checkArguments"]["varInput"]=&$conf;#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePathAndName","content","fileArgu");#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";#可以省略的參數:#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("filePathAndName");#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.#$conf["canBeEmpty"]=array();#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.#$conf["skipableVariableCanNotBeEmpty"]=array();#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("liId");#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"liName\"]");#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("liName","liContnet","liId");#參考資料來源:#array_keys=>http://php.net/manual/en/function.array-keys.php$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);unset($conf["variableCheck::checkArguments"]);#如果檢查參數失敗if($checkArguments["status"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#如果檢查參數不通過if($checkArguments["passed"]=="false"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"]=$checkArguments;#回傳結果return $result;}#if end#函式說明:#匯入phpodt函式庫的函式#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#無#可省略參數:#無$importLib=od::importOdtLib();#如果匯入 phpodt 函式庫失敗if($importLib["status"]=="false"){#設置錯誤訊息$result["error"]=$importLib;#設置執行不正常$result["status"]="false";#回傳結果return $result;}#if end#建立實體$odt=\ODT::getInstance();#針對 $conf["content"] 的每個元素foreach($conf["content"] as $pKey=>$pVal){#新增段落$pKey=new \Paragraph();#設置內容$pKey->addText($pVal);}#foreach end#輸出置檔案$odt->output($conf["filePathAndName"].".odt");#取得檔案位置$result["content"]=$conf["filePathAndName"].".odt";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function createOdt end}#class od end?>