26
26
#include "php_ini.h"
27
27
#include "ext/standard/info.h"
28
28
#include "php_timecop.h"
29
+ #include <time.h>
29
30
30
31
/* If you declare any globals in php_timecop.h uncomment this:
31
32
ZEND_DECLARE_MODULE_GLOBALS(timecop)
@@ -39,7 +40,7 @@ static int le_timecop;
39
40
* Every user visible function must have an entry in timecop_functions[].
40
41
*/
41
42
const zend_function_entry timecop_functions [] = {
42
- PHP_FE (confirm_timecop_compiled , NULL ) /* For testing, remove later. */
43
+ PHP_FE (timecop_time , NULL )
43
44
PHP_FE_END /* Must be the last line in timecop_functions[] */
44
45
};
45
46
/* }}} */
@@ -54,11 +55,11 @@ zend_module_entry timecop_module_entry = {
54
55
timecop_functions ,
55
56
PHP_MINIT (timecop ),
56
57
PHP_MSHUTDOWN (timecop ),
57
- PHP_RINIT ( timecop ), /* Replace with NULL if there's nothing to do at request start */
58
- PHP_RSHUTDOWN ( timecop ), /* Replace with NULL if there's nothing to do at request end */
58
+ NULL ,
59
+ NULL ,
59
60
PHP_MINFO (timecop ),
60
61
#if ZEND_MODULE_API_NO >= 20010901
61
- "0.1" , /* Replace with version number for your extension */
62
+ "0.1" ,
62
63
#endif
63
64
STANDARD_MODULE_PROPERTIES
64
65
};
@@ -111,30 +112,12 @@ PHP_MSHUTDOWN_FUNCTION(timecop)
111
112
}
112
113
/* }}} */
113
114
114
- /* Remove if there's nothing to do at request start */
115
- /* {{{ PHP_RINIT_FUNCTION
116
- */
117
- PHP_RINIT_FUNCTION (timecop )
118
- {
119
- return SUCCESS ;
120
- }
121
- /* }}} */
122
-
123
- /* Remove if there's nothing to do at request end */
124
- /* {{{ PHP_RSHUTDOWN_FUNCTION
125
- */
126
- PHP_RSHUTDOWN_FUNCTION (timecop )
127
- {
128
- return SUCCESS ;
129
- }
130
- /* }}} */
131
-
132
115
/* {{{ PHP_MINFO_FUNCTION
133
116
*/
134
117
PHP_MINFO_FUNCTION (timecop )
135
118
{
136
119
php_info_print_table_start ();
137
- php_info_print_table_header (2 , "timecop support " , "enabled" );
120
+ php_info_print_table_header (2 , "timecop" , "enabled" );
138
121
php_info_print_table_end ();
139
122
140
123
/* Remove comments if you have entries in php.ini
@@ -144,25 +127,22 @@ PHP_MINFO_FUNCTION(timecop)
144
127
/* }}} */
145
128
146
129
147
- /* Remove the following function when you have succesfully modified config.m4
148
- so that your module can be compiled into PHP, it exists only for testing
149
- purposes. */
150
-
151
- /* Every user-visible function in PHP should document itself in the source */
152
- /* {{{ proto string confirm_timecop_compiled(string arg)
153
- Return a string to confirm that the module is compiled in */
154
- PHP_FUNCTION (confirm_timecop_compiled )
130
+ /* {{{ proto int timecop_time(void)
131
+ Return timestamp for $_SERVER[request_time] */
132
+ PHP_FUNCTION (timecop_time )
155
133
{
156
- char * arg = NULL ;
157
- int arg_len , len ;
158
- char * strg ;
159
-
160
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & arg , & arg_len ) == FAILURE ) {
161
- return ;
134
+ zval * * array , * * request_time_long ;
135
+ long ret ;
136
+ if (zend_hash_find (& EG (symbol_table ), "_SERVER" , sizeof ("_SERVER" ), (void * * ) & array ) == SUCCESS &&
137
+ Z_TYPE_PP (array ) == IS_ARRAY &&
138
+ zend_hash_find (Z_ARRVAL_PP (array ), "REQUEST_TIME" , sizeof ("REQUEST_TIME" ), (void * * ) & request_time_long )
139
+ == SUCCESS
140
+ ) {
141
+ ret = Z_LVAL_PP (request_time_long );
142
+ } else {
143
+ ret = time (NULL );
162
144
}
163
-
164
- len = spprintf (& strg , 0 , "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP." , "timecop" , arg );
165
- RETURN_STRINGL (strg , len , 0 );
145
+ RETURN_LONG (ret );
166
146
}
167
147
/* }}} */
168
148
/* The previous line is meant for vim and emacs, so it can correctly fold and
0 commit comments