blob: 3cb0e2dc87192f54cc11b3d94b5bf7d7110bd6ee (
plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/**
* Function.h
*
* Object represents a callable function that is defined with the CPP API.
* After you've instantiated the extension, you can add function objects to
* it.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2013 Copernica BV
*/
/**
* Forward definitions
*/
struct _zend_function_entry;
struct _zend_internal_function_info;
/**
* Set up namespace
*/
namespace Php {
/**
* Class definition
*/
class Function
{
public:
/**
* Constructor
* @param name Name of the function
* @param min Min number of arguments
* @param max Max number of arguments
*/
Function(const char *name, const std::initializer_list<Argument> &arguments = {});
/**
* No copy and move constructors
* @param function The other function
*/
Function(const Function &function) = delete;
Function(Function &&function) = delete;
/**
* Destructor
*/
virtual ~Function();
/**
* No assignment operator
* @param function The other function
* @return Function
*/
Function &operator=(const Function &function) = delete;
/**
* Comparison
* @param function The other function
* @return bool
*/
bool operator<(const Function &function) const
{
return strcmp(name(), function.name()) < 0;
}
/**
* Comparison
* @param function The other function
* @return bool
*/
bool operator>(const Function &function) const
{
return strcmp(name(), function.name()) > 0;
}
/**
* Comparison
* @param function The other function
* @return bool
*/
bool operator==(const Function &function) const
{
return strcmp(name(), function.name()) == 0;
}
/**
* Function name
* @return const char *
*/
const char *name() const
{
return _ptr.text();
}
/**
* Method that gets called every time the function is executed
* @param environment Environment object
* @param params The parameters that were passed
* @return Variable Return value
*/
virtual Value invoke(Environment &environment, Parameters ¶ms)
{
return nullptr;
}
protected:
/**
* Suggestion for the return type
* @var Type
*/
Type _type = nullType;
/**
* Required number of arguments
* @var integer
*/
int _required;
/**
* Total number of arguments
* @var integer
*/
int _argc;
/**
* The arguments
* @var zend_arg_info[]
*/
struct _zend_arg_info *_argv;
/**
* The object address is stored in a hidden pointer, so that we have access to the function object
* @var HiddenPointer
*/
HiddenPointer<Function> _ptr;
protected:
/**
* Fill a function entry
* @param entry Entry to be filled
* @param classname Optional class name
*/
void fill(struct _zend_function_entry *entry, const char *classname=NULL) const;
/**
* Fill function info
* @param info Info object to be filled
* @param classname Optional class name
*/
void fill(struct _zend_internal_function_info *info, const char *classname=NULL) const;
/**
* Extension has access to the private members
*/
friend class Extension;
};
/**
* End of namespace
*/
}
|