Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
34859d0
feat: Add interface bindings
Norbytus Jul 10, 2025
f5e9c61
feat: Add interface builders
Norbytus Jul 13, 2025
d73682d
feat(macro): Add macro to declare interface from trait
Norbytus Jul 13, 2025
b3fde0f
feat: Add tests
Norbytus Jul 13, 2025
32486ea
feat: Add missing things in interface builder
Norbytus Jul 20, 2025
64046c1
feat: Add methods, const registration for interface
Norbytus Jul 20, 2025
4815727
feat: Add tests for interface registration
Norbytus Jul 20, 2025
1b65a64
chore: Add internal function for interface attribute macros
Norbytus Jul 21, 2025
d19d798
feat: Add doc for interface macros and add test for expand
Norbytus Jul 21, 2025
955410e
chore: CI things
Norbytus Jul 21, 2025
efdd583
feat: Change const registration for interface
Norbytus Jul 21, 2025
c7ec91c
feat: Rewrite attribute parse
Norbytus Jul 22, 2025
cfb6bae
refactor: Change parser function
Norbytus Aug 4, 2025
df237a6
fix: Add path to hashmap
Norbytus Aug 4, 2025
ea7a84a
fix: Fix constant registration for interface
Norbytus Aug 4, 2025
3b25e66
chore: Add test with default value
Norbytus Aug 4, 2025
08167e3
chore: Delete unnecessary impl generation
Norbytus Aug 4, 2025
6322320
feat: Define constructor
Norbytus Aug 4, 2025
d8d13de
feat: Describe interface classes
Norbytus Aug 4, 2025
f18389f
feat: Separate interfaces from classes in module
Norbytus Aug 4, 2025
b21ef31
feat: Add doc about interface in guide
Norbytus Aug 10, 2025
c967420
chore: Delete unused interface.rs
Norbytus Aug 10, 2025
8b19163
chore: Clean from duplicated code
Norbytus Aug 10, 2025
fe59256
chore: Fix clippy and etc
Norbytus Aug 10, 2025
07baf5e
chore: Remove expand test
Norbytus Aug 11, 2025
c0a7827
test(interface): add macro expansion tests
Xenira Oct 4, 2025
05dfddd
feat(interface): add doc comment support
Xenira Oct 4, 2025
f7709e0
docs(interface): update lib docs
Xenira Oct 4, 2025
f575a33
test(interface): fix expansion test
Xenira Oct 4, 2025
0936605
feat(interface): add support for renaming all consts/methods
Xenira Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ bind! {
zend_register_double_constant,
zend_register_ini_entries,
zend_register_internal_enum,
zend_register_internal_interface,
zend_ini_entry_def,
zend_register_internal_class_ex,
zend_register_long_constant,
Expand Down
19 changes: 13 additions & 6 deletions crates/macros/src/class.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use darling::util::Flag;
use darling::{FromAttributes, FromMeta, ToTokens};
use proc_macro2::TokenStream;
use quote::quote;
use quote::{quote, TokenStreamExt};
use syn::{Attribute, Expr, Fields, ItemStruct};

use crate::helpers::get_docs;
Expand All @@ -28,8 +28,17 @@ pub struct StructAttributes {

#[derive(FromMeta, Debug)]
pub struct ClassEntryAttribute {
ce: syn::Expr,
stub: String,
pub ce: syn::Expr,
pub stub: String,
}

impl ToTokens for ClassEntryAttribute {
fn to_tokens(&self, tokens: &mut TokenStream) {
let ce = &self.ce;
let stub = &self.stub;
let token = quote! { (#ce, #stub) };
tokens.append_all(token);
}
}

pub fn parser(mut input: ItemStruct) -> Result<TokenStream> {
Expand Down Expand Up @@ -151,10 +160,8 @@ fn generate_registered_class_impl(
};

let extends = if let Some(extends) = extends {
let ce = &extends.ce;
let stub = &extends.stub;
quote! {
Some((#ce, #stub))
Some(#extends)
}
} else {
quote! { None }
Expand Down
34 changes: 34 additions & 0 deletions crates/macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@ impl<'a> Function<'a> {
format_ident!("_internal_{}", &self.ident)
}

pub fn abstract_function_builder(&self) -> TokenStream {
let name = &self.name;
let (required, not_required) = self.args.split_args(self.optional.as_ref());

// `entry` impl
let required_args = required
.iter()
.map(TypedArg::arg_builder)
.collect::<Vec<_>>();
let not_required_args = not_required
.iter()
.map(TypedArg::arg_builder)
.collect::<Vec<_>>();

let returns = self.build_returns();
let docs = if self.docs.is_empty() {
quote! {}
} else {
let docs = &self.docs;
quote! {
.docs(&[#(#docs),*])
}
};

quote! {
::ext_php_rs::builders::FunctionBuilder::new_abstract(#name)
#(.arg(#required_args))*
.not_required()
#(.arg(#not_required_args))*
#returns
#docs
}
}

/// Generates the function builder for the function.
pub fn function_builder(&self, call_type: CallType) -> TokenStream {
let name = &self.name;
Expand Down
10 changes: 10 additions & 0 deletions crates/macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ pub fn get_docs(attrs: &[Attribute]) -> Result<Vec<String>> {
})
.collect::<Result<Vec<_>>>()
}

pub trait CleanPhpAttr {
fn clean_php(&mut self);
}

impl CleanPhpAttr for Vec<Attribute> {
fn clean_php(&mut self) {
self.retain(|attr| !attr.path().is_ident("php"));
}
}
12 changes: 6 additions & 6 deletions crates/macros/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct ParsedImpl<'a> {
}

#[derive(Debug, Eq, Hash, PartialEq)]
enum MethodModifier {
pub enum MethodModifier {
Abstract,
Static,
}
Expand All @@ -141,7 +141,7 @@ impl quote::ToTokens for MethodModifier {
}

#[derive(Debug)]
struct FnBuilder {
pub struct FnBuilder {
/// Tokens which represent the `FunctionBuilder` for this function.
pub builder: TokenStream,
/// The visibility of this method.
Expand All @@ -151,13 +151,13 @@ struct FnBuilder {
}

#[derive(Debug)]
struct Constant<'a> {
pub struct Constant<'a> {
/// Name of the constant in PHP land.
name: String,
pub name: String,
/// Identifier of the constant in Rust land.
ident: &'a syn::Ident,
pub ident: &'a syn::Ident,
/// Documentation for the constant.
docs: Vec<String>,
pub docs: Vec<String>,
}

impl<'a> ParsedImpl<'a> {
Expand Down
Loading