Skip to content

Commit d319526

Browse files
committed
first commit
0 parents  commit d319526

File tree

8 files changed

+384
-0
lines changed

8 files changed

+384
-0
lines changed

Diff for: CREDITS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
timecop

Diff for: EXPERIMENTAL

Whitespace-only changes.

Diff for: config.m4

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
dnl $Id$
2+
dnl config.m4 for extension timecop
3+
4+
dnl Comments in this file start with the string 'dnl'.
5+
dnl Remove where necessary. This file will not work
6+
dnl without editing.
7+
8+
dnl If your extension references something external, use with:
9+
10+
dnl PHP_ARG_WITH(timecop, for timecop support,
11+
dnl Make sure that the comment is aligned:
12+
dnl [ --with-timecop Include timecop support])
13+
14+
dnl Otherwise use enable:
15+
16+
PHP_ARG_ENABLE(timecop, whether to enable timecop support,
17+
[ --enable-timecop Enable timecop support])
18+
19+
if test "$PHP_TIMECOP" != "no"; then
20+
dnl Write more examples of tests here...
21+
22+
dnl # --with-timecop -> check with-path
23+
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
24+
dnl SEARCH_FOR="/include/timecop.h" # you most likely want to change this
25+
dnl if test -r $PHP_TIMECOP/$SEARCH_FOR; then # path given as parameter
26+
dnl TIMECOP_DIR=$PHP_TIMECOP
27+
dnl else # search default path list
28+
dnl AC_MSG_CHECKING([for timecop files in default path])
29+
dnl for i in $SEARCH_PATH ; do
30+
dnl if test -r $i/$SEARCH_FOR; then
31+
dnl TIMECOP_DIR=$i
32+
dnl AC_MSG_RESULT(found in $i)
33+
dnl fi
34+
dnl done
35+
dnl fi
36+
dnl
37+
dnl if test -z "$TIMECOP_DIR"; then
38+
dnl AC_MSG_RESULT([not found])
39+
dnl AC_MSG_ERROR([Please reinstall the timecop distribution])
40+
dnl fi
41+
42+
dnl # --with-timecop -> add include path
43+
dnl PHP_ADD_INCLUDE($TIMECOP_DIR/include)
44+
45+
dnl # --with-timecop -> check for lib and symbol presence
46+
dnl LIBNAME=timecop # you may want to change this
47+
dnl LIBSYMBOL=timecop # you most likely want to change this
48+
49+
dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
50+
dnl [
51+
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TIMECOP_DIR/lib, TIMECOP_SHARED_LIBADD)
52+
dnl AC_DEFINE(HAVE_TIMECOPLIB,1,[ ])
53+
dnl ],[
54+
dnl AC_MSG_ERROR([wrong timecop lib version or lib not found])
55+
dnl ],[
56+
dnl -L$TIMECOP_DIR/lib -lm
57+
dnl ])
58+
dnl
59+
dnl PHP_SUBST(TIMECOP_SHARED_LIBADD)
60+
61+
AC_DEFINE(HAVE_TIMECOPLIB,1,[Whether timecop is present])
62+
PHP_NEW_EXTENSION(timecop, timecop.c, $ext_shared)
63+
fi

Diff for: config.w32

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
// If your extension references something external, use ARG_WITH
5+
// ARG_WITH("timecop", "for timecop support", "no");
6+
7+
// Otherwise, use ARG_ENABLE
8+
// ARG_ENABLE("timecop", "enable timecop support", "no");
9+
10+
if (PHP_TIMECOP != "no") {
11+
EXTENSION("timecop", "timecop.c");
12+
}
13+

