@@ -18,6 +18,7 @@ use syn::{
1818
1919extern crate proc_macro;
2020
21+ // BEGIN DOCS FROM classes.md
2122/// # `#[php_class]` Attribute
2223///
2324/// Structs can be exported to PHP as classes with the `#[php_class]` attribute
@@ -33,7 +34,7 @@ extern crate proc_macro;
3334/// - `name` - Changes the name of the class when exported to PHP. The Rust
3435/// struct name is kept the same. If no name is given, the name of the struct
3536/// is used. Useful for namespacing classes.
36- /// - `rename ` - Changes the case of the class name when exported to PHP.
37+ /// - `change_case ` - Changes the case of the class name when exported to PHP.
3738/// - `#[php(extends(ce = ce_fn, stub = "ParentClass"))]` - Sets the parent
3839/// class of the class. Can only be used once. `ce_fn` must be a function with
3940/// the signature `fn() -> &'static ClassEntry`.
@@ -50,8 +51,8 @@ extern crate proc_macro;
5051///
5152/// - `name` - Allows you to rename the property, e.g. `#[php(name =
5253/// "new_name")]`
53- /// - `rename ` - Allows you to rename the property using rename rules, e.g.
54- /// `#[php(rename = PascalCase)]`
54+ /// - `change_case ` - Allows you to rename the property using rename rules, e.g.
55+ /// `#[php(change_case = PascalCase)]`
5556///
5657/// ## Restrictions
5758///
@@ -199,6 +200,7 @@ extern crate proc_macro;
199200/// }
200201/// # fn main() {}
201202/// ````
203+ // END DOCS FROM classes.md
202204#[ proc_macro_attribute]
203205pub fn php_class ( args : TokenStream , input : TokenStream ) -> TokenStream {
204206 let input = parse_macro_input ! ( input as ItemStruct ) ;
@@ -211,6 +213,7 @@ pub fn php_class(args: TokenStream, input: TokenStream) -> TokenStream {
211213 . into ( )
212214}
213215
216+ // BEGIN DOCS FROM function.md
214217/// # `#[php_function]` Attribute
215218///
216219/// Used to annotate functions which should be exported to PHP. Note that this
@@ -365,6 +368,7 @@ pub fn php_class(args: TokenStream, input: TokenStream) -> TokenStream {
365368/// You can also return a `Result` from the function. The error variant will be
366369/// translated into an exception and thrown. See the section on
367370/// [exceptions](../exceptions.md) for more details.
371+ // END DOCS FROM function.md
368372#[ proc_macro_attribute]
369373pub fn php_function ( args : TokenStream , input : TokenStream ) -> TokenStream {
370374 let input = parse_macro_input ! ( input as ItemFn ) ;
@@ -377,6 +381,7 @@ pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
377381 . into ( )
378382}
379383
384+ // BEGIN DOCS FROM constant.md
380385/// # `#[php_const]` Attribute
381386///
382387/// Exports a Rust constant as a global PHP constant. The constant can be any
@@ -389,8 +394,8 @@ pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
389394///
390395/// - `name` - Allows you to rename the property, e.g. `#[php(name =
391396/// "new_name")]`
392- /// - `rename ` - Allows you to rename the property using rename rules, e.g.
393- /// `#[php(rename = PascalCase)]`
397+ /// - `change_case ` - Allows you to rename the property using rename rules, e.g.
398+ /// `#[php(change_case = PascalCase)]`
394399///
395400/// ## Examples
396401///
@@ -428,6 +433,7 @@ pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
428433/// var_dump(I_AM_RENAMED); // int(42)
429434/// var_dump(MANUAL_CONSTANT); // string(12) "Hello world!"
430435/// ```
436+ // END DOCS FROM constant.md
431437#[ proc_macro_attribute]
432438pub fn php_const ( args : TokenStream , input : TokenStream ) -> TokenStream {
433439 let input = parse_macro_input ! ( input as ItemConst ) ;
@@ -440,6 +446,7 @@ pub fn php_const(args: TokenStream, input: TokenStream) -> TokenStream {
440446 . into ( )
441447}
442448
449+ // BEGIN DOCS FROM module.md
443450/// # `#[php_module]` Attribute
444451///
445452/// The module macro is used to annotate the `get_module` function, which is
@@ -506,6 +513,7 @@ pub fn php_const(args: TokenStream, input: TokenStream) -> TokenStream {
506513/// }
507514/// # fn main() {}
508515/// ```
516+ // END DOCS FROM module.md
509517#[ proc_macro_attribute]
510518pub fn php_module ( args : TokenStream , input : TokenStream ) -> TokenStream {
511519 let input = parse_macro_input ! ( input as ItemFn ) ;
@@ -518,6 +526,7 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
518526 . into ( )
519527}
520528
529+ // BEGIN DOCS FROM impl.md
521530/// # `#[php_impl]` Attribute
522531///
523532/// You can export an entire `impl` block to PHP. This exports all methods as
@@ -532,6 +541,21 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
532541/// If you want to use async Rust, use `#[php_async_impl]`, instead: see [here
533542/// »](./async_impl.md) for more info.
534543///
544+ /// ## Options
545+ ///
546+ /// By default all constants are renamed to `UPPER_CASE` and all methods are
547+ /// renamed to camelCase. This can be changed by passing the
548+ /// `change_method_case` and `change_constant_case` as `#[php]` attributes on
549+ /// the `impl` block. The options are:
550+ ///
551+ /// - `#[php(change_method_case = "snake_case")]` - Renames the method to snake
552+ /// case.
553+ /// - `#[php(change_constant_case = "snake_case")]` - Renames the constant to
554+ /// snake case.
555+ ///
556+ /// See the [`name` and `change_case`](./php.md#name-and-change_case) section
557+ /// for a list of all available cases.
558+ ///
535559/// ## Methods
536560///
537561/// Methods basically follow the same rules as functions, so read about the
@@ -546,17 +570,6 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
546570/// must be named `self_`. This can also be used to return a reference to
547571/// `$this`.
548572///
549- /// By default, all methods are renamed in PHP to the camel-case variant of the
550- /// Rust method name. This can be changed on the `#[php_impl]` attribute, by
551- /// passing one of the following as the `rename_methods` option:
552- ///
553- /// - `"none"` - does not rename the methods.
554- /// - `"camelCase"` - renames all methods to camel case (default).
555- /// - `"snake_case"` - renames all methods to snake case.
556- ///
557- /// For example, to disable renaming, change the `#[php_impl]` attribute to
558- /// `#[php_impl(rename_methods = "none")]`.
559- ///
560573/// The rest of the options are passed as separate attributes:
561574///
562575/// - `#[php(defaults(i = 5, b = "hello")]` - Sets the default value for
@@ -602,8 +615,9 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
602615/// attributes. By default, the `get_` or `set_` prefix is trimmed from the
603616/// start of the function name, and the remainder is used as the property name.
604617///
605- /// If you want to use a different name for the property, you can pass a
606- /// `rename` option to the attribute which will change the property name.
618+ /// If you want to use a different name for the property, you can pass a `name`
619+ /// or `change_case` option to the `#[php]` attribute which will change the
620+ /// property name.
607621///
608622/// Properties do not necessarily have to have both a getter and a setter, if
609623/// the property is immutable the setter can be omitted, and vice versa for
@@ -696,6 +710,7 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
696710/// ```
697711///
698712/// [`php_async_impl`]: ./async_impl.md
713+ // END DOCS FROM impl.md
699714#[ proc_macro_attribute]
700715pub fn php_impl ( args : TokenStream , input : TokenStream ) -> TokenStream {
701716 let input = parse_macro_input ! ( input as ItemImpl ) ;
@@ -708,6 +723,7 @@ pub fn php_impl(args: TokenStream, input: TokenStream) -> TokenStream {
708723 . into ( )
709724}
710725
726+ // BEGIN DOCS FROM extern.md
711727/// # `#[php_extern]` Attribute
712728///
713729/// Attribute used to annotate `extern` blocks which are deemed as PHP
@@ -771,6 +787,7 @@ pub fn php_impl(args: TokenStream, input: TokenStream) -> TokenStream {
771787/// [`strpos`]: https://www.php.net/manual/en/function.strpos.php
772788/// [`IntoZval`]: crate::convert::IntoZval
773789/// [`Zval`]: crate::types::Zval
790+ // END DOCS FROM extern.md
774791#[ proc_macro_attribute]
775792pub fn php_extern ( _: TokenStream , input : TokenStream ) -> TokenStream {
776793 let input = parse_macro_input ! ( input as ItemForeignMod ) ;
@@ -780,6 +797,7 @@ pub fn php_extern(_: TokenStream, input: TokenStream) -> TokenStream {
780797 . into ( )
781798}
782799
800+ // BEGIN DOCS FROM zval_convert.md
783801/// # `ZvalConvert` Derive Macro
784802///
785803/// The `#[derive(ZvalConvert)]` macro derives the `FromZval` and `IntoZval`
@@ -932,6 +950,7 @@ pub fn php_extern(_: TokenStream, input: TokenStream) -> TokenStream {
932950/// test_union(null); // UnionExample::None
933951/// var_dump(give_union()); // int(5)
934952/// ```
953+ // END DOCS FROM zval_convert.md
935954#[ proc_macro_derive( ZvalConvert ) ]
936955pub fn zval_convert_derive ( input : TokenStream ) -> TokenStream {
937956 let input = parse_macro_input ! ( input as DeriveInput ) ;
0 commit comments