|
| 1 | +# INI Builder |
| 2 | + |
| 3 | +When configuring a SAPI you may use `IniBuilder` to load INI settings as text. |
| 4 | +This is useful for setting up configurations required by the SAPI capabilities. |
| 5 | + |
| 6 | +INI settings applied to a SAPI through `sapi.ini_entries` will be immutable, |
| 7 | +meaning they cannot be changed at runtime. This is useful for applying settings |
| 8 | +to match hard requirements of the way your SAPI works. |
| 9 | + |
| 10 | +To apply _configurable_ defaults it is recommended to use a `sapi.ini_defaults` |
| 11 | +callback instead, which will allow settings to be changed at runtime. |
| 12 | + |
| 13 | +```rust,no_run |
| 14 | +use ext_php_rs::builder::{IniBuilder, SapiBuilder}; |
| 15 | +
|
| 16 | +// Create a new IniBuilder instance. |
| 17 | +let mut builder = IniBuilder::new(); |
| 18 | +
|
| 19 | +// Append a single key/value pair to the INIT buffer with an unquoted value. |
| 20 | +builder.unquoted("log_errors", "1"); |
| 21 | +
|
| 22 | +// Append a single key/value pair to the INI buffer with a quoted value. |
| 23 | +builder.quoted("default_mimetype", "text/html"); |
| 24 | +
|
| 25 | +// Append INI line text as-is. A line break will be automatically appended. |
| 26 | +builder.define("memory_limit=128MB"); |
| 27 | +
|
| 28 | +// Prepend INI line text as-is. No line break insertion will occur. |
| 29 | +builder.prepend("error_reporting=0\ndisplay_errors=1\n"); |
| 30 | +
|
| 31 | +// Construct a SAPI. |
| 32 | +let mut sapi = SapiBuiler::new("name", "pretty_name").build() |
| 33 | + .expect("should build SAPI"); |
| 34 | +
|
| 35 | +// Dump INI entries from the builder into the SAPI. |
| 36 | +sapi.ini_entries = builder.finish(); |
| 37 | +``` |
0 commit comments