-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphp_daytime.c
More file actions
306 lines (232 loc) · 6.56 KB
/
Copy pathphp_daytime.c
File metadata and controls
306 lines (232 loc) · 6.56 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/pcre/php_pcre.h"
#include "zend_exceptions.h"
#include "Zend/zend_interfaces.h"
#include "Zend/zend_smart_str.h"
#include "Zend/zend_types.h"
#include "daytime_arginfo.h"
#include "src/daytime.h"
#include "php_daytime.h"
zend_object_handlers obj_handler_DayTime;
zend_class_entry *zt_ce_DayTime;
#define REGISTER_DAYTIME_CONST_LONG(const_name, value) \
zend_declare_class_constant_long(zt_ce_DayTime, const_name, sizeof(const_name)-1, (zend_long)value);
#include "fn_daytime.c"
PHP_METHOD(DayTime, __construct)
{
zval *object = ZEND_THIS;
char* src;
long slen;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(src, slen)
ZEND_PARSE_PARAMETERS_END();
p_daytime pz = ZP_DAYTIME_P(object);
char* error = sto_daytime(src, slen, &pz->daytime.tval);
if (error) {
zend_throw_exception(zend_ce_exception,error,0);
}
}
PHP_METHOD(DayTime, str)
{
zval *object = ZEND_THIS;
char* src;
long slen;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(src, slen)
ZEND_PARSE_PARAMETERS_END();
p_daytime pz = ZP_DAYTIME_P(object);
char* error = sto_daytime(src, slen, &pz->daytime.tval);
if (error) {
zend_throw_exception(zend_ce_exception,error,0);
}
}
PHP_METHOD(DayTime, set)
{
zval *object = ZEND_THIS;
long hours;
long mins;
double secs;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_LONG(hours)
Z_PARAM_LONG(mins)
Z_PARAM_DOUBLE(secs)
ZEND_PARSE_PARAMETERS_END();
p_daytime pz = ZP_DAYTIME_P(object);
char* error = daytime_set(hours,mins,secs, &pz->daytime.tval);
if (error) {
zend_throw_exception(zend_ce_exception,error,0);
}
}
PHP_METHOD(DayTime, split)
{
zval *object = ZEND_THIS;
zval* hours;
zval* mins;
zval* secs;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_ZVAL(hours)
Z_PARAM_ZVAL(mins)
Z_PARAM_ZVAL(secs)
ZEND_PARSE_PARAMETERS_END();
int h24, m60;
double s60;
p_daytime pz = ZP_DAYTIME_P(object);
daytime_split(pz->daytime.tval, &h24, &m60, &s60);
ZVAL_LONG(Z_REFVAL_P(hours), h24);
ZVAL_LONG(Z_REFVAL_P(mins), m60);
ZVAL_DOUBLE(Z_REFVAL_P(secs), s60);
}
PHP_METHOD(DayTime, format)
{
zval *object = ZEND_THIS;
long flags = 0;
zend_string *result;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
ZEND_PARSE_PARAMETERS_END();
p_daytime pz = ZP_DAYTIME_P(object);
result = daytime_format(pz->daytime.tval,flags);
ZVAL_STR(return_value, result);
}
PHP_METHOD(DayTime, day)
{
zval *object = ZEND_THIS;
double value;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_DOUBLE(value);
ZEND_PARSE_PARAMETERS_END();
p_daytime pz = ZP_DAYTIME_P(object);
if (value < 0.0 || value >= 1.0) {
zend_throw_exception(zend_ce_exception,"Value must be positive fraction",0);
}
pz->daytime.tval = value;
}
PHP_METHOD(DayTime, value)
{
zval *object = ZEND_THIS;
ZEND_PARSE_PARAMETERS_NONE();
p_daytime pz = ZP_DAYTIME_P(object);
ZVAL_DOUBLE(return_value, pz->daytime.tval);
}
PHP_METHOD(DayTime, __toString)
{
zval *object = ZEND_THIS;
zend_string *result;
ZEND_PARSE_PARAMETERS_NONE();
p_daytime pz = ZP_DAYTIME_P(object);
result = daytime_format(pz->daytime.tval,DAYT_SEC_AUTO);
ZVAL_STR(return_value, result);
}
static void t_daytime_copy_ctor( p_daytime to, p_daytime from)
{
}
static zend_object *t_daytime_new_ex(zend_class_entry *class_type,
zend_object *orig, bool clone_orig)
{
p_daytime intern;
zend_class_entry *parent = class_type;
bool inherited = false;
intern = zend_object_alloc(sizeof(t_daytime), class_type);
intern->daytime.tval = 0.0;
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
if (orig && clone_orig) {
p_daytime other = p_daytime_from_obj(orig);
t_daytime_copy_ctor(intern, other);
}
while(parent) {
if (parent == zt_ce_DayTime) {
intern->std.handlers = &obj_handler_DayTime;
break;
}
parent = parent->parent;
inherited = true;
}
ZEND_ASSERT(parent);
return &intern->std;
}
static zend_object *t_daytime_new(zend_class_entry *class_type)
{
return t_daytime_new_ex(class_type, NULL, 0);
}
static zend_object *t_daytime_clone(zend_object *old_object)
{
zend_object *new_object = t_daytime_new_ex(old_object->ce, old_object, 1);
zend_objects_clone_members(new_object, old_object);
return new_object;
}
static void t_daytime_free_storage(zend_object *object)
{
p_daytime intern = p_daytime_from_obj(object);
zend_object_std_dtor(&intern->std);
}
PHPAPI void
t_register_std_class(zend_class_entry ** ppce,
char * class_name,
const zend_function_entry* function_list)
{
zend_class_entry ce;
INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
*ppce = zend_register_internal_class(&ce);
}
PHP_MINIT_FUNCTION(t_daytime)
{
t_register_std_class(&zt_ce_DayTime, "DayTime", class_DayTime_methods);
zt_ce_DayTime->create_object = t_daytime_new;
memcpy(&obj_handler_DayTime, &std_object_handlers, sizeof(zend_object_handlers));
obj_handler_DayTime.offset = XtOffsetOf(t_daytime, std);
obj_handler_DayTime.clone_obj = t_daytime_clone;
obj_handler_DayTime.dtor_obj = zend_objects_destroy_object;
obj_handler_DayTime.free_obj = t_daytime_free_storage;
REGISTER_DAYTIME_CONST_LONG("DAYT_SEC_AUTO", (zend_long)DAYT_SEC_AUTO);
REGISTER_DAYTIME_CONST_LONG("DAYT_SEC_INT", (zend_long)DAYT_SEC_INT);
REGISTER_DAYTIME_CONST_LONG("DAYT_SEC_DEC", (zend_long)DAYT_SEC_DEC);
REGISTER_DAYTIME_CONST_LONG("DAYT_SEC_NONE", (zend_long)DAYT_SEC_NONE);
}
PHP_MINIT_FUNCTION(daytime)
{
PHP_MINIT(t_daytime)(INIT_FUNC_ARGS_PASSTHRU);
}
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(daytime)
{
#if defined(ZTS) && defined(COMPILE_DL_DAYTIME)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(daytime)
{
php_info_print_table_start();
php_info_print_table_header(2, "daytime support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ daytime_module_entry */
zend_module_entry daytime_module_entry = {
STANDARD_MODULE_HEADER,
"daytime", /* Extension name */
ext_functions, /* zend_function_entry */
PHP_MINIT(daytime), /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(daytime), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(daytime), /* PHP_MINFO - Module info */
PHP_DAYTIME_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_DAYTIME
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(daytime)
#endif