folk-plugin-grpc 0.7.1

gRPC plugin for Folk — unary server + client (call upstreams from PHP) via tonic
Documentation
//! PHP host-function surface owned by the gRPC plugin (feature `php-ext`).
//!
//! Historically `folk_grpc_descriptors` was emitted as a Rust string by
//! folk-builder's codegen (with a `has_grpc` gate) — an ownership inversion where
//! the builder "knew" about a gRPC-specific function. This module moves that
//! ownership into the plugin: the plugin declares its PHP surface as real,
//! reviewable, clippy-checked Rust, and folk-builder simply calls
//! [`register_php_functions`] when the gRPC plugin is in the build
//! (folk-releases#89).

use ext_php_rs::binary::Binary;
use ext_php_rs::prelude::*;

use crate::export_descriptors;

/// Compile `paths` (proto files, cwd-relative) into an encoded
/// `FileDescriptorSet` and return the raw bytes.
///
/// Reuses the plugin's standalone [`export_descriptors`] (proto → FDS, no server
/// boot, no protoc), so the codegen SDK can obtain descriptors in-process — the
/// counterpart to the `folk-server grpc:descriptors` subprocess path.
#[php_function]
#[allow(clippy::needless_pass_by_value)] // ext-php-rs requires owned types
pub fn folk_grpc_descriptors(paths: Vec<String>) -> PhpResult<Binary<u8>> {
    let fds = export_descriptors(&paths)
        .map_err(|e| PhpException::default(format!("folk_grpc_descriptors: {e}")))?;
    Ok(Binary::new(fds))
}

/// Register the gRPC plugin's PHP host functions on `module` and return it.
///
/// Called by folk-builder's generated `get_module` (after
/// `folk_ext::register_core_functions`) when this plugin is present.
pub fn register_php_functions(module: ModuleBuilder) -> ModuleBuilder {
    module.function(wrap_function!(folk_grpc_descriptors))
}