-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_function_type.v
More file actions
104 lines (85 loc) · 2.51 KB
/
php_function_type.v
File metadata and controls
104 lines (85 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module vphp
pub struct PhpFunction {
fn_name string
}
pub fn PhpFunction.named(name string) PhpFunction {
return PhpFunction{
fn_name: name
}
}
pub fn PhpFunction.find(name string) ?PhpFunction {
if !function_exists(name) {
return none
}
return PhpFunction.named(name)
}
pub fn (f PhpFunction) name() string {
return f.fn_name
}
pub fn (f PhpFunction) to_zval() ZVal {
return ZVal.new_string(f.fn_name)
}
pub fn (f PhpFunction) exists() bool {
return PhpFunction.named('function_exists').result_bool(PhpString.of(f.fn_name))
}
pub fn (f PhpFunction) call_zval(args []vphp.ZVal) ZVal {
return f.to_zval().call(args)
}
pub fn (f PhpFunction) call_owned_request_zval(args []vphp.ZVal) ZVal {
return f.to_zval().call_owned_request(args)
}
pub fn (f PhpFunction) call_owned_persistent_zval(args []vphp.ZVal) ZVal {
return f.to_zval().call_owned_persistent(args)
}
fn (f PhpFunction) request_owned_zval(args []vphp.ZVal) RequestOwnedZBox {
return RequestOwnedZBox.adopt_zval(f.call_owned_request_zval(args))
}
fn (f PhpFunction) request_owned(args ...PhpArgInput) RequestOwnedZBox {
return f.request_owned_zval(php_arg_inputs_to_zvals(args))
}
pub fn (f PhpFunction) invoke(args ...PhpArgInput) PhpValue {
mut result := f.request_owned(args)
return result.take_value()
}
pub fn (f PhpFunction) call[T](args ...PhpArgInput) !T {
mut result := f.request_owned(args)
defer {
result.release()
}
return php_call_copied_result_as[T](result.to_zval())
}
pub fn (f PhpFunction) with_result[T, R](run fn (T) R, args ...PhpArgInput) !R {
mut result := f.request_owned(args)
defer {
result.release()
}
value := php_call_result_as[T](result.to_zval())!
return run(value)
}
pub fn (f PhpFunction) with_result_zval[T](run fn (ZVal) T, args ...ZVal) T {
mut result := f.request_owned_zval(args)
defer {
result.release()
}
return run(result.to_zval())
}
pub fn (f PhpFunction) result_string(args ...PhpArgInput) string {
return f.with_result[PhpString, string](fn (z PhpString) string {
return z.value()
}, ...args) or { '' }
}
pub fn (f PhpFunction) result_bool(args ...PhpArgInput) bool {
return f.with_result[PhpBool, bool](fn (z PhpBool) bool {
return z.value()
}, ...args) or { false }
}
pub fn (f PhpFunction) result_i64(args ...PhpArgInput) i64 {
return f.with_result[PhpInt, i64](fn (z PhpInt) i64 {
return z.value()
}, ...args) or { 0 }
}
pub fn (f PhpFunction) result_double(args ...PhpArgInput) f64 {
return f.with_result[PhpDouble, f64](fn (z PhpDouble) f64 {
return z.value()
}, ...args) or { 0.0 }
}