|
1 | 1 | mod allocator; |
2 | 2 |
|
3 | | -use allocator::PhpAllocator; |
4 | 3 | use ext_php_rs::{ |
| 4 | + parse_args, |
5 | 5 | php::{ |
| 6 | + args::Arg, |
| 7 | + enums::DataType, |
6 | 8 | exceptions::PhpException, |
| 9 | + execution_data::ExecutionData, |
| 10 | + function::FunctionBuilder, |
7 | 11 | types::{ |
| 12 | + array::OwnedHashTable, |
8 | 13 | callable::Callable, |
9 | 14 | closure::Closure, |
10 | 15 | object::{ClassObject, ClassRef}, |
| 16 | + zval::{FromZval, IntoZval, Zval}, |
11 | 17 | }, |
12 | 18 | }, |
13 | 19 | php_class, |
14 | 20 | prelude::*, |
15 | 21 | }; |
16 | 22 |
|
17 | | -// #[php_function] |
18 | | -// pub fn hello_world() -> String { |
19 | | -// let call = Callable::try_from_name("strpos").unwrap(); |
20 | | - |
21 | | -// eprintln!("im callin"); |
22 | | -// let val = call.try_call(vec![&"hello world", &"w"]); |
23 | | -// dbg!(val); |
24 | | -// "Ok".into() |
25 | | -// } |
26 | | - |
27 | | -// #[php_const] |
28 | | -// const SKEL_TEST_CONST: &str = "Test constant"; |
29 | | -// #[php_const] |
30 | | -// const SKEL_TEST_LONG_CONST: i32 = 1234; |
31 | | - |
32 | | -// #[php_function(optional = "z")] |
33 | | -// pub fn skeleton_version(x: ZendHashTable, y: f64, z: Option<f64>) -> String { |
34 | | -// dbg!(x, y, z); |
35 | | -// "Hello".into() |
36 | | -// } |
37 | | - |
38 | | -// #[php_function(optional = "z")] |
39 | | -// pub fn skeleton_array( |
40 | | -// arr: ZendHashTable, |
41 | | -// x: i32, |
42 | | -// y: f64, |
43 | | -// z: Option<f64>, |
44 | | -// ) -> Result<ZendHashTable, String> { |
45 | | -// for (k, x, y) in arr.iter() { |
46 | | -// println!("{:?} {:?} {:?}", k, x, y.string()); |
47 | | -// } |
48 | | - |
49 | | -// dbg!(x, y, z); |
50 | | - |
51 | | -// let mut new = ZendHashTable::new(); |
52 | | -// new.insert("Hello", &"World") |
53 | | -// .map_err(|_| "Couldn't insert into hashtable")?; |
54 | | -// Ok(new) |
55 | | -// } |
56 | | - |
57 | | -// #[php_function(optional = "i", defaults(i = 5))] |
58 | | -// pub fn test_array(i: i32, b: Option<i32>) -> Vec<i32> { |
59 | | -// dbg!(i, b); |
60 | | -// vec![1, 2, 3, 4] |
61 | | -// } |
62 | | - |
63 | | -// #[php_function(optional = "offset", defaults(offset = 0))] |
64 | | -// pub fn rust_strpos(haystack: &str, needle: &str, offset: i64) -> Option<usize> { |
65 | | -// let haystack = haystack.chars().skip(offset as usize).collect::<String>(); |
66 | | -// haystack.find(needle) |
67 | | -// } |
68 | | - |
69 | | -// #[php_function] |
70 | | -// pub fn example_exception() -> Result<i32, &'static str> { |
71 | | -// Err("Bad here") |
72 | | -// } |
73 | | - |
74 | | -// #[php_function] |
75 | | -// pub fn skel_unpack<'a>( |
76 | | -// mut arr: HashMap<String, String>, |
77 | | -// ) -> Result<HashMap<String, String>, PhpException<'a>> { |
78 | | -// arr.insert("hello".into(), "not world".into()); |
79 | | -// Ok(arr) |
80 | | -// } |
81 | | - |
82 | | -// #[php_function] |
83 | | -// pub fn test_extern() -> i32 { |
84 | | -// // let y = unsafe { strpos("hello", "e", None) }; |
85 | | -// // dbg!(y); |
86 | | -// // let x = unsafe { test_func() }; |
87 | | -// // dbg!(x.try_call(vec![])); |
88 | | -// 0 |
89 | | -// } |
90 | | - |
91 | | -// #[php_function] |
92 | | -// pub fn test_lifetimes<'a>() -> ZendHashTable<'a> { |
93 | | -// ZendHashTable::try_from(&HashMap::<String, String>::new()).unwrap() |
94 | | -// } |
95 | | - |
96 | | -#[php_function] |
97 | | -pub fn test_str(input: &str) -> &str { |
98 | | - input |
99 | | -} |
100 | | - |
101 | | -// #[no_mangle] |
102 | | -// pub extern "C" fn php_module_info(_module: *mut ModuleEntry) { |
103 | | -// info_table_start!(); |
104 | | -// info_table_row!("skeleton extension", "enabled"); |
105 | | -// info_table_end!(); |
106 | | -// } |
107 | | - |
108 | | -// #[php_class(name = "Redis\\Exception\\RedisClientException")] |
109 | | -// #[extends(ClassEntry::exception())] |
110 | | -// #[derive(Default)] |
111 | | -// struct RedisException; |
112 | | - |
113 | | -// #[php_function] |
114 | | -// pub fn test_exception() -> Result<i32, PhpException<'static>> { |
115 | | -// Err(PhpException::from_class::<RedisException>( |
116 | | -// "Hello world".into(), |
117 | | -// )) |
118 | | -// } |
119 | | - |
120 | | -// #[global_allocator] |
121 | | -// static GLOBAL: PhpAllocator = PhpAllocator::new(); |
122 | | - |
123 | 23 | #[php_class] |
124 | 24 | #[property(test = 0)] |
125 | 25 | #[property(another = "Hello world")] |
|
0 commit comments