Skip to content

Commit 0f4f6f7

Browse files
committed
Add docs / guide
1 parent b451d60 commit 0f4f6f7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

guide/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
- [Constants](./macros/constant.md)
3333
- [`ZvalConvert`](./macros/zval_convert.md)
3434
- [Exceptions](./exceptions.md)
35+
- [INI Settings](./ini-settings.md)

guide/src/ini-settings.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# INI Settings
2+
3+
Your PHP Extension may want to provide it's own PHP INI settings to configure behaviour. This can be done in the `#[php_startup]` annotated startup function.
4+
5+
## Registering INI Settings
6+
7+
All PHP INI definitions must be registered with PHP to get / set their values via the `php.ini` file or `ini_get() / ini_set()`.
8+
9+
10+
```rust,no_run
11+
# #![cfg_attr(windows, feature(abi_vectorcall))]
12+
# extern crate ext_php_rs;
13+
# use ext_php_rs::prelude::*;
14+
# use ext_php_rs::zend::IniEntryDef;
15+
# use ext_php_rs::flags::IniEntryPermission;
16+
17+
#[php_startup]
18+
pub fn startup_function(ty: i32, module_number: i32) {
19+
let ini_entries: Vec<IniEntryDef> = vec![
20+
IniEntryDef::new(
21+
"my_extension.display_emoji".to_owned(),
22+
"yes".to_owned(),
23+
IniEntryPermission::All,
24+
),
25+
];
26+
IniEntryDef::register(ini_entries, module_number);
27+
}
28+
# fn main() {}
29+
```
30+
31+
## Getting INI Settings
32+
33+
The INI values are stored as part of the `GlobalExecutor`, and can be accessed via the `ini_values()` function. To retrieve the value for a registered INI setting
34+
35+
```rust,no_run
36+
# #![cfg_attr(windows, feature(abi_vectorcall))]
37+
# extern crate ext_php_rs;
38+
# use ext_php_rs::prelude::*;
39+
# use ext_php_rs::zend::ExecutorGlobals;
40+
41+
#[php_startup]
42+
pub fn startup_function(ty: i32, module_number: i32) {
43+
// Get all INI values
44+
let ini_values = ExecutorGlobals::get().ini_values(); // HashMap<String, Option<String>>
45+
let my_ini_value = ini_values.get("my_extension.display_emoji"); // Option<Option<String>>
46+
}
47+
# fn main() {}
48+
```

0 commit comments

Comments
 (0)