pub fn parse(input: &[u8]) -> Option<Value>Expand description
yaml_parse($input): the first document of input as a PHP value, or
None where PHP returns false (and warns): a malformed document or an
unknown alias, or nesting deeper than MAX_DEPTH. An input without a
document is null.
PHP: yaml_parse($input) with yaml.decode_timestamp, decode_binary
and decode_php off (their defaults). Only the first document is read:
errors after it are not reported.
use php_std::{Value, yaml};
let Some(Value::Array(config)) = yaml::parse(b"enabled: yes\nmode: 0755\nratio: 1.5\n") else { panic!() };
assert_eq!(config.get_str("enabled"), Some(&Value::Bool(true)));
assert_eq!(config.get_str("mode"), Some(&Value::Int(493)));
assert_eq!(config.get_str("ratio"), Some(&Value::Float(1.5)));
assert_eq!(yaml::parse(b"a: *missing"), None);$config = yaml_parse("enabled: yes\nmode: 0755\nratio: 1.5\n");
var_dump($config['enabled'], $config['mode'], $config['ratio']); // bool(true) int(493) float(1.5)
var_dump(@yaml_parse('a: *missing')); // bool(false)