@@ -18,6 +18,7 @@ use syn::{
18
18
19
19
extern crate proc_macro;
20
20
21
+ // BEGIN DOCS FROM classes.md
21
22
/// # `#[php_class]` Attribute
22
23
///
23
24
/// Structs can be exported to PHP as classes with the `#[php_class]` attribute
@@ -33,7 +34,7 @@ extern crate proc_macro;
33
34
/// - `name` - Changes the name of the class when exported to PHP. The Rust
34
35
/// struct name is kept the same. If no name is given, the name of the struct
35
36
/// 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.
37
38
/// - `#[php(extends(ce = ce_fn, stub = "ParentClass"))]` - Sets the parent
38
39
/// class of the class. Can only be used once. `ce_fn` must be a function with
39
40
/// the signature `fn() -> &'static ClassEntry`.
@@ -50,8 +51,8 @@ extern crate proc_macro;
50
51
///
51
52
/// - `name` - Allows you to rename the property, e.g. `#[php(name =
52
53
/// "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)]`
55
56
///
56
57
/// ## Restrictions
57
58
///
@@ -199,6 +200,7 @@ extern crate proc_macro;
199
200
/// }
200
201
/// # fn main() {}
201
202
/// ````
203
+ // END DOCS FROM classes.md
202
204
#[ proc_macro_attribute]
203
205
pub fn php_class ( args : TokenStream , input : TokenStream ) -> TokenStream {
204
206
let input = parse_macro_input ! ( input as ItemStruct ) ;
@@ -211,6 +213,7 @@ pub fn php_class(args: TokenStream, input: TokenStream) -> TokenStream {
211
213
. into ( )
212
214
}
213
215
216
+ // BEGIN DOCS FROM function.md
214
217
/// # `#[php_function]` Attribute
215
218
///
216
219
/// 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 {
365
368
/// You can also return a `Result` from the function. The error variant will be
366
369
/// translated into an exception and thrown. See the section on
367
370
/// [exceptions](../exceptions.md) for more details.
371
+ // END DOCS FROM function.md
368
372
#[ proc_macro_attribute]
369
373
pub fn php_function ( args : TokenStream , input : TokenStream ) -> TokenStream {
370
374
let input = parse_macro_input ! ( input as ItemFn ) ;
@@ -377,6 +381,7 @@ pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
377
381
. into ( )
378
382
}
379
383
384
+ // BEGIN DOCS FROM constant.md
380
385
/// # `#[php_const]` Attribute
381
386
///
382
387
/// 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 {
389
394
///
390
395
/// - `name` - Allows you to rename the property, e.g. `#[php(name =
391
396
/// "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)]`
394
399
///
395
400
/// ## Examples
396
401
///
@@ -428,6 +433,7 @@ pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
428
433
/// var_dump(I_AM_RENAMED); // int(42)
429
434
/// var_dump(MANUAL_CONSTANT); // string(12) "Hello world!"
430
435
/// ```
436
+ // END DOCS FROM constant.md
431
437
#[ proc_macro_attribute]
432
438
pub fn php_const ( args : TokenStream , input : TokenStream ) -> TokenStream {
433
439
let input = parse_macro_input ! ( input as ItemConst ) ;
@@ -440,6 +446,7 @@ pub fn php_const(args: TokenStream, input: TokenStream) -> TokenStream {
440
446
. into ( )
441
447
}
442
448
449
+ // BEGIN DOCS FROM module.md
443
450
/// # `#[php_module]` Attribute
444
451
///
445
452
/// 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 {
506
513
/// }
507
514
/// # fn main() {}
508
515
/// ```
516
+ // END DOCS FROM module.md
509
517
#[ proc_macro_attribute]
510
518
pub fn php_module ( args : TokenStream , input : TokenStream ) -> TokenStream {
511
519
let input = parse_macro_input ! ( input as ItemFn ) ;
@@ -518,6 +526,7 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
518
526
. into ( )
519
527
}
520
528
529
+ // BEGIN DOCS FROM impl.md
521
530
/// # `#[php_impl]` Attribute
522
531
///
523
532
/// 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 {
532
541
/// If you want to use async Rust, use `#[php_async_impl]`, instead: see [here
533
542
/// »](./async_impl.md) for more info.
534
543
///
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
+ ///
535
559
/// ## Methods
536
560
///
537
561
/// 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 {
546
570
/// must be named `self_`. This can also be used to return a reference to
547
571
/// `$this`.
548
572
///
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
- ///
560
573
/// The rest of the options are passed as separate attributes:
561
574
///
562
575
/// - `#[php(defaults(i = 5, b = "hello")]` - Sets the default value for
@@ -602,8 +615,9 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
602
615
/// attributes. By default, the `get_` or `set_` prefix is trimmed from the
603
616
/// start of the function name, and the remainder is used as the property name.
604
617
///
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.
607
621
///
608
622
/// Properties do not necessarily have to have both a getter and a setter, if
609
623
/// 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 {
696
710
/// ```
697
711
///
698
712
/// [`php_async_impl`]: ./async_impl.md
713
+ // END DOCS FROM impl.md
699
714
#[ proc_macro_attribute]
700
715
pub fn php_impl ( args : TokenStream , input : TokenStream ) -> TokenStream {
701
716
let input = parse_macro_input ! ( input as ItemImpl ) ;
@@ -708,6 +723,7 @@ pub fn php_impl(args: TokenStream, input: TokenStream) -> TokenStream {
708
723
. into ( )
709
724
}
710
725
726
+ // BEGIN DOCS FROM extern.md
711
727
/// # `#[php_extern]` Attribute
712
728
///
713
729
/// Attribute used to annotate `extern` blocks which are deemed as PHP
@@ -771,6 +787,7 @@ pub fn php_impl(args: TokenStream, input: TokenStream) -> TokenStream {
771
787
/// [`strpos`]: https://www.php.net/manual/en/function.strpos.php
772
788
/// [`IntoZval`]: crate::convert::IntoZval
773
789
/// [`Zval`]: crate::types::Zval
790
+ // END DOCS FROM extern.md
774
791
#[ proc_macro_attribute]
775
792
pub fn php_extern ( _: TokenStream , input : TokenStream ) -> TokenStream {
776
793
let input = parse_macro_input ! ( input as ItemForeignMod ) ;
@@ -780,6 +797,7 @@ pub fn php_extern(_: TokenStream, input: TokenStream) -> TokenStream {
780
797
. into ( )
781
798
}
782
799
800
+ // BEGIN DOCS FROM zval_convert.md
783
801
/// # `ZvalConvert` Derive Macro
784
802
///
785
803
/// The `#[derive(ZvalConvert)]` macro derives the `FromZval` and `IntoZval`
@@ -932,6 +950,7 @@ pub fn php_extern(_: TokenStream, input: TokenStream) -> TokenStream {
932
950
/// test_union(null); // UnionExample::None
933
951
/// var_dump(give_union()); // int(5)
934
952
/// ```
953
+ // END DOCS FROM zval_convert.md
935
954
#[ proc_macro_derive( ZvalConvert ) ]
936
955
pub fn zval_convert_derive ( input : TokenStream ) -> TokenStream {
937
956
let input = parse_macro_input ! ( input as DeriveInput ) ;
0 commit comments