找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 4459|回复: 2

PHP扩展生成框架的一个简便功能

[复制链接]
发表于 2009-11-28 00:59:31 | 显示全部楼层 |阅读模式 IP:江苏扬州
作者:老王
PHP扩展的生成框架(ext_skel)已经很方便了,今天我发现一个选项可以让开发过程更方便。
./ext_skel --help
./ext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]]
           [--skel=dir] [--full-xml] [--no-help]
  --extname=module   module is the name of your extension
  --proto=file       file contains prototypes of functions to create
  --stubs=file       generate only function stubs in file
  --xml              generate xml documentation to be added to phpdoc-cvs
  --skel=dir         path to the skeleton directory
  --full-xml         generate xml documentation for a self-contained extension
                     (not yet implemented)
  --no-help          don't try to be nice and create comments in the code
                     and helper functions to test if the module compiled
首先,编写一个proto文件:
vi foo.proto
内容如下(注意行尾没有分号):
int fun_a(string str_a, string str_b)
int fun_b(int int_a, int int_b)
软后生成扩展:
./ext_skel --extname=foo --proto=foo.proto
然后看看生成的文件:
vi php_foo.h
你会发现相应的内容已经被自动添加了:
PHP_FUNCTION(confirm_foo_compiled); /* For testing, remove later. */
PHP_FUNCTION(fun_a);
PHP_FUNCTION(fun_b);
vi foo.c
/* {{{ foo_functions[]
*
* Every user visible function must have an entry in foo_functions[].
*/
zend_function_entry foo_functions[] = {
    PHP_FE(confirm_foo_compiled,    NULL)       /* For testing, remove later. */
    PHP_FE(fun_a,   NULL)
    PHP_FE(fun_b,   NULL)
    {NULL, NULL, NULL}  /* Must be the last line in foo_functions[] */
};
/* {{{ proto int fun_a(string str_a, string str_b)
    */
PHP_FUNCTION(fun_a)
{
    char *str_a = NULL;
    char *str_b = NULL;
    int argc = ZEND_NUM_ARGS();
    int str_a_len;
    int str_b_len;
    if (zend_parse_parameters(argc TSRMLS_CC, "ss", &str_a, &str_a_len, &str_b, &str_b_len) == FAILURE)
        return;
    php_error(E_WARNING, "fun_a: not yet implemented");
}
/* }}} */
/* {{{ proto int fun_b(int int_a, int int_b)
    */
PHP_FUNCTION(fun_b)
{
    int argc = ZEND_NUM_ARGS();
    long int_a;
    long int_b;
    if (zend_parse_parameters(argc TSRMLS_CC, "ll", &int_a, &int_b) == FAILURE)
        return;
    php_error(E_WARNING, "fun_b: not yet implemented");
}
/* }}} */
可以看到,相应的代码都已经自动加上了。
如果我们在foo.proto里加入
int fun_c(resource res_a, array arr_b[, int int_c])
那么:
/* {{{ proto int fun_c(resource res_a, array arr_b [, int int_c])
    */
PHP_FUNCTION(fun_c)
{
    int argc = ZEND_NUM_ARGS();
    int res_a_id = -1;
    long int_c;
    zval *res_a = NULL;
    zval *arr_b = NULL;
    if (zend_parse_parameters(argc TSRMLS_CC, "ra|l", &res_a, &arr_b, &int_c) == FAILURE)
        return;
    if (res_a) {
        ZEND_FETCH_RESOURCE(???, ???, res_a, res_a_id, "???", ???_rsrc_id);
    }
    php_error(E_WARNING, "fun_c: not yet implemented");
}
/* }}} */
可以看到,可选参数也判断出来了,很智能。
贴几个网址:
http://talks.php.net/show/extending-php-apachecon2003/
http://blog.csdn.net/taft/archive/2006/02/10/596291.aspx
发表于 2010-3-18 13:05:06 | 显示全部楼层 IP:印度
看完了这么强的文章,我想说点什么,但是又不知道说什么好,想来想去只想
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 19:22 , Processed in 0.192382 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表