Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fc84abe
feat: Add interface bindings
Norbytus Jul 10, 2025
164fe18
feat: Add interface builders
Norbytus Jul 13, 2025
44cb830
feat(macro): Add macro to declare interface from trait
Norbytus Jul 13, 2025
740ceda
feat: Add tests
Norbytus Jul 13, 2025
fbaf1a9
feat: Add missing things in interface builder
Norbytus Jul 20, 2025
ce53141
feat: Add methods, const registration for interface
Norbytus Jul 20, 2025
8f8f61d
feat: Add tests for interface registration
Norbytus Jul 20, 2025
14ab871
chore: Add internal function for interface attribute macros
Norbytus Jul 21, 2025
1d69860
feat: Add doc for interface macros and add test for expand
Norbytus Jul 21, 2025
94ab2cd
chore: CI things
Norbytus Jul 21, 2025
b728a4c
feat: Change const registration for interface
Norbytus Jul 21, 2025
6b990d6
feat: Rewrite attribute parse
Norbytus Jul 22, 2025
18cc27f
refactor: Change parser function
Norbytus Aug 4, 2025
b951a20
fix: Add path to hashmap
Norbytus Aug 4, 2025
5258958
fix: Fix constant registration for interface
Norbytus Aug 4, 2025
085f3f2
chore: Add test with default value
Norbytus Aug 4, 2025
0256cad
chore: Delete unnecessary impl generation
Norbytus Aug 4, 2025
724ca82
feat: Define constructor
Norbytus Aug 4, 2025
661ae2b
feat: Describe interface classes
Norbytus Aug 4, 2025
fc00fb5
feat: Separate interfaces from classes in module
Norbytus Aug 4, 2025
13cb601
feat: Add doc about interface in guide
Norbytus Aug 10, 2025
a2d0f54
chore: Delete unused interface.rs
Norbytus Aug 10, 2025
38d3839
chore: Clean from duplicated code
Norbytus Aug 10, 2025
0a66195
chore: Fix clippy and etc
Norbytus Aug 10, 2025
23b22df
chore: Remove expand test
Norbytus Aug 11, 2025
821dcb8
test(interface): add macro expansion tests
Xenira Oct 4, 2025
fbbcd0a
feat(interface): add doc comment support
Xenira Oct 4, 2025
cc86ac8
docs(interface): update lib docs
Xenira Oct 4, 2025
cf3cf69
test(interface): fix expansion test
Xenira Oct 4, 2025
3634fb5
feat(interface): add support for renaming all consts/methods
Xenira Oct 4, 2025
8c9ab59
docs(macro): update lib docs
Xenira Nov 14, 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::{TokenStreamExt, quote};
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
Loading