|
1 | 1 | #![cfg_attr(windows, feature(abi_vectorcall))]
|
2 |
| -use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval}; |
3 |
| -use std::collections::HashMap; |
| 2 | +use ext_php_rs::prelude::php_module; |
4 | 3 |
|
5 |
| -#[php_function] |
6 |
| -pub fn test_str(a: &str) -> &str { |
7 |
| - a |
8 |
| -} |
9 |
| - |
10 |
| -#[php_function] |
11 |
| -pub fn test_string(a: String) -> String { |
12 |
| - a |
13 |
| -} |
14 |
| - |
15 |
| -#[php_function] |
16 |
| -pub fn test_bool(a: bool) -> bool { |
17 |
| - a |
18 |
| -} |
19 |
| - |
20 |
| -#[php_function] |
21 |
| -pub fn test_number_signed(a: i32) -> i32 { |
22 |
| - a |
23 |
| -} |
| 4 | +#[php_module] |
| 5 | +mod module { |
| 6 | + use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval}; |
| 7 | + use std::collections::HashMap; |
24 | 8 |
|
25 |
| -#[php_function] |
26 |
| -pub fn test_number_unsigned(a: u32) -> u32 { |
27 |
| - a |
28 |
| -} |
| 9 | + #[php_function()] |
| 10 | + pub fn test_str(a: &str) -> &str { |
| 11 | + a |
| 12 | + } |
29 | 13 |
|
30 |
| -#[php_function] |
31 |
| -pub fn test_number_float(a: f32) -> f32 { |
32 |
| - a |
33 |
| -} |
| 14 | + #[php_function()] |
| 15 | + pub fn test_string(a: String) -> String { |
| 16 | + a |
| 17 | + } |
34 | 18 |
|
35 |
| -#[php_function] |
36 |
| -pub fn test_array(a: Vec<String>) -> Vec<String> { |
37 |
| - a |
38 |
| -} |
| 19 | + #[php_function()] |
| 20 | + pub fn test_bool(a: bool) -> bool { |
| 21 | + a |
| 22 | + } |
39 | 23 |
|
40 |
| -#[php_function] |
41 |
| -pub fn test_array_assoc(a: HashMap<String, String>) -> HashMap<String, String> { |
42 |
| - a |
43 |
| -} |
| 24 | + #[php_function()] |
| 25 | + pub fn test_number_signed(a: i32) -> i32 { |
| 26 | + a |
| 27 | + } |
44 | 28 |
|
45 |
| -#[php_function] |
46 |
| -pub fn test_binary(a: Binary<u32>) -> Binary<u32> { |
47 |
| - a |
48 |
| -} |
| 29 | + #[php_function()] |
| 30 | + pub fn test_number_unsigned(a: u32) -> u32 { |
| 31 | + a |
| 32 | + } |
49 | 33 |
|
50 |
| -#[php_function] |
51 |
| -pub fn test_nullable(a: Option<String>) -> Option<String> { |
52 |
| - a |
53 |
| -} |
| 34 | + #[php_function()] |
| 35 | + pub fn test_number_float(a: f32) -> f32 { |
| 36 | + a |
| 37 | + } |
54 | 38 |
|
55 |
| -#[php_function] |
56 |
| -pub fn test_object(a: &mut ZendObject) -> &mut ZendObject { |
57 |
| - a |
58 |
| -} |
| 39 | + #[php_function()] |
| 40 | + pub fn test_array(a: Vec<String>) -> Vec<String> { |
| 41 | + a |
| 42 | + } |
59 | 43 |
|
60 |
| -#[php_function] |
61 |
| -pub fn test_closure() -> Closure { |
62 |
| - Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>) |
63 |
| -} |
| 44 | + #[php_function()] |
| 45 | + pub fn test_array_assoc(a: HashMap<String, String>) -> HashMap<String, String> { |
| 46 | + a |
| 47 | + } |
64 | 48 |
|
65 |
| -#[php_function] |
66 |
| -pub fn test_closure_once(a: String) -> Closure { |
67 |
| - Closure::wrap_once(Box::new(move || a) as Box<dyn FnOnce() -> String>) |
68 |
| -} |
| 49 | + #[php_function()] |
| 50 | + pub fn test_binary(a: Binary<u32>) -> Binary<u32> { |
| 51 | + a |
| 52 | + } |
69 | 53 |
|
70 |
| -#[php_function] |
71 |
| -pub fn test_callable(call: ZendCallable, a: String) -> Zval { |
72 |
| - call.try_call(vec![&a]).expect("Failed to call function") |
73 |
| -} |
| 54 | + #[php_function()] |
| 55 | + pub fn test_nullable(a: Option<String>) -> Option<String> { |
| 56 | + a |
| 57 | + } |
74 | 58 |
|
75 |
| -#[php_class] |
76 |
| -pub struct TestClass { |
77 |
| - string: String, |
78 |
| - number: i32, |
79 |
| - #[prop] |
80 |
| - boolean: bool, |
81 |
| -} |
| 59 | + #[php_function()] |
| 60 | + pub fn test_object(a: &mut ZendObject) -> &mut ZendObject { |
| 61 | + a |
| 62 | + } |
82 | 63 |
|
83 |
| -#[php_impl] |
84 |
| -impl TestClass { |
85 |
| - #[getter] |
86 |
| - pub fn get_string(&self) -> String { |
87 |
| - self.string.to_string() |
| 64 | + #[php_function()] |
| 65 | + pub fn test_closure() -> Closure { |
| 66 | + Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>) |
88 | 67 | }
|
89 | 68 |
|
90 |
| - #[setter] |
91 |
| - pub fn set_string(&mut self, string: String) { |
92 |
| - self.string = string; |
| 69 | + #[php_function()] |
| 70 | + pub fn test_closure_once(a: String) -> Closure { |
| 71 | + Closure::wrap_once(Box::new(move || a) as Box<dyn FnOnce() -> String>) |
93 | 72 | }
|
94 | 73 |
|
95 |
| - #[getter] |
96 |
| - pub fn get_number(&self) -> i32 { |
97 |
| - self.number |
| 74 | + #[php_function()] |
| 75 | + pub fn test_callable(call: ZendCallable, a: String) -> Zval { |
| 76 | + call.try_call(vec![&a]).expect("Failed to call function") |
98 | 77 | }
|
99 | 78 |
|
100 |
| - #[setter] |
101 |
| - pub fn set_number(&mut self, number: i32) { |
102 |
| - self.number = number; |
| 79 | + #[php_class] |
| 80 | + pub struct TestClass { |
| 81 | + string: String, |
| 82 | + number: i32, |
| 83 | + #[prop] |
| 84 | + boolean: bool, |
103 | 85 | }
|
104 |
| -} |
105 | 86 |
|
106 |
| -#[php_function] |
107 |
| -pub fn test_class(string: String, number: i32) -> TestClass { |
108 |
| - TestClass { |
109 |
| - string, |
110 |
| - number, |
111 |
| - boolean: true, |
| 87 | + #[php_impl] |
| 88 | + impl TestClass { |
| 89 | + #[getter] |
| 90 | + pub fn get_string(&self) -> String { |
| 91 | + self.string.to_string() |
| 92 | + } |
| 93 | + |
| 94 | + #[setter] |
| 95 | + pub fn set_string(&mut self, string: String) { |
| 96 | + self.string = string; |
| 97 | + } |
| 98 | + |
| 99 | + #[getter] |
| 100 | + pub fn get_number(&self) -> i32 { |
| 101 | + self.number |
| 102 | + } |
| 103 | + |
| 104 | + #[setter] |
| 105 | + pub fn set_number(&mut self, number: i32) { |
| 106 | + self.number = number; |
| 107 | + } |
112 | 108 | }
|
113 |
| -} |
114 | 109 |
|
115 |
| -#[php_module] |
116 |
| -pub fn get_module(module: ModuleBuilder) -> ModuleBuilder { |
117 |
| - module |
| 110 | + #[php_function()] |
| 111 | + pub fn test_class(string: String, number: i32) -> TestClass { |
| 112 | + TestClass { |
| 113 | + string, |
| 114 | + number, |
| 115 | + boolean: true, |
| 116 | + } |
| 117 | + } |
118 | 118 | }
|
119 | 119 |
|
120 | 120 | #[cfg(test)]
|
|
0 commit comments