#[php_function]
pub fn {{ register_fn }}(backend: &mut ext_php_rs::types::ZendObject) -> ext_php_rs::prelude::PhpResult<()> {
{% for method in required_methods %}
    if backend.try_call_method("{{ method.name }}", vec![]).is_err() {
        return Err(ext_php_rs::exception::PhpException::default(
            format!("Backend missing required method: {}", "{{ method.name }}")
        ));
    }
{% endfor %}

    let wrapper = {{ wrapper }}::new(backend);
    let arc: std::sync::Arc<dyn {{ trait_path }}> = std::sync::Arc::new(wrapper);

    let registry = {{ registry_getter }}();
    let mut registry = registry.write();
    registry.register(arc{{ extra_args }}).map_err(|e| ext_php_rs::exception::PhpException::default(
        format!("Failed to register backend: {}", e)
    ))?;
    Ok(())
}
