alef-backend-php 0.14.36

PHP (ext-php-rs) backend for alef
Documentation
{% if is_optional %}
let {{ php_name }}_core: Option<Vec<{{ core_import }}::{{ struct_name }}>> = if let Some(arr) = {{ php_name }}.as_ref() {
    let mut result = Vec::new();
    if let Some(ht) = unsafe { arr.value.arr.as_ref() } {
        for (_, item) in ht.iter() {
            if let Some(parsed) = <{{ core_import }}::{{ struct_name }} as ext_php_rs::convert::FromZvalMut>::from_zval_mut(unsafe { &mut *(item as *const ext_php_rs::types::Zval as *mut ext_php_rs::types::Zval) }) {
                result.push(parsed);
            } else {
                return Err(ext_php_rs::exception::PhpException::default("Failed to convert array element to {{ struct_name }}".to_string()));
            }
        }
    }
    Some(result)
} else {
    None
};
{% else %}
let mut {{ php_name }}_core_result = Vec::new();
if let Some(ht) = unsafe { {{ php_name }}.value.arr.as_ref() } {
    for (_, item) in ht.iter() {
        if let Some(parsed) = <{{ core_import }}::{{ struct_name }} as ext_php_rs::convert::FromZvalMut>::from_zval_mut(unsafe { &mut *(item as *const ext_php_rs::types::Zval as *mut ext_php_rs::types::Zval) }) {
            {{ php_name }}_core_result.push(parsed);
        } else {
            return Err(ext_php_rs::exception::PhpException::default("Failed to convert array element to {{ struct_name }}".to_string()));
        }
    }
}
let {{ php_name }}_core: Vec<{{ core_import }}::{{ struct_name }}> = {{ php_name }}_core_result;
{% endif %}