Skip to content

Commit 736c080

Browse files
committed
fix: Fix constant registration for interface
1 parent 7c8a485 commit 736c080

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

crates/macros/src/interface.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ToTokens for InterfaceData<'_> {
5454
let implements = &self.attrs.extends;
5555
let methods_sig = &self.methods;
5656
let path = &self.path;
57+
let constants = &self.constants;
5758
quote! {
5859
pub struct #interface_name;
5960

@@ -89,6 +90,7 @@ impl ToTokens for InterfaceData<'_> {
8990
fn constructor() -> Option<::ext_php_rs::class::ConstructorMeta<Self>> {
9091
None
9192
}
93+
9294
fn constants() -> &'static [(
9395
&'static str,
9496
&'static dyn ext_php_rs::convert::IntoZvalDyn,
@@ -99,27 +101,27 @@ impl ToTokens for InterfaceData<'_> {
99101
}
100102

101103
fn get_properties<'a>() -> ::std::collections::HashMap<&'static str, ::ext_php_rs::internal::property::PropertyInfo<'a, Self>> {
102-
::std::collections::HashMap::new()
104+
panic!("Non supported for Interface");
103105
}
104106
}
105107

106108
impl ::ext_php_rs::internal::class::PhpClassImpl<#path> for ::ext_php_rs::internal::class::PhpClassImplCollector<#path> {
107109
fn get_methods(self) -> ::std::vec::Vec<
108110
(::ext_php_rs::builders::FunctionBuilder<'static>, ::ext_php_rs::flags::MethodFlags)
109111
> {
110-
vec![]
112+
panic!("Non supported for Interface");
111113
}
112114

113115
fn get_method_props<'a>(self) -> ::std::collections::HashMap<&'static str, ::ext_php_rs::props::Property<'a, #path>> {
114-
todo!()
116+
panic!("Non supported for Interface");
115117
}
116118

117119
fn get_constructor(self) -> ::std::option::Option<::ext_php_rs::class::ConstructorMeta<#path>> {
118120
None
119121
}
120122

121123
fn get_constants(self) -> &'static [(&'static str, &'static dyn ::ext_php_rs::convert::IntoZvalDyn, &'static [&'static str])] {
122-
&[]
124+
&[#(#constants),*]
123125
}
124126
}
125127

@@ -299,6 +301,7 @@ impl<'a> Parse<'a, Vec<FnBuilder>> for ItemTrait {
299301
}
300302
}
301303

304+
#[derive(Debug)]
302305
struct Constant<'a> {
303306
name: String,
304307
expr: &'a Expr,
@@ -311,7 +314,7 @@ impl ToTokens for Constant<'_> {
311314
let expr = &self.expr;
312315
let docs = &self.docs;
313316
quote! {
314-
(#name, #expr, &[#(#docs),*])
317+
(#name, &#expr, &[#(#docs),*])
315318
}
316319
.to_tokens(tokens);
317320
}

tests/src/integration/interface/interface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ public function refToLikeThisClass(
3030
assert(is_a($f, Throwable::class));
3131
assert($f->nonStatic('Rust') === 'Rust - TEST');
3232
assert($f->refToLikeThisClass('TEST', $f) === 'TEST - TEST | TEST - TEST');
33+
assert(ExtPhpRs\Interface\EmptyObjectInterface::STRING_CONST === 'STRING_CONST');
34+
assert(ExtPhpRs\Interface\EmptyObjectInterface::USIZE_CONST === 200);

tests/src/integration/interface/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use ext_php_rs::types::ZendClassObject;
42
use ext_php_rs::zend::ce;
53
use ext_php_rs::{php_class, php_impl, php_interface};
@@ -9,6 +7,10 @@ use ext_php_rs::{php_module, prelude::ModuleBuilder};
97
#[php(extends(ce = ce::throwable, stub = "\\Throwable"))]
108
#[php(name = "ExtPhpRs\\Interface\\EmptyObjectInterface")]
119
pub trait EmptyObjectTrait {
10+
const STRING_CONST: &'static str = "STRING_CONST";
11+
12+
const USIZE_CONST: u64 = 200;
13+
1214
fn void();
1315

1416
fn non_static(&self, data: String) -> String;

0 commit comments

Comments
 (0)