|
1 | | -// Copyright (c) 2022 PHPER Framework Team |
2 | | -// PHPER is licensed under Mulan PSL v2. |
3 | | -// You can use this software according to the terms and conditions of the Mulan |
4 | | -// PSL v2. You may obtain a copy of Mulan PSL v2 at: |
5 | | -// http://license.coscl.org.cn/MulanPSL2 |
6 | | -// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY |
7 | | -// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
8 | | -// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. |
9 | | -// See the Mulan PSL v2 for more details. |
10 | | - |
11 | | -use phper::{functions::Argument, modules::Module, values::ZVal}; |
12 | | - |
13 | | -pub fn integrate(module: &mut Module) { |
14 | | - register_two_optionals(module); |
15 | | - register_no_optionals(module); |
16 | | - register_exceed_error(module); |
17 | | - register_insufficient_error(module); |
18 | | -} |
19 | | - |
20 | | -fn register_two_optionals(module: &mut Module) { |
21 | | - module |
22 | | - .add_function_with_execute_data( |
23 | | - "materialize_missing_two_optionals", |
24 | | - |execute_data, _arguments| -> phper::Result<String> { |
25 | | - execute_data.materialize_missing([ZVal::from(42), ZVal::from("hello")])?; |
26 | | - let a = execute_data.get_parameter(0).expect_long()?; |
27 | | - let b = execute_data.get_parameter(1).expect_z_str()?.to_str()?; |
28 | | - let c = execute_data.get_parameter(2).expect_long()?; |
29 | | - let d = execute_data.get_parameter(3).expect_z_str()?.to_str()?; |
30 | | - Ok(format!("{}, {}, {}, {}", a, b, c, d)) |
31 | | - }, |
32 | | - ) |
33 | | - .arguments([ |
34 | | - Argument::new("a"), |
35 | | - Argument::new("b"), |
36 | | - Argument::new("c").optional(), |
37 | | - Argument::new("d").optional(), |
38 | | - ]); |
39 | | -} |
40 | | - |
41 | | -fn register_no_optionals(module: &mut Module) { |
42 | | - module |
43 | | - .add_function_with_execute_data( |
44 | | - "materialize_missing_no_optionals", |
45 | | - |execute_data, _arguments| -> phper::Result<String> { |
46 | | - execute_data.materialize_missing([])?; |
47 | | - let a = execute_data.get_parameter(0).expect_long()?; |
48 | | - let b = execute_data.get_parameter(1).expect_z_str()?.to_str()?; |
49 | | - Ok(format!("{}, {}", a, b)) |
50 | | - }, |
51 | | - ) |
52 | | - .arguments([Argument::new("a"), Argument::new("b")]); |
53 | | -} |
54 | | - |
55 | | -fn register_exceed_error(module: &mut Module) { |
56 | | - module |
57 | | - .add_function_with_execute_data( |
58 | | - "materialize_missing_exceed_error", |
59 | | - |execute_data, _arguments| -> phper::Result<String> { |
60 | | - execute_data.materialize_missing([ZVal::from(1), ZVal::from(2), ZVal::from(3)])?; |
61 | | - Ok("ok".to_owned()) |
62 | | - }, |
63 | | - ) |
64 | | - .arguments([Argument::new("a").optional(), Argument::new("b").optional()]); |
65 | | -} |
66 | | - |
67 | | -fn register_insufficient_error(module: &mut Module) { |
68 | | - module |
69 | | - .add_function_with_execute_data( |
70 | | - "materialize_missing_insufficient_error", |
71 | | - |execute_data, _arguments| -> phper::Result<String> { |
72 | | - execute_data.materialize_missing(std::iter::empty())?; |
73 | | - Ok("ok".to_owned()) |
74 | | - }, |
75 | | - ) |
76 | | - .arguments([Argument::new("a").optional(), Argument::new("b").optional()]); |
77 | | -} |
0 commit comments