@@ -15,7 +15,8 @@ register functions, classes, constants and startup function when declaring
1515the module.
1616
1717``` rs
18- #[php_module(startup = " startup_function" )]
18+ #[php_module]
19+ #[php(startup = " startup_function" )]
1920pub fn get_module (module : ModuleBuilder ) -> ModuleBuilder {
2021 module
2122 . class :: <TestClass >()
@@ -44,6 +45,13 @@ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
4445}
4546```
4647
48+ ** Supported ` #[php] ` attributes:**
49+ - ` #[php(name = "NEW_NAME")] ` - Renames the function
50+ - ` #[php(rename = case)] ` - Changes the case of the function name
51+ - ` #[php(vis = "public")] ` - Changes the visibility of the function
52+ - ` #[php(defaults(a = 5, test = 100))] ` - Sets default values for function arguments
53+ - ` #[php(variadic)] ` - Marks the function as variadic. The last argument must be a ` &[&Zval] `
54+
4755### Classes
4856
4957Mostly unchanged in terms of the class and impl definitions, however you now
@@ -55,24 +63,23 @@ use ext_php_rs::prelude::*;
5563#[php_class]
5664#[derive(Debug )]
5765pub struct TestClass {
58- #[prop]
66+ #[php( prop) ]
5967 a : i32 ,
60- #[prop]
68+ #[php( prop) ]
6169 b : i32 ,
6270}
6371
6472#[php_impl]
6573impl TestClass {
66- #[rename( " NEW_CONSTANT_NAME" )]
74+ #[php(name = " NEW_CONSTANT_NAME" )]
6775 pub const SOME_CONSTANT : i32 = 5 ;
6876 pub const SOME_OTHER_STR : & 'static str = " Hello, world!" ;
6977
7078 pub fn __construct (a : i32 , b : i32 ) -> Self {
7179 Self { a : a + 10 , b : b + 10 }
7280 }
7381
74- #[optional(test)]
75- #[defaults(a = 5, test = 100)]
82+ #[php(defaults(a = 5, test = 100))]
7683 pub fn test_camel_case (& self , a : i32 , test : i32 ) {
7784 println! (" a: {} test: {}" , a , test );
7885 }
@@ -95,6 +102,20 @@ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
95102}
96103```
97104
105+ ** Supported ` #[php] ` attributes (` struct ` ):**
106+ - ` #[php(name = "NEW_NAME")] ` - Renames the class
107+ - ` #[php(rename = case)] ` - Changes the case of the class name
108+ - ` #[php(vis = "public")] ` - Changes the visibility of the class
109+ - ` #[php(extends = "ParentClass")] ` - Extends a parent class
110+ - ` #[php(implements = "Interface")] ` - Implements an interface
111+ - ` #[php(prop)] ` - Marks a field as a property
112+
113+ ** Supported ` #[php] ` attributes (` impl ` ):**
114+ - ` #[php(rename_consts = case)] ` - Changes the case of the constant names. Can be overridden by attributes on the constants.
115+ - ` #[php(rename_methods = case)] ` - Changes the case of the method names. Can be overridden by attributes on the methods.
116+
117+ For elements in the ` #[php_impl] ` block see the respective function and constant attributes.
118+
98119### Constants
99120
100121Mostly unchanged in terms of constant definition, however you now need to
@@ -106,14 +127,24 @@ use ext_php_rs::prelude::*;
106127#[php_const]
107128const SOME_CONSTANT : i32 = 100 ;
108129
130+ #[php_const]
131+ #[php(name = " HELLO_WORLD" )]
132+ const SOME_OTHER_CONSTANT : & 'static str = " Hello, world!" ;
133+
109134#[php_module]
110135pub fn get_module (module : ModuleBuilder ) -> ModuleBuilder {
111136 module
112137 . constant (wrap_constant! (SOME_CONSTANT )) // SOME_CONSTANT = 100
138+ . constant (wrap_constant! (SOME_OTHER_CONSTANT )) // HELLO_WORLD = "Hello, world!"
113139 . constant ((" CONST_NAME" , SOME_CONSTANT , & [])) // CONST_NAME = 100
114140}
115141```
116142
143+ ** Supported ` #[php] ` attributes:**
144+ - ` #[php(name = "NEW_NAME")] ` - Renames the constant
145+ - ` #[php(rename = case)] ` - Changes the case of the constant name
146+ - ` #[php(vis = "public")] ` - Changes the visibility of the constant
147+
117148### Extern
118149
119150No changes.
@@ -144,8 +175,24 @@ fn startup_function(ty: i32, mod_num: i32) -> i32 {
144175 0
145176}
146177
147- #[php_module(startup = " startup_function" )]
178+ #[php_module]
179+ #[php(startup = " startup_function" )]
148180pub fn get_module (module : ModuleBuilder ) -> ModuleBuilder {
149181 module
150182}
151183```
184+
185+ ### ` #[php] ` Attributes
186+
187+ Attributes like ` #[rename] ` or ` #[prop] ` have been moved to the ` #[php] ` attribute.
188+
189+ The ` #[php] ` attribute on an item are combined with each other. This means that
190+ the following variants are equivalent:
191+ ``` rs
192+ #[php(rename = case)]
193+ #[php(vis = " public" )]
194+ ```
195+
196+ ``` rs
197+ #[php(rename = case, vis = " public" )]
198+ ```
0 commit comments