From 9d71b63e21fc5d812e8c7e39360fb10a0ea23230 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sat, 15 Sep 2018 12:11:19 +0200 Subject: [PATCH 1/1] Fix api by replacing __toString with parse Add parse arginfo Fix args naming --- bbcode.c | 69 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/bbcode.c b/bbcode.c index 22780ae..f6dd39a 100644 --- a/bbcode.c +++ b/bbcode.c @@ -14,9 +14,8 @@ ZEND_DECLARE_MODULE_GLOBALS(bbcode) */ typedef struct _bbcode_object { - /*zval *tag; - zval *smiley; - zval *flag;*/ + HashTable *tag; + HashTable *smiley; zval flag; zend_object std; } bbcode_object; @@ -91,7 +90,8 @@ static void bbcode_free(bbcode_object *obj TSRMLS_DC); static zend_object *bbcode_clone(zval *obj TSRMLS_DC); static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC); -/* BBCode object destroy call */ +/* {{{ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { + * BBCode object destroy call */ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { //zend_objects_destroy_object(&obj->std); zend_objects_destroy_object((zend_object *)obj); @@ -104,8 +104,10 @@ static void bbcode_destroy(bbcode_object *obj TSRMLS_DC) { //efree(obj); } +/* }}} */ -/* BBCode object free call */ +/* {{{ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { + * BBCode object free call */ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { /*if (obj->flag) { @@ -115,7 +117,10 @@ static void bbcode_free(bbcode_object *obj TSRMLS_DC) { //efree(obj); zend_object_std_dtor((zend_object *)obj); } +/* }}} */ +/* {{{ static zend_object *bbcode_clone(zval *obj) { + * BBCode object clone call */ static zend_object *bbcode_clone(zval *obj) { zend_object *oldobj = Z_OBJ_P(obj); @@ -134,7 +139,10 @@ static zend_object *bbcode_clone(zval *obj) { return newobj; } +/* }}} */ +/* {{{ static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC) { + * BBCode object create call */ static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC) { bbcode_object *obj = (bbcode_object *)ecalloc(1, sizeof(bbcode_object) + zend_object_properties_size(ce));//emalloc(sizeof(bbcode_object)); @@ -153,26 +161,43 @@ static zend_object *bbcode_create(zend_class_entry *ce TSRMLS_DC) { return &obj->std; } +/* }}} */ -/* {{{ PHP_METHOD(BBCode::__construct) { - */ +/* {{{ ZEND_BEGIN_ARG_INFO_EX(bbcode_construct_arginfo) */ ZEND_BEGIN_ARG_INFO_EX(bbcode_construct_arginfo, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, tag, 1) ZEND_ARG_ARRAY_INFO(0, smiley, 1) ZEND_ARG_INFO(0, flag) ZEND_END_ARG_INFO() +/* }}} */ +/* {{{ ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo) */ +ZEND_BEGIN_ARG_INFO_EX(bbcode_parse_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() +/* }}} */ +/* { { { PHP_METHOD(BBCode, __construct) { + */ PHP_METHOD(BBCode, __construct) { - zend_array *tag; - zend_array *smiley; + HashTable *tag = NULL; + HashTable *smiley = NULL; long flag = BBCODE_DEFAULT_FLAG; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|al", &tag, &smiley, &flag) == FAILURE) { +/*TODO: init tag with [ + '' => [ ? ] +]*/ +/* TODO: init smiley with default list + * TODO: use prefix in an ini parameter ? ini_setable ? + * TODO: make sure it's not really a global and per-app param ? + * */ + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|Hl", &tag, &smiley, &flag) == FAILURE) { return; } - bbcode_object *obj = bbcode_fetch(Z_OBJ_P(getThis())); + //bbcode_object *obj = bbcode_fetch(Z_OBJ_P(getThis())); + bbcode_object *obj = Z_BBCODE_P(getThis()); assert(obj != NULL); //TODO: set tag and smiley @@ -181,6 +206,12 @@ PHP_METHOD(BBCode, __construct) { Z_LVAL(obj->flag) = flag; } + if (smiley) { + obj->smiley = smiley; + } + + obj->tag = tag; + //obj = zend_object_store_get_object(getThis() TSRMLS_CC); //if (error) { //ZVAL_NULL(this); @@ -194,10 +225,18 @@ PHP_METHOD(BBCode, __destruct) { } /* }}} */ -/* {{{ PHP_METHOD(BBCode, __toString) { +/* {{{ PHP_METHOD(BBCode, parse) { */ -PHP_METHOD(BBCode, __toString) { - //TODO: +PHP_METHOD(BBCode, parse) { + zend_string *str = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { + return; + } + + //TODO: apply the parsing on string + + RETURN_STR(str); } /* }}} */ @@ -208,7 +247,7 @@ PHP_METHOD(BBCode, __toString) { const zend_function_entry bbcode_methods[] = { PHP_ME(BBCode, __construct, bbcode_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(BBCode, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - PHP_ME(BBCode, __toString, NULL, ZEND_ACC_PUBLIC) + PHP_ME(BBCode, parse, bbcode_parse_arginfo, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */ -- 2.41.1