Diff for: php_timecop.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2012 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifndef PHP_TIMECOP_H
22+
#define PHP_TIMECOP_H
23+
24+
extern zend_module_entry timecop_module_entry;
25+
#define phpext_timecop_ptr &timecop_module_entry
26+
27+
#ifdef PHP_WIN32
28+
# define PHP_TIMECOP_API __declspec(dllexport)
29+
#elif defined(__GNUC__) && __GNUC__ >= 4
30+
# define PHP_TIMECOP_API __attribute__ ((visibility("default")))
31+
#else
32+
# define PHP_TIMECOP_API
33+
#endif
34+
35+
#ifdef ZTS
36+
#include "TSRM.h"
37+
#endif
38+
39+
PHP_MINIT_FUNCTION(timecop);
40+
PHP_MSHUTDOWN_FUNCTION(timecop);
41+
PHP_RINIT_FUNCTION(timecop);
42+
PHP_RSHUTDOWN_FUNCTION(timecop);
43+
PHP_MINFO_FUNCTION(timecop);
44+
45+
PHP_FUNCTION(confirm_timecop_compiled); /* For testing, remove later. */
46+
47+
/*
48+
Declare any global variables you may need between the BEGIN
49+
and END macros here:
50+
51+
ZEND_BEGIN_MODULE_GLOBALS(timecop)
52+
long global_value;
53+
char *global_string;
54+
ZEND_END_MODULE_GLOBALS(timecop)
55+
*/
56+
57+
/* In every utility function you add that needs to use variables
58+
in php_timecop_globals, call TSRMLS_FETCH(); after declaring other
59+
variables used by that function, or better yet, pass in TSRMLS_CC
60+
after the last function argument and declare your utility function
61+
with TSRMLS_DC after the last declared argument. Always refer to
62+
the globals in your function as TIMECOP_G(variable). You are
63+
encouraged to rename these macros something shorter, see
64+
examples in any other php module directory.
65+
*/
66+
67+
#ifdef ZTS
68+
#define TIMECOP_G(v) TSRMG(timecop_globals_id, zend_timecop_globals *, v)
69+
#else
70+
#define TIMECOP_G(v) (timecop_globals.v)
71+
#endif
72+
73+
#endif /* PHP_TIMECOP_H */
74+
75+
76+
/*
77+
* Local variables:
78+
* tab-width: 4
79+
* c-basic-offset: 4
80+
* End:
81+
* vim600: noet sw=4 ts=4 fdm=marker
82+
* vim<600: noet sw=4 ts=4
83+
*/

Diff for: tests/001.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Check for timecop presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("timecop")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
echo "timecop extension is available";
8+
/*
9+
you can add regression tests for your extension here
10+
11+
the output of your test code has to be equal to the
12+
text in the --EXPECT-- section below for the tests
13+
to pass, differences between the output and the
14+
expected text are interpreted as failure
15+
16+
see php5/README.TESTING for further information on
17+
writing regression tests
18+
*/
19+
?>
20+
--EXPECT--
21+
timecop extension is available

