-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation_ext.c
More file actions
174 lines (140 loc) · 5.03 KB
/
Copy pathvalidation_ext.c
File metadata and controls
174 lines (140 loc) · 5.03 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
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
165
166
167
168
169
170
171
172
173
174
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "Zend/zend_API.h"
#include "Zend/zend_interfaces.h"
#include "Zend/zend_exceptions.h"
#include "Zend/zend_inheritance.h"
#include "ext/standard/info.h"
#include "validation_ext.h"
/* Class entries */
zend_class_entry *validation_ext_Validator_ce;
zend_class_entry *validation_ext_Validatable_ce;
/* Object definition */
typedef struct {
zend_object std;
} validation_ext_Validator_object;
static inline validation_ext_Validator_object *validation_ext_Validator_fetch_object(zend_object *obj) {
return (validation_ext_Validator_object *)((char *)obj - XtOffsetOf(validation_ext_Validator_object, std));
}
/* Object handlers */
static zend_object_handlers validation_ext_Validator_handlers;
/* Method declarations */
PHP_METHOD(Validation_Validator, __construct);
PHP_METHOD(Validation_Validator, validate);
PHP_METHOD(Validation_Validator, validateCallable);
/* Argument info */
ZEND_BEGIN_ARG_INFO_EX(arginfo_Validation_Validator___construct, 0, 0, 0)
ZEND_ARG_INFO(0, validator)
ZEND_ARG_INFO(0, stopFirstError)
ZEND_ARG_INFO(0, strict)
ZEND_ARG_INFO(0, context)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_Validation_Validator_validate, 0, 0, 2)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, model)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_Validation_Validator_validateCallable, 0, 0, 2)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, call)
ZEND_END_ARG_INFO()
/* Method entries for Validator class */
static zend_function_entry validation_ext_Validator_methods[] = {
PHP_ME(Validation_Validator, __construct, arginfo_Validation_Validator___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Validation_Validator, validate, arginfo_Validation_Validator_validate, ZEND_ACC_PUBLIC)
PHP_ME(Validation_Validator, validateCallable, arginfo_Validation_Validator_validateCallable, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* Object creation and destruction */
static zend_object *validation_ext_Validator_create_object(zend_class_entry *ce)
{
validation_ext_Validator_object *obj = (validation_ext_Validator_object *)zend_object_alloc(sizeof(validation_ext_Validator_object), ce);
zend_object_std_init(&obj->std, ce);
object_properties_init(&obj->std, ce);
return &obj->std;
}
static void validation_ext_Validator_free_object(zend_object *object)
{
validation_ext_Validator_object *obj = validation_ext_Validator_fetch_object(object);
zend_object_std_dtor(&obj->std);
}
/* Method implementations */
PHP_METHOD(Validation_Validator, __construct)
{
zend_bool stopFirstError = 0;
zend_bool strict = 0;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(stopFirstError)
Z_PARAM_BOOL(strict)
ZEND_PARSE_PARAMETERS_END();
validation_ext_Validator_object *obj = validation_ext_Validator_fetch_object(Z_OBJ_P(getThis()));
}
PHP_METHOD(Validation_Validator, validate)
{
// Empty implementation as requested
}
PHP_METHOD(Validation_Validator, validateCallable)
{
// Empty implementation as requested
}
/* Module startup */
PHP_MINIT_FUNCTION(validation_ext)
{
zend_class_entry ce;
/* Register Validatable interface */
INIT_CLASS_ENTRY(ce, "Attributes\\Validation\\Validatable", NULL);
validation_ext_Validatable_ce = zend_register_internal_interface(&ce);
/* Register Validator class */
INIT_CLASS_ENTRY(ce, "Attributes\\Validation\\Validator", validation_ext_Validator_methods);
ce.create_object = validation_ext_Validator_create_object;
validation_ext_Validator_ce = zend_register_internal_class(&ce);
/* Setup object handlers */
memcpy(&validation_ext_Validator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
validation_ext_Validator_handlers.offset = XtOffsetOf(validation_ext_Validator_object, std);
validation_ext_Validator_handlers.free_obj = validation_ext_Validator_free_object;
validation_ext_Validator_handlers.clone_obj = NULL;
/* Implement Validatable interface */
zend_do_implement_interface(validation_ext_Validator_ce, validation_ext_Validatable_ce);
return SUCCESS;
}
/* Module shutdown */
PHP_MSHUTDOWN_FUNCTION(validation_ext)
{
return SUCCESS;
}
/* Request startup */
PHP_RINIT_FUNCTION(validation_ext)
{
return SUCCESS;
}
/* Request shutdown */
PHP_RSHUTDOWN_FUNCTION(validation_ext)
{
return SUCCESS;
}
/* Module info */
PHP_MINFO_FUNCTION(validation_ext)
{
php_info_print_table_start();
php_info_print_table_header(2, "validation_ext", "enabled");
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* Module entry */
zend_module_entry validation_ext_module_entry = {
STANDARD_MODULE_HEADER,
VALIDATION_EXT_NAME,
NULL, /* Function entries */
PHP_MINIT(validation_ext),
PHP_MSHUTDOWN(validation_ext),
PHP_RINIT(validation_ext),
PHP_RSHUTDOWN(validation_ext),
PHP_MINFO(validation_ext),
VALIDATION_EXT_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_VALIDATION_EXT
ZEND_GET_MODULE(validation_ext)
#endif