php-src/ext/skeleton/skeleton.c
Kalle Sommer Nielsen f35f45906e Redesigned ext_skel to be written entirely in PHP with no dependencies, this means it will now run on Windows without Cygwin and other nonsense.
It no longer includes a way to generate XML documentation (the PHP documentation utilities already got tools for that in svn under phpdoc/doc-base) and it no longer support function stubs.

$ php ext_skel.php --help
php ext_skel.php --ext=<name> [--experimental] [--author=<name>]
                 [--dir=<path>] [--std] [--onlyunix]
                 [--onlywindows] [--help]

  --ext=<name>          The name of the extension defined as <name>
  --experimental        Passed if this extension is experimental, this creates
                        the EXPERIMENTAL file in the root of the extension
  --author=<name>       Your name, this is used if --header is passed and
                        for the CREDITS file
  --dir=<path>          Path to the directory for where extension should be
                        created. Defaults to the directory of where this script
                        lives
  --std                 If passed, the standard header and vim rules footer used

                        in extensions that is included in the core, will be used

  --onlyunix            Only generate configure scripts for Unix
  --onlywindows         Only generate configure scripts for Windows
  --help                This help

Example usage:
$ php ext_skel.php --ext test --std --experimental
$ php ext_skel.php --ext kalle --author "Kalle Sommer Nielsen"
$ php ext_skel.php --ext phpfi --dir "/home/kalle/dev/" --onlyunix
2017-07-23 10:36:35 +02:00

103 lines
2.1 KiB
C

%HEADER%
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_%EXTNAME%.h"
/* {{{ void %EXTNAME%_test1()
*/
PHP_FUNCTION(%EXTNAME%_test1)
{
ZEND_PARSE_PARAMETERS_NONE();
php_printf("The extension %s is loaded and working!\r\n", "%EXTNAME%");
}
/* }}} */
/* {{{ string %EXTNAME%_test2( [ string $var ] )
*/
PHP_FUNCTION(%EXTNAME%_test2)
{
char *var = "World";
size_t var_len = sizeof("World") - 1;
zend_string *retval;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(var, var_len)
ZEND_PARSE_PARAMETERS_END();
retval = strpprintf(0, "Hello %s", var);
RETURN_STR(retval);
}
/* }}}*/
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(%EXTNAME%)
{
#if defined(ZTS) && defined(COMPILE_DL_%EXTNAMECAPS%)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(%EXTNAME%)
{
php_info_print_table_start();
php_info_print_table_header(2, "%EXTNAME% support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ arginfo
*/
ZEND_BEGIN_ARG_INFO(arginfo_%EXTNAME%_test1, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_%EXTNAME%_test2, 0)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ %EXTNAME%_functions[]
*/
const zend_function_entry %EXTNAME%_functions[] = {
PHP_FE(%EXTNAME%_test1, arginfo_%EXTNAME%_test1)
PHP_FE(%EXTNAME%_test2, arginfo_%EXTNAME%_test2)
PHP_FE_END
};
/* }}} */
/* {{{ %EXTNAME%_module_entry
*/
zend_module_entry %EXTNAME%_module_entry = {
STANDARD_MODULE_HEADER,
"%EXTNAME%", /* Extension name */
%EXTNAME%_functions, /* zend_function_entry */
NULL, /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(%EXTNAME%), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(%EXTNAME%), /* PHP_MINFO - Module info */
PHP_%EXTNAMECAPS%_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_%EXTNAMECAPS%
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(%EXTNAME%)
#endif
%FOOTER%