惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
A
About on SuperTechFans
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
B
Blog RSS Feed
G
Google Developers Blog
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)

zodream梦想开源/个人编程日记

文件解析笔记-zodream梦想开源/个人编程日记 密码本开发笔记之读写与保存-zodream梦想开源/个人编程日记 SkiaSharp 把 pixel byte[] 转成 SKBitmap-zodream梦想开源/个人编程日记 nas 使用 Docker 安装 gogs-zodream梦想开源/个人编程日记 复制 android 手机中的文件到电脑-zodream梦想开源/个人编程日记 周报:寻找优质的周刊-zodream梦想开源/个人编程日记 开发日志:对Markdown的代码块新增引用来源支持-zodream梦想开源/个人编程日记 周报:怎么写技术类的教程文章-zodream梦想开源/个人编程日记 css display:flex 布局尺寸超出问题-zodream梦想开源/个人编程日记 周报:SEO优化的思考-zodream梦想开源/个人编程日记 Edge 浏览器不适用 Edge Image Viewer 打开图片 -zodream梦想开源/个人编程日记 SEO 学习笔记(一) 内容来源-zodream梦想开源/个人编程日记 PHP 实现双因素身份认证(2FA)-zodream梦想开源/个人编程日记 WPF MVVM 获取List 多选数据-zodream梦想开源/个人编程日记 Burp Suite 抓包-zodream梦想开源/个人编程日记 使用 indexnow 注意事项-zodream梦想开源/个人编程日记 Godot 使用字体图标 例如: Iconfont、FontAwesome-zodream梦想开源/个人编程日记 angular 15 对指定页面进行访问限制-zodream梦想开源/个人编程日记 CSS 使用 column-count 实现瀑布流出现内容分割的解决办法-zodream梦想开源/个人编程日记 input 确认按键事件在手机端不生效-zodream梦想开源/个人编程日记 C# 使用socket 进行通讯-zodream梦想开源/个人编程日记 Maui开发中Windows应用开启管理员权限-zodream梦想开源/个人编程日记 Maui 中自定义控件-zodream梦想开源/个人编程日记 angular 14 使用 ng-template 实现tree 结构显示-zodream梦想开源/个人编程日记 c# 动态安装和卸载dll-zodream梦想开源/个人编程日记 慎用 CompositionTarget.Rendering-zodream梦想开源/个人编程日记 c# 重写 c++ 程序笔记:数据初始化-zodream梦想开源/个人编程日记 源码编译 aseprite-zodream梦想开源/个人编程日记 记录一下字符串分隔split各语言之间的不同-zodream梦想开源/个人编程日记 c# Gzip解码无头内容-zodream梦想开源/个人编程日记
VS2019 开发PHP 拓展(五)创建 class-zodream梦想开源/个人...
zodream · 2020-03-24 · via zodream梦想开源/个人编程日记

VS2019 开发PHP 拓展(五)创建 class

增加一个 application 类

zodream_application.h

定义类的方法

#ifndef ZODREAM_APPLICATION_H
#define ZODREAM_APPLICATION_H

#ifndef ZO_BOOTED
#define ZO_BOOTED ZEND_STRL("booted")
#endif // !ZO_BOOTED


PHP_METHOD(ZodreamApplication, __construct);
PHP_METHOD(ZodreamApplication, __destruct);
PHP_METHOD(ZodreamApplication, version);
PHP_METHOD(ZodreamApplication, handle);

extern zend_class_entry* zo_application_ce;

ZEND_MINIT_FUNCTION(zodream_appliation);

#endif //ZODREAM_APPLICATION_H

12345678910111213141516171819

zodream_application.c

实现类的方法,并实现初始化

#include "zodream_application.h"

zend_class_entry* zo_application_ce;

/* {{{ proto ZodreamApplication ZodreamApplication::__construct()
        Public constructor */
PHP_METHOD(ZodreamApplication, __construct)
{
    // 修改属性
    zend_update_property_bool(zo_application_ce, getThis(), ZO_BOOTED, TRUE);
}
/* }}} */

/* {{{ proto void ZodreamApplication::__destruct()
*/
PHP_METHOD(ZodreamApplication, __destruct)
{

}
/* }}} */

/* {{{ proto string ZodreamApplication::version()
*/
PHP_METHOD(ZodreamApplication, version)
{
    zend_string *retval = strpprintf(0, PHP_ZODREAM_VERSION);
    RETURN_STR(retval);
}
/* }}} */

/* {{{ proto void ZodreamApplication::handle()
*/
PHP_METHOD(ZodreamApplication, handle)
{
    zend_bool* booted = (zend_bool *)zend_read_property(zo_application_ce, getThis(), ZO_BOOTED, 0, NULL);
    RETURN_BOOL(booted);
}
/* }}} */

zend_function_entry zodream_application_methods[] = {
     PHP_ME(ZodreamApplication, __destruct, arginfo_void, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR )
     PHP_ME(ZodreamApplication, __construct, arginfo_void, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
     PHP_ME(ZodreamApplication, version, arginfo_void, ZEND_ACC_PUBLIC)
     PHP_ME(ZodreamApplication, handle, arginfo_void, ZEND_ACC_PUBLIC)
     PHP_FE_END
};

ZEND_MINIT_FUNCTION(zodream_application)
{
    zend_class_entry ce;
    INIT_CLASS_ENTRY(ce, "Zodream\\Application", zodream_application_methods);
    zo_application_ce = zend_register_internal_class_ex(&ce, NULL);
    zo_application_ce->ce_flags |= ZEND_ACC_FINAL;

    zend_declare_property_bool(zo_application_ce, ZO_BOOTED, FALSE, ZEND_ACC_PROTECTED);
    zend_declare_class_constant_string(zo_application_ce, ZEND_STRL("VERSION"), PHP_ZODREAM_VERSION);

    return SUCCESS;
}

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859

zodream.c

进行类的初始化

PHP_MINIT_FUNCTION(zodream)
{
    ZEND_MODULE_STARTUP_N(zodream_application)(INIT_FUNC_ARGS_PASSTHRU)
    return SUCCESS;
}

123456

转载请保留原文链接: https://zodream.cn/blog/id/106.html