From 096937185b5e249341eec6899ef35462034895be Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sat, 8 Jul 2006 12:28:25 +0000 Subject: [PATCH] - HttpQueryString implements ArrayAccess --- docs/functions.html | 14 ++++- http_querystring_object.c | 98 ++++++++++++++++++++++++++++++++++- package2.xml | 3 +- php_http_querystring_object.h | 5 +- 4 files changed, 116 insertions(+), 4 deletions(-) diff --git a/docs/functions.html b/docs/functions.html index f78ada3..743a151 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -663,6 +663,14 @@ WARNING: Don't use any character set that can contain NUL bytes like UTF-16.

Implements Serializable.

void HttpQueryString::unserialize(string serialized)

Implements Serializable.

+

mixed HttpQueryString::offsetGet(string offset)

+

Implements ArrayAccess.

+

void HttpQueryString::offsetSet(string offset, mixed value)

+

Implements ArrayAccess.

+

bool HttpQueryString::offsetExists(string offset)

+

Implements ArrayAccess.

+

void HttpQueryString::offsetUnset(string offset)

+

Implements ArrayAccess.


http_request_object.c

HttpRequest

@@ -1337,6 +1345,10 @@ http.cache_log is set.

  • HttpQueryString::xlate()
  • HttpQueryString::serialize()
  • HttpQueryString::unserialize()
  • +
  • HttpQueryString::offsetGet()
  • +
  • HttpQueryString::offsetSet()
  • +
  • HttpQueryString::offsetExists()
  • +
  • HttpQueryString::offsetUnset()
  • @@ -1453,7 +1465,7 @@ http.cache_log is set.

    -

    Generated at: Fri, 07 Jul 2006 13:48:43 +0200

    +

    Generated at: Fri, 07 Jul 2006 21:23:59 +0200

    diff --git a/http_querystring_object.c b/http_querystring_object.c index 3ae00fd..33e4356 100644 --- a/http_querystring_object.c +++ b/http_querystring_object.c @@ -77,6 +77,24 @@ HTTP_BEGIN_ARGS(unserialize, 1) HTTP_ARG_VAL(serialized, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(offsetGet, 1) + HTTP_ARG_VAL(offset, 0) +HTTP_END_ARGS; + +HTTP_BEGIN_ARGS(offsetSet, 2) + HTTP_ARG_VAL(offset, 0) + HTTP_ARG_VAL(value, 0) +HTTP_END_ARGS; + +HTTP_BEGIN_ARGS(offsetExists, 1) + HTTP_ARG_VAL(offset, 0) +HTTP_END_ARGS; + +HTTP_BEGIN_ARGS(offsetUnset, 1) + HTTP_ARG_VAL(offset, 0) +HTTP_END_ARGS; + + #define OBJ_PROP_CE http_querystring_object_ce zend_class_entry *http_querystring_object_ce; zend_function_entry http_querystring_object_fe[] = { @@ -108,6 +126,12 @@ zend_function_entry http_querystring_object_fe[] = { HTTP_QUERYSTRING_ME(serialize, ZEND_ACC_PUBLIC) HTTP_QUERYSTRING_ME(unserialize, ZEND_ACC_PUBLIC) + /* Implements ArrayAccess */ + HTTP_QUERYSTRING_ME(offsetGet, ZEND_ACC_PUBLIC) + HTTP_QUERYSTRING_ME(offsetSet, ZEND_ACC_PUBLIC) + HTTP_QUERYSTRING_ME(offsetExists, ZEND_ACC_PUBLIC) + HTTP_QUERYSTRING_ME(offsetUnset, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY }; static zend_object_handlers http_querystring_object_handlers; @@ -117,7 +141,7 @@ PHP_MINIT_FUNCTION(http_querystring_object) HTTP_REGISTER_CLASS_EX(HttpQueryString, http_querystring_object, NULL, 0); #ifndef WONKY - zend_class_implements(http_querystring_object_ce TSRMLS_CC, 1, zend_ce_serializable); + zend_class_implements(http_querystring_object_ce TSRMLS_CC, 2, zend_ce_serializable, zend_ce_arrayaccess); #endif DCL_STATIC_PROP_N(PRIVATE, instance); @@ -535,6 +559,78 @@ PHP_METHOD(HttpQueryString, unserialize) } /* }}} */ +/* {{{ proto mixed HttpQueryString::offsetGet(string offset) + * + * Implements ArrayAccess. + */ +PHP_METHOD(HttpQueryString, offsetGet) +{ + char *offset_str; + int offset_len; + zval **value; + + if ( (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(GET_PROP(queryArray)), offset_str, offset_len + 1, (void *) &value))) { + RETVAL_ZVAL(*value, 1, 0); + } +} +/* }}} */ + +/* {{{ proto void HttpQueryString::offsetSet(string offset, mixed value) + * + * Implements ArrayAccess. + */ +PHP_METHOD(HttpQueryString, offsetSet) +{ + char *offset_str; + int offset_len; + zval *value; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) { + zval *qarr = GET_PROP(queryArray), *qstr = GET_PROP(queryString); + + ZVAL_ADDREF(value); + add_assoc_zval_ex(qarr, offset_str, offset_len + 1, value); + http_querystring_update(qarr, qstr); + } +} +/* }}} */ + +/* {{{ proto bool HttpQueryString::offsetExists(string offset) + * + * Implements ArrayAccess. + */ +PHP_METHOD(HttpQueryString, offsetExists) +{ + char *offset_str; + int offset_len; + zval **value; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) { + RETURN_BOOL((SUCCESS == zend_hash_find(Z_ARRVAL_P(GET_PROP(queryArray)), offset_str, offset_len + 1, (void *) &value)) && (Z_TYPE_PP(value) != IS_NULL)); + } +} +/* }}} */ + +/* {{{ proto void HttpQueryString::offsetUnset(string offset) + * + * Implements ArrayAccess. + */ +PHP_METHOD(HttpQueryString, offsetUnset) +{ + char *offset_str; + int offset_len; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) { + zval *qarr = GET_PROP(queryArray); + + if (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarr), offset_str, offset_len + 1)) { + http_querystring_update(qarr, GET_PROP(queryString)); + } + } +} +/* }}} */ + #endif /* ZEND_ENGINE_2 */ /* diff --git a/package2.xml b/package2.xml index 646928f..2a1c73b 100644 --- a/package2.xml +++ b/package2.xml @@ -41,7 +41,8 @@ support. Parallel requests are available for PHP 5 and greater. diff --git a/php_http_querystring_object.h b/php_http_querystring_object.h index 26b3070..56e1a0f 100644 --- a/php_http_querystring_object.h +++ b/php_http_querystring_object.h @@ -59,7 +59,10 @@ PHP_METHOD(HttpQueryString, singleton); #endif PHP_METHOD(HttpQueryString, serialize); PHP_METHOD(HttpQueryString, unserialize); - +PHP_METHOD(HttpQueryString, offsetGet); +PHP_METHOD(HttpQueryString, offsetSet); +PHP_METHOD(HttpQueryString, offsetExists); +PHP_METHOD(HttpQueryString, offsetUnset); #endif #endif -- 2.30.2