2024 年日本 PHP 研討會

簡介

Yet Another Configurations Container (Yaconf) 是一個設定容器,它會解析 INI 檔案,並在 PHP 啟動時將結果儲存在 PHP 中,該結果會在整個 PHP 生命週期中持續存在。

Yaconf 將所有設定儲存為內部字串或不可變陣列,這表示它們無法進行引用計數,因此當您從 Yaconf 擷取設定時,可以將其視為零拷貝,速度非常快。

Yaconf 支援 INI 檔案中的區段和區段繼承。如果 PHP 是以非 ZTS 模式建置的,Yaconf 也支援在 INI 檔案更改後自動重新載入。

Yaconf 需要 PHP 7.0 或更高版本。

範例 #1 INI 範例

;Simple key val
key=val

;Hash
hash.a=val

;Array
arr.0=val
;or
arr[]=val

;PHP constant
version=PHP_VERSION

;Environment variable
env=${PATH}

範例 #2 INI 區段範例

[SectionA]
key=val
hash.a=val

;SectionB inherits SectionA
[SectionB:SectionA]
key=new_val                  ;override configuration key in SectionA
新增註釋

使用者提供的註釋

此頁面沒有使用者提供的註釋。
To Top