Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 638 | Rev 717 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 638 Rev 714
Line 23... Line 23...
23
*/
23
*/
24
 
24
 
25
#使用命名空間qbpwcf
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
26
namespace qbpwcf;
27
 
27
 
-
 
28
#以該檔案的實際位置的 lib path 為 include path 首位
-
 
29
exec("cd ".pathinfo(__FILE__)["dirname"]."/../qbpwcf;pwd;",$output,$status);
-
 
30
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
-
 
31
 
28
#匯入套件
32
#匯入套件
29
require_once("qbpwcf/allInOneForJson.php");
33
require_once("allInOne.php");
30
 
34
 
31
#建議的log位置
35
#建議的log位置
32
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
36
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
33
 
37
 
34
#函式說明:
38
#要使用的範例name
35
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
-
 
36
#回傳結果:
39
#$nameOfSample="initial";
37
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
-
 
38
#$result["error"],錯誤訊息陣列.
40
$nameOfSample="20240328";
-
 
41
 
39
#$result["function"],當前執行的函數名稱.
42
#存放範例的資料夾
40
#$result["content"],結果.
43
$sampleFolder="config::client";
41
#必填參數:
44
 
42
#$conf["server"],字串,組態服務設定服務的網址
45
#設置範例檔案名稱與路徑
43
$conf["server"]="https://latest.qbpwcf.org/sample/config::server.php";
46
$fileNameOfSample=$sampleFolder."/".$nameOfSample.".php";
44
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
-
 
45
$conf["postName"]="169.254.1.1";
-
 
46
#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
-
 
47
 
47
$conf["fileArgu"]=__FILE__;
48
#初始化儲存範例代碼
48
#可省略參數:
49
$samples=array();
49
#無.
50
 
50
#參考資料:
51
#增加 config::client 的範例資訊
-
 
52
$samples[]=array("name"=>"initial","comnent"=>"initial sample.");
-
 
53
$samples[]=array("name"=>"20240328","comnent"=>"get config from cache");
51
#無.
54
 
52
#備註:
-
 
53
#目前僅能跟server函式提供的服務對接.
55
#針對每個範例資訊
54
$client=config::client($conf);
56
foreach($samples as $sample){
55
unset($conf);
-
 
56
 
57
 
57
#如果執行失敗
58
	#如果找到對應的範例
58
if($client["status"]==="false"){
59
	if($sample["name"]===$nameOfSample){
59
 
60
	
60
	#函式說明:
61
		#如果存放範例的資料夾不存在
-
 
62
		if(!file_exists($sampleFolder)){
61
	#撰寫log
63
		
62
	#回傳結果:
64
			#提示訊息
63
	#$result["status"],狀態,"true"或"false".
65
			echo "存放範例的資料夾(".$sampleFolder.")不存在".PHP_EOL;
-
 
66
		
64
	#$result["error"],錯誤訊息陣列.
67
			#結束執行,並回傳1給shell
-
 
68
			exit(1);
-
 
69
		
-
 
70
			}#if end
-
 
71
			
65
	#$result["function"],當前函式的名稱.
72
		#如果對應的範例檔案不存在
66
	#$result["argu"],使用的參數.
73
		if(!file_exists($fileNameOfSample)){
-
 
74
		
67
	#必填參數:
75
			#提示訊息
68
	#$conf["path"],字串,log檔案的路徑與名稱.
76
			echo "範例檔案(".$fileNameOfSample.")不存在".PHP_EOL;
-
 
77
		
69
	$conf["path"]=$logFile;
78
			#結束執行,並回傳1給shell
70
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
71
	$conf["content"]=$client;
79
			exit(1);
72
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
-
 
80
		
73
	$conf["fileArgu"]=__FILE__;
81
			}#if end
-
 
82
			
74
	#可省略參數:
83
		#匯入範例
75
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
76
	#$conf["rewrite"]="false";
84
		require_once($fileNameOfSample);
-
 
85
		
77
	#參考資料:
86
		#結束執行
78
	#無.
87
		exit;
79
	#備註:
88
	
80
	#無.
89
		}#if end
81
	$record=logs::record($conf);
-
 
-
 
90
 
82
	unset($conf);
91
	}#foreach end
83
	
92
	
84
	#結束執行
93
#執行到這邊代表沒有對應的範例
85
	exit;
-
 
86
 
94
 
87
	}#if end
95
#提示範例不存在
-
 
96
echo "範例(".$nameOfSample.")不存在".PHP_EOL;
88
 
97
 
89
#印出 json 結果
98
#結束執行,並回傳1給shell
90
echo json_encode($client["content"]);
99
exit(1);
91
 
100
 
92
?>
101
?>
93
102