Diff for: timecop.c

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2012 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifdef HAVE_CONFIG_H
22+
#include "config.h"
23+
#endif
24+
25+
#include "php.h"
26+
#include "php_ini.h"
27+
#include "ext/standard/info.h"
28+
#include "php_timecop.h"
29+
30+
/* If you declare any globals in php_timecop.h uncomment this:
31+
ZEND_DECLARE_MODULE_GLOBALS(timecop)
32+
*/
33+
34+
/* True global resources - no need for thread safety here */
35+
static int le_timecop;
36+
37+
/* {{{ timecop_functions[]
38+
*
39+
* Every user visible function must have an entry in timecop_functions[].
40+
*/
41+
const zend_function_entry timecop_functions[] = {
42+
PHP_FE(confirm_timecop_compiled, NULL) /* For testing, remove later. */
43+
PHP_FE_END /* Must be the last line in timecop_functions[] */
44+
};
45+
/* }}} */
46+
47+
/* {{{ timecop_module_entry
48+
*/
49+
zend_module_entry timecop_module_entry = {
50+
#if ZEND_MODULE_API_NO >= 20010901
51+
STANDARD_MODULE_HEADER,
52+
#endif
53+
"timecop",
54+
timecop_functions,
55+
PHP_MINIT(timecop),
56+
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 */
59+
PHP_MINFO(timecop),
60+
#if ZEND_MODULE_API_NO >= 20010901
61+
"0.1", /* Replace with version number for your extension */
62+
#endif
63+
STANDARD_MODULE_PROPERTIES
64+
};
65+
/* }}} */
66+
67+
#ifdef COMPILE_DL_TIMECOP
68+
ZEND_GET_MODULE(timecop)
69+
#endif
70+
71+
/* {{{ PHP_INI
72+
*/
73+
/* Remove comments and fill if you need to have entries in php.ini
74+
PHP_INI_BEGIN()
75+
STD_PHP_INI_ENTRY("timecop.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_timecop_globals, timecop_globals)
76+
STD_PHP_INI_ENTRY("timecop.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_timecop_globals, timecop_globals)
77+
PHP_INI_END()
78+
*/
79+
/* }}} */
80+
81+
/* {{{ php_timecop_init_globals
82+
*/
83+
/* Uncomment this function if you have INI entries
84+
static void php_timecop_init_globals(zend_timecop_globals *timecop_globals)
85+
{
86+
timecop_globals->global_value = 0;
87+
timecop_globals->global_string = NULL;
88+
}
89+
*/
90+
/* }}} */
91+
92+
/* {{{ PHP_MINIT_FUNCTION
93+
*/
94+
PHP_MINIT_FUNCTION(timecop)
95+
{
96+
/* If you have INI entries, uncomment these lines
97+
REGISTER_INI_ENTRIES();
98+
*/
99+
return SUCCESS;
100+
}
101+
/* }}} */
102+
103+
/* {{{ PHP_MSHUTDOWN_FUNCTION
104+
*/
105+
PHP_MSHUTDOWN_FUNCTION(timecop)
106+
{
107+
/* uncomment this line if you have INI entries
108+
UNREGISTER_INI_ENTRIES();
109+
*/
110+
return SUCCESS;
111+
}
112+
/* }}} */
113+
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+
/* {{{ PHP_MINFO_FUNCTION
133+
*/
134+
PHP_MINFO_FUNCTION(timecop)
135+
{
136+
php_info_print_table_start();
137+
php_info_print_table_header(2, "timecop support", "enabled");
138+
php_info_print_table_end();
139+
140+
/* Remove comments if you have entries in php.ini
141+
DISPLAY_INI_ENTRIES();
142+
*/
143+
}
144+
/* }}} */
145+
146+
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)
155+
{
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;
162+
}
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);
166+
}
167+
/* }}} */
168+
/* The previous line is meant for vim and emacs, so it can correctly fold and
169+
unfold functions in source code. See the corresponding marks just before
170+
function definition, where the functions purpose is also documented. Please
171+
follow this convention for the convenience of others editing your code.
172+
*/
173+
174+
175+
/*
176+
* Local variables:
177+
* tab-width: 4
178+
* c-basic-offset: 4
179+
* End:
180+
* vim600: noet sw=4 ts=4 fdm=marker
181+
* vim<600: noet sw=4 ts=4
182+
*/

Diff for: timecop.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$br = (php_sapi_name() == "cli")? "":"<br>";
3+
4+
if(!extension_loaded('timecop')) {
5+
dl('timecop.' . PHP_SHLIB_SUFFIX);
6+
}
7+
$module = 'timecop';
8+
$functions = get_extension_funcs($module);
9+
echo "Functions available in the test extension:$br\n";
10+
foreach($functions as $func) {
11+
echo $func."$br\n";
12+
}
13+
echo "$br\n";
14+
$function = 'confirm_' . $module . '_compiled';
15+
if (extension_loaded($module)) {
16+
$str = $function($module);
17+
} else {
18+
$str = "Module $module is not compiled into PHP";
19+
}
20+
echo "$str\n";
21+
?>

0 commit comments

Comments
 (0)