forked from hnw/php-timecop
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d319526
Showing
8 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
timecop |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
dnl $Id$ | ||
dnl config.m4 for extension timecop | ||
|
||
dnl Comments in this file start with the string 'dnl'. | ||
dnl Remove where necessary. This file will not work | ||
dnl without editing. | ||
|
||
dnl If your extension references something external, use with: | ||
|
||
dnl PHP_ARG_WITH(timecop, for timecop support, | ||
dnl Make sure that the comment is aligned: | ||
dnl [ --with-timecop Include timecop support]) | ||
|
||
dnl Otherwise use enable: | ||
|
||
PHP_ARG_ENABLE(timecop, whether to enable timecop support, | ||
[ --enable-timecop Enable timecop support]) | ||
|
||
if test "$PHP_TIMECOP" != "no"; then | ||
dnl Write more examples of tests here... | ||
|
||
dnl # --with-timecop -> check with-path | ||
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this | ||
dnl SEARCH_FOR="/include/timecop.h" # you most likely want to change this | ||
dnl if test -r $PHP_TIMECOP/$SEARCH_FOR; then # path given as parameter | ||
dnl TIMECOP_DIR=$PHP_TIMECOP | ||
dnl else # search default path list | ||
dnl AC_MSG_CHECKING([for timecop files in default path]) | ||
dnl for i in $SEARCH_PATH ; do | ||
dnl if test -r $i/$SEARCH_FOR; then | ||
dnl TIMECOP_DIR=$i | ||
dnl AC_MSG_RESULT(found in $i) | ||
dnl fi | ||
dnl done | ||
dnl fi | ||
dnl | ||
dnl if test -z "$TIMECOP_DIR"; then | ||
dnl AC_MSG_RESULT([not found]) | ||
dnl AC_MSG_ERROR([Please reinstall the timecop distribution]) | ||
dnl fi | ||
|
||
dnl # --with-timecop -> add include path | ||
dnl PHP_ADD_INCLUDE($TIMECOP_DIR/include) | ||
|
||
dnl # --with-timecop -> check for lib and symbol presence | ||
dnl LIBNAME=timecop # you may want to change this | ||
dnl LIBSYMBOL=timecop # you most likely want to change this | ||
|
||
dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, | ||
dnl [ | ||
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TIMECOP_DIR/lib, TIMECOP_SHARED_LIBADD) | ||
dnl AC_DEFINE(HAVE_TIMECOPLIB,1,[ ]) | ||
dnl ],[ | ||
dnl AC_MSG_ERROR([wrong timecop lib version or lib not found]) | ||
dnl ],[ | ||
dnl -L$TIMECOP_DIR/lib -lm | ||
dnl ]) | ||
dnl | ||
dnl PHP_SUBST(TIMECOP_SHARED_LIBADD) | ||
|
||
AC_DEFINE(HAVE_TIMECOPLIB,1,[Whether timecop is present]) | ||
PHP_NEW_EXTENSION(timecop, timecop.c, $ext_shared) | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// $Id$ | ||
// vim:ft=javascript | ||
|
||
// If your extension references something external, use ARG_WITH | ||
// ARG_WITH("timecop", "for timecop support", "no"); | ||
|
||
// Otherwise, use ARG_ENABLE | ||
// ARG_ENABLE("timecop", "enable timecop support", "no"); | ||
|
||
if (PHP_TIMECOP != "no") { | ||
EXTENSION("timecop", "timecop.c"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 5 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 1997-2012 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* $Id$ */ | ||
|
||
#ifndef PHP_TIMECOP_H | ||
#define PHP_TIMECOP_H | ||
|
||
extern zend_module_entry timecop_module_entry; | ||
#define phpext_timecop_ptr &timecop_module_entry | ||
|
||
#ifdef PHP_WIN32 | ||
# define PHP_TIMECOP_API __declspec(dllexport) | ||
#elif defined(__GNUC__) && __GNUC__ >= 4 | ||
# define PHP_TIMECOP_API __attribute__ ((visibility("default"))) | ||
#else | ||
# define PHP_TIMECOP_API | ||
#endif | ||
|
||
#ifdef ZTS | ||
#include "TSRM.h" | ||
#endif | ||
|
||
PHP_MINIT_FUNCTION(timecop); | ||
PHP_MSHUTDOWN_FUNCTION(timecop); | ||
PHP_RINIT_FUNCTION(timecop); | ||
PHP_RSHUTDOWN_FUNCTION(timecop); | ||
PHP_MINFO_FUNCTION(timecop); | ||
|
||
PHP_FUNCTION(confirm_timecop_compiled); /* For testing, remove later. */ | ||
|
||
/* | ||
Declare any global variables you may need between the BEGIN | ||
and END macros here: | ||
ZEND_BEGIN_MODULE_GLOBALS(timecop) | ||
long global_value; | ||
char *global_string; | ||
ZEND_END_MODULE_GLOBALS(timecop) | ||
*/ | ||
|
||
/* In every utility function you add that needs to use variables | ||
in php_timecop_globals, call TSRMLS_FETCH(); after declaring other | ||
variables used by that function, or better yet, pass in TSRMLS_CC | ||
after the last function argument and declare your utility function | ||
with TSRMLS_DC after the last declared argument. Always refer to | ||
the globals in your function as TIMECOP_G(variable). You are | ||
encouraged to rename these macros something shorter, see | ||
examples in any other php module directory. | ||
*/ | ||
|
||
#ifdef ZTS | ||
#define TIMECOP_G(v) TSRMG(timecop_globals_id, zend_timecop_globals *, v) | ||
#else | ||
#define TIMECOP_G(v) (timecop_globals.v) | ||
#endif | ||
|
||
#endif /* PHP_TIMECOP_H */ | ||
|
||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
* vim600: noet sw=4 ts=4 fdm=marker | ||
* vim<600: noet sw=4 ts=4 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
Check for timecop presence | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("timecop")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
echo "timecop extension is available"; | ||
/* | ||
you can add regression tests for your extension here | ||
the output of your test code has to be equal to the | ||
text in the --EXPECT-- section below for the tests | ||
to pass, differences between the output and the | ||
expected text are interpreted as failure | ||
see php5/README.TESTING for further information on | ||
writing regression tests | ||
*/ | ||
?> | ||
--EXPECT-- | ||
timecop extension is available |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 5 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 1997-2012 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* $Id$ */ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "php.h" | ||
#include "php_ini.h" | ||
#include "ext/standard/info.h" | ||
#include "php_timecop.h" | ||
|
||
/* If you declare any globals in php_timecop.h uncomment this: | ||
ZEND_DECLARE_MODULE_GLOBALS(timecop) | ||
*/ | ||
|
||
/* True global resources - no need for thread safety here */ | ||
static int le_timecop; | ||
|
||
/* {{{ timecop_functions[] | ||
* | ||
* Every user visible function must have an entry in timecop_functions[]. | ||
*/ | ||
const zend_function_entry timecop_functions[] = { | ||
PHP_FE(confirm_timecop_compiled, NULL) /* For testing, remove later. */ | ||
PHP_FE_END /* Must be the last line in timecop_functions[] */ | ||
}; | ||
/* }}} */ | ||
|
||
/* {{{ timecop_module_entry | ||
*/ | ||
zend_module_entry timecop_module_entry = { | ||
#if ZEND_MODULE_API_NO >= 20010901 | ||
STANDARD_MODULE_HEADER, | ||
#endif | ||
"timecop", | ||
timecop_functions, | ||
PHP_MINIT(timecop), | ||
PHP_MSHUTDOWN(timecop), | ||
PHP_RINIT(timecop), /* Replace with NULL if there's nothing to do at request start */ | ||
PHP_RSHUTDOWN(timecop), /* Replace with NULL if there's nothing to do at request end */ | ||
PHP_MINFO(timecop), | ||
#if ZEND_MODULE_API_NO >= 20010901 | ||
"0.1", /* Replace with version number for your extension */ | ||
#endif | ||
STANDARD_MODULE_PROPERTIES | ||
}; | ||
/* }}} */ | ||
|
||
#ifdef COMPILE_DL_TIMECOP | ||
ZEND_GET_MODULE(timecop) | ||
#endif | ||
|
||
/* {{{ PHP_INI | ||
*/ | ||
/* Remove comments and fill if you need to have entries in php.ini | ||
PHP_INI_BEGIN() | ||
STD_PHP_INI_ENTRY("timecop.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_timecop_globals, timecop_globals) | ||
STD_PHP_INI_ENTRY("timecop.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_timecop_globals, timecop_globals) | ||
PHP_INI_END() | ||
*/ | ||
/* }}} */ | ||
|
||
/* {{{ php_timecop_init_globals | ||
*/ | ||
/* Uncomment this function if you have INI entries | ||
static void php_timecop_init_globals(zend_timecop_globals *timecop_globals) | ||
{ | ||
timecop_globals->global_value = 0; | ||
timecop_globals->global_string = NULL; | ||
} | ||
*/ | ||
/* }}} */ | ||
|
||
/* {{{ PHP_MINIT_FUNCTION | ||
*/ | ||
PHP_MINIT_FUNCTION(timecop) | ||
{ | ||
/* If you have INI entries, uncomment these lines | ||
REGISTER_INI_ENTRIES(); | ||
*/ | ||
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
/* {{{ PHP_MSHUTDOWN_FUNCTION | ||
*/ | ||
PHP_MSHUTDOWN_FUNCTION(timecop) | ||
{ | ||
/* uncomment this line if you have INI entries | ||
UNREGISTER_INI_ENTRIES(); | ||
*/ | ||
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
/* Remove if there's nothing to do at request start */ | ||
/* {{{ PHP_RINIT_FUNCTION | ||
*/ | ||
PHP_RINIT_FUNCTION(timecop) | ||
{ | ||
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
/* Remove if there's nothing to do at request end */ | ||
/* {{{ PHP_RSHUTDOWN_FUNCTION | ||
*/ | ||
PHP_RSHUTDOWN_FUNCTION(timecop) | ||
{ | ||
return SUCCESS; | ||
} | ||
/* }}} */ | ||
|
||
/* {{{ PHP_MINFO_FUNCTION | ||
*/ | ||
PHP_MINFO_FUNCTION(timecop) | ||
{ | ||
php_info_print_table_start(); | ||
php_info_print_table_header(2, "timecop support", "enabled"); | ||
php_info_print_table_end(); | ||
|
||
/* Remove comments if you have entries in php.ini | ||
DISPLAY_INI_ENTRIES(); | ||
*/ | ||
} | ||
/* }}} */ | ||
|
||
|
||
/* Remove the following function when you have succesfully modified config.m4 | ||
so that your module can be compiled into PHP, it exists only for testing | ||
purposes. */ | ||
|
||
/* Every user-visible function in PHP should document itself in the source */ | ||
/* {{{ proto string confirm_timecop_compiled(string arg) | ||
Return a string to confirm that the module is compiled in */ | ||
PHP_FUNCTION(confirm_timecop_compiled) | ||
{ | ||
char *arg = NULL; | ||
int arg_len, len; | ||
char *strg; | ||
|
||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { | ||
return; | ||
} | ||
|
||
len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "timecop", arg); | ||
RETURN_STRINGL(strg, len, 0); | ||
} | ||
/* }}} */ | ||
/* The previous line is meant for vim and emacs, so it can correctly fold and | ||
unfold functions in source code. See the corresponding marks just before | ||
function definition, where the functions purpose is also documented. Please | ||
follow this convention for the convenience of others editing your code. | ||
*/ | ||
|
||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
* vim600: noet sw=4 ts=4 fdm=marker | ||
* vim<600: noet sw=4 ts=4 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
$br = (php_sapi_name() == "cli")? "":"<br>"; | ||
|
||
if(!extension_loaded('timecop')) { | ||
dl('timecop.' . PHP_SHLIB_SUFFIX); | ||
} | ||
$module = 'timecop'; | ||
$functions = get_extension_funcs($module); | ||
echo "Functions available in the test extension:$br\n"; | ||
foreach($functions as $func) { | ||
echo $func."$br\n"; | ||
} | ||
echo "$br\n"; | ||
$function = 'confirm_' . $module . '_compiled'; | ||
if (extension_loaded($module)) { | ||
$str = $function($module); | ||
} else { | ||
$str = "Module $module is not compiled into PHP"; | ||
} | ||
echo "$str\n"; | ||
?> |