* standard return values
authorMichael Wallner <mike@php.net>
Tue, 5 Nov 2013 16:13:41 +0000 (16:13 +0000)
committerMichael Wallner <mike@php.net>
Tue, 5 Nov 2013 16:13:41 +0000 (16:13 +0000)
* reflection2php fixes

15 files changed:
php_http_api.h
php_http_client.c
php_http_client_curl.c
php_http_client_request.c
php_http_client_response.c
php_http_cookie.c
php_http_env.c
php_http_headers.c
php_http_message_body.c
php_http_params.c
php_http_querystring.c
php_http_url.c
reflection2php.php
tests/client012.phpt
tests/clientresponse003.phpt

index 211c6eb9022f44e99603ad8c7ca43ac74b4255c6..62530b8edac5471e1c15f46335a9633d420bb9d1 100644 (file)
@@ -42,6 +42,9 @@
 /* make functions that return SUCCESS|FAILURE more obvious */
 typedef int STATUS;
 
+/* inline doc */
+#define _RETURNS(type)
+
 #if (defined(HAVE_ICONV) || defined(PHP_HTTP_HAVE_EXT_ICONV)) && (PHP_HTTP_SHARED_DEPS || !defined(COMPILE_DL_ICONV))
 #      define PHP_HTTP_HAVE_ICONV
 #endif
index dc972906a70d77c05b7c7b1d0c1a1178538b06ac..1e89b38fc877e6c790b0a6de3de8331370d9b75e 100644 (file)
@@ -388,6 +388,7 @@ static STATUS handle_response(void *arg, php_http_client_t *client, php_http_cli
        if ((msg = *response)) {
                php_http_message_object_t *msg_obj;
                zval *info, *zresponse, *zrequest;
+               HashTable *info_ht;
 
                if (i_zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
                        handle_history(&zclient, *request, *response TSRMLS_CC);
@@ -406,8 +407,9 @@ static STATUS handle_response(void *arg, php_http_client_t *client, php_http_cli
                php_http_message_object_prepend(zresponse, zrequest, 1 TSRMLS_CC);
 
                MAKE_STD_ZVAL(info);
-               array_init(info);
-               php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &Z_ARRVAL_P(info));
+               object_init(info);
+               info_ht = HASH_OF(info);
+               php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &info_ht);
                zend_update_property(php_http_client_response_class_entry, zresponse, ZEND_STRL("transferInfo"), info TSRMLS_CC);
                zval_ptr_dtor(&info);
 
@@ -528,7 +530,7 @@ static PHP_METHOD(HttpClient, __construct)
                                        obj->client->responses.dtor = response_dtor;
                                }
                        } else {
-                               php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_FACTORY, "Failed to locate \"%s\" client request handler", driver_str);
+                               php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to locate \"%s\" client request handler", driver_str);
                        }
                }
        } end_error_handling();
@@ -747,8 +749,6 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_send, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpClient, send)
 {
-       RETVAL_FALSE;
-
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                if (SUCCESS == zend_parse_parameters_none()) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
@@ -769,11 +769,8 @@ static PHP_METHOD(HttpClient, once)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (0 < php_http_client_once(obj->client)) {
-                       RETURN_TRUE;
-               }
+               RETURN_BOOL(0 < php_http_client_once(obj->client));
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_wait, 0, 0, 0)
@@ -792,7 +789,6 @@ static PHP_METHOD(HttpClient, wait)
 
                RETURN_BOOL(SUCCESS == php_http_client_wait(obj->client, timeout > 0 ? &timeout_val : NULL));
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enablePipelining, 0, 0, 0)
@@ -953,11 +949,13 @@ static PHP_METHOD(HttpClient, getTransferInfo)
 
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
+                       HashTable *info;
                        php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                        php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
 
-                       array_init(return_value);
-                       php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &Z_ARRVAL_P(return_value));
+                       object_init(return_value);
+                       info = HASH_OF(return_value);
+                       php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &info);
                }
        } end_error_handling();
 }
index a5af70dc426a96eca1aefbecf1ed5b87d7a1eb36..37fc41301cc8345028880a7ba1697b150898f22e 100644 (file)
@@ -228,7 +228,12 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
        /* catch progress */
        switch (type) {
                case CURLINFO_TEXT:
-                       if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
+                       if (data[0] == '-') {
+                       } else if (php_memnstr(data, ZEND_STRL("Adding handle:"), data + length)) {
+                               h->progress.info = "setup";
+                       } else if (php_memnstr(data, ZEND_STRL("addHandle"), data + length)) {
+                               h->progress.info = "setup";
+                       } else if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
                                h->progress.info = "resolve";
                        } else if (php_memnstr(data, ZEND_STRL("Trying"), data + length)) {
                                h->progress.info = "connect";
@@ -238,6 +243,10 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                                h->progress.info = "connected";
                        } else if (php_memnstr(data, ZEND_STRL("Re-using existing connection!"), data + length)) {
                                h->progress.info = "connected";
+                       } else if (php_memnstr(data, ZEND_STRL("blacklisted"), data + length)) {
+                               h->progress.info = "blacklist check";
+                       } else if (php_memnstr(data, ZEND_STRL("SSL"), data + length)) {
+                               h->progress.info = "ssl negotiation";
                        } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
                                h->progress.info = "not disconnected";
                        } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
@@ -247,7 +256,9 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                        } else if (php_memnstr(data, ZEND_STRL("Operation timed out"), data + length)) {
                                h->progress.info = "timeout";
                        } else {
+#if PHP_DEBUG
                                h->progress.info = data;
+#endif
                        }
                        if (h->client->callback.progress.func) {
                                h->client->callback.progress.func(h->client->callback.progress.arg, h->client, &h->queue, &h->progress);
@@ -1054,11 +1065,9 @@ static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
        if ((opt = php_http_option_register(registry, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION, IS_LONG))) {
                opt->setter = php_http_curle_option_set_redirect;
        }
-       php_http_option_register(registry, ZEND_STRL("unrestrictedauth"), CURLOPT_UNRESTRICTED_AUTH, IS_BOOL);
+       php_http_option_register(registry, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH, IS_BOOL);
 #if PHP_HTTP_CURL_VERSION(7,19,1)
-       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_BOOL);
-#else
-       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POST301, IS_BOOL);
+       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_LONG);
 #endif
 
        /* retries */
@@ -1161,7 +1170,6 @@ static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
                        opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
                }
                php_http_option_register(registry, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE, IS_STRING);
-               php_http_option_register(registry, ZEND_STRL("certpasswd"), CURLOPT_SSLCERTPASSWD, IS_STRING);
 
                if ((opt = php_http_option_register(registry, ZEND_STRL("key"), CURLOPT_SSLKEY, IS_STRING))) {
                        opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
index 86843e6428b8d6199b50450b2e79de24db29df7c..db8ef51f318fed893de7a88ca4ff34375fef25ff 100644 (file)
@@ -31,22 +31,16 @@ static PHP_METHOD(HttpClientRequest, __construct)
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!O!", &meth_str, &meth_len, &url_str, &url_len, &zheaders, &zbody, php_http_message_body_class_entry)) {
                        php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-                       php_http_message_body_object_t *body_obj = NULL;
-
-                       if (zbody) {
-                               php_http_message_object_set_body(obj, zbody TSRMLS_CC);
-                       }
 
                        if (obj->message) {
                                php_http_message_set_type(obj->message, PHP_HTTP_REQUEST);
-                               if (body_obj) {
-                                       php_http_message_body_free(&obj->message->body);
-                                       obj->message->body = body_obj->body;
-                               }
                        } else {
-                               obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, body_obj ? body_obj->body : NULL TSRMLS_CC);
+                               obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC);
                        }
 
+                       if (zbody) {
+                               php_http_message_object_set_body(obj, zbody TSRMLS_CC);
+                       }
                        if (meth_str && meth_len) {
                                PHP_HTTP_INFO(obj->message).request.method = estrndup(meth_str, meth_len);
                        }
@@ -93,11 +87,14 @@ static PHP_METHOD(HttpClientRequest, getContentType)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               zval *zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
+               zval *zct;
 
-               RETURN_ZVAL(zct, 0, 1);
+               php_http_message_update_headers(obj->message);
+               zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
+               if (zct) {
+                       RETURN_ZVAL(zct, 0, 1);
+               }
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setQuery, 0, 0, 0)
index de27904de0160a22e0f20d39dd4f3a5def1a5aee..26e85178012452e4b9825d5805ca1e6a7d343a79 100644 (file)
@@ -20,46 +20,37 @@ static PHP_METHOD(HttpClientResponse, getCookies)
 {
        long flags = 0;
        zval *allowed_extras_array = NULL;
+       int i = 0;
+       char **allowed_extras = NULL;
+       zval *header = NULL, **entry = NULL;
+       HashPosition pos;
+       php_http_message_object_t *msg;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
-               int i = 0;
-               char **allowed_extras = NULL;
-               zval *header = NULL, **entry = NULL;
-               HashPosition pos;
-               php_http_message_object_t *msg = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
+               return;
+       }
 
-               array_init(return_value);
+       msg = zend_object_store_get_object(getThis() TSRMLS_CC);
+       array_init(return_value);
 
-               if (allowed_extras_array) {
-                       allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
-                       FOREACH_VAL(pos, allowed_extras_array, entry) {
-                               zval *data = php_http_ztyp(IS_STRING, *entry);
-                               allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
-                               zval_ptr_dtor(&data);
-                       }
+       if (allowed_extras_array) {
+               allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
+               FOREACH_VAL(pos, allowed_extras_array, entry) {
+                       zval *data = php_http_ztyp(IS_STRING, *entry);
+                       allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
+                       zval_ptr_dtor(&data);
                }
+       }
 
-               if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
-                       php_http_cookie_list_t *list;
-
-                       if (Z_TYPE_P(header) == IS_ARRAY) {
-                               zval **single_header;
+       if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
+               php_http_cookie_list_t *list;
 
-                               FOREACH_VAL(pos, header, single_header) {
-                                       zval *data = php_http_ztyp(IS_STRING, *single_header);
+               if (Z_TYPE_P(header) == IS_ARRAY) {
+                       zval **single_header;
 
-                                       if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
-                                               zval *cookie;
+                       FOREACH_VAL(pos, header, single_header) {
+                               zval *data = php_http_ztyp(IS_STRING, *single_header);
 
-                                               MAKE_STD_ZVAL(cookie);
-                                               ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
-                                               add_next_index_zval(return_value, cookie);
-                                       }
-                                       zval_ptr_dtor(&data);
-                               }
-                       } else {
-                               zval *data = php_http_ztyp(IS_STRING, header);
                                if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
                                        zval *cookie;
 
@@ -69,19 +60,26 @@ static PHP_METHOD(HttpClientResponse, getCookies)
                                }
                                zval_ptr_dtor(&data);
                        }
-                       zval_ptr_dtor(&header);
-               }
-
-               if (allowed_extras) {
-                       for (i = 0; allowed_extras[i]; ++i) {
-                               efree(allowed_extras[i]);
+               } else {
+                       zval *data = php_http_ztyp(IS_STRING, header);
+                       if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
+                               zval *cookie;
+
+                               MAKE_STD_ZVAL(cookie);
+                               ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
+                               add_next_index_zval(return_value, cookie);
                        }
-                       efree(allowed_extras);
+                       zval_ptr_dtor(&data);
                }
+               zval_ptr_dtor(&header);
+       }
 
-               return;
+       if (allowed_extras) {
+               for (i = 0; allowed_extras[i]; ++i) {
+                       efree(allowed_extras[i]);
+               }
+               efree(allowed_extras);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo, 0, 0, 0)
@@ -91,21 +89,26 @@ static PHP_METHOD(HttpClientResponse, getTransferInfo)
 {
        char *info_name = NULL;
        int info_len = 0;
+       zval *infop, *info;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
-               zval **infop, *info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
+               return;
+       }
 
-               /* request completed? */
-               if (Z_TYPE_P(info) == IS_ARRAY) {
-                       if (info_len && info_name) {
-                               if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(info), php_http_pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
-                                       RETURN_ZVAL(*infop, 1, 0);
-                               } else {
-                                       php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name);
-                               }
+       info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
+
+       /* request completed? */
+       if (Z_TYPE_P(info) == IS_OBJECT) {
+               if (info_len && info_name) {
+                       infop = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
+
+                       if (infop) {
+                               RETURN_ZVAL(infop, 1, 0);
                        } else {
-                               RETURN_ZVAL(info, 1, 0);
+                               php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name);
                        }
+               } else {
+                       RETURN_ZVAL(info, 1, 0);
                }
        }
        RETURN_FALSE;
index d9f2551b255e3b04a75ebb197fdf7189f84ffe1b..dd8339bffda829e082d76521bfab3a4a1a5f86c9 100644 (file)
@@ -545,7 +545,7 @@ static PHP_METHOD(HttpCookie, addCookies)
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getExtras, 0, 0, 0)
-ZEND_END_ARG_INFO();;
+ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpCookie, getExtras)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
@@ -555,9 +555,7 @@ static PHP_METHOD(HttpCookie, getExtras)
 
                array_init(return_value);
                array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
-               return;
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtras, 0, 0, 0)
@@ -615,7 +613,6 @@ static PHP_METHOD(HttpCookie, getCookie)
                        RETURN_ZVAL(zvalue, 1, 0);
                }
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setCookie, 0, 0, 1)
@@ -641,7 +638,7 @@ static PHP_METHOD(HttpCookie, setCookie)
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookie, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookie, 0, 0, 2)
        ZEND_ARG_INFO(0, cookie_name)
        ZEND_ARG_INFO(0, cookie_value)
 ZEND_END_ARG_INFO();
@@ -650,7 +647,7 @@ static PHP_METHOD(HttpCookie, addCookie)
        char *name_str, *value_str;
        int name_len, value_len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                PHP_HTTP_COOKIE_OBJECT_INIT(obj);
@@ -678,7 +675,6 @@ static PHP_METHOD(HttpCookie, getExtra)
                        RETURN_ZVAL(zvalue, 1, 0);
                }
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtra, 0, 0, 1)
@@ -704,7 +700,7 @@ static PHP_METHOD(HttpCookie, setExtra)
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtra, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtra, 0, 0, 2)
        ZEND_ARG_INFO(0, extra_name)
        ZEND_ARG_INFO(0, extra_value)
 ZEND_END_ARG_INFO();
@@ -713,7 +709,7 @@ static PHP_METHOD(HttpCookie, addExtra)
        char *name_str, *value_str;
        int name_len, value_len;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                PHP_HTTP_COOKIE_OBJECT_INIT(obj);
@@ -737,7 +733,6 @@ static PHP_METHOD(HttpCookie, getDomain)
                }
                RETURN_NULL();
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setDomain, 0, 0, 0)
@@ -772,7 +767,6 @@ static PHP_METHOD(HttpCookie, getPath)
                }
                RETURN_NULL();
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setPath, 0, 0, 0)
@@ -804,7 +798,6 @@ static PHP_METHOD(HttpCookie, getExpires)
 
                RETURN_LONG(obj->list->expires);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExpires, 0, 0, 0)
@@ -835,7 +828,6 @@ static PHP_METHOD(HttpCookie, getMaxAge)
 
                RETURN_LONG(obj->list->max_age);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setMaxAge, 0, 0, 0)
@@ -856,7 +848,7 @@ static PHP_METHOD(HttpCookie, setMaxAge)
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getFlags, 0, 0, 0)
-ZEND_END_ARG_INFO();;
+ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpCookie, getFlags)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
@@ -866,7 +858,6 @@ static PHP_METHOD(HttpCookie, getFlags)
 
                RETURN_LONG(obj->list->flags);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setFlags, 0, 0, 0)
index c6b5c2bad6d6909d84952bca0e234616625adb73..7a68f8a2c50166719eb979638507fbb3fa08ae53 100644 (file)
@@ -234,7 +234,7 @@ PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
                php_stream *input = php_stream_open_wrapper("php://input", "r", 0, NULL);
 
                /* php://input does not support stat */
-               php_stream_copy_to_stream(input, s, -1);
+               php_stream_copy_to_stream_ex(input, s, -1, NULL);
                php_stream_close(input);
 #else
                if (SG(request_info).post_data || SG(request_info).raw_post_data) {
@@ -686,22 +686,20 @@ static PHP_METHOD(HttpEnv, getRequestHeader)
        char *header_name_str = NULL;
        int header_name_len = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
-               if (header_name_str && header_name_len) {
-                       size_t header_length;
-                       char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL TSRMLS_CC);
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+               return;
+       }
+       if (header_name_str && header_name_len) {
+               size_t header_length;
+               char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL TSRMLS_CC);
 
-                       if (header_value) {
-                               RETURN_STRINGL(header_value, header_length, 0);
-                       }
-                       RETURN_NULL();
-               } else {
-                       array_init(return_value);
-                       php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
-                       return;
+               if (header_value) {
+                       RETURN_STRINGL(header_value, header_length, 0);
                }
+       } else {
+               array_init(return_value);
+               php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestBody, 0, 0, 0)
@@ -730,10 +728,10 @@ static PHP_METHOD(HttpEnv, getResponseStatusForCode)
 {
        long code;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
-               RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+               return;
        }
-       RETURN_FALSE;
+       RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes, 0, 0, 0)
@@ -745,7 +743,7 @@ static PHP_METHOD(HttpEnv, getResponseStatusForAllCodes)
        php_http_strlist_iterator_t i;
 
        if (SUCCESS != zend_parse_parameters_none()) {
-               RETURN_FALSE;
+               return;
        }
 
        array_init(return_value);
@@ -765,31 +763,29 @@ static PHP_METHOD(HttpEnv, getResponseHeader)
        char *header_name_str = NULL;
        int header_name_len = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
-               if (header_name_str && header_name_len) {
-                       char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+               return;
+       }
+       if (header_name_str && header_name_len) {
+               char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
 
-                       if (header_value) {
-                               RETURN_STRING(header_value, 0);
-                       }
-                       RETURN_NULL();
-               } else {
-                       array_init(return_value);
-                       php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
-                       return;
+               if (header_value) {
+                       RETURN_STRING(header_value, 0);
                }
+       } else {
+               array_init(return_value);
+               php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseCode, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getResponseCode)
 {
-       if (SUCCESS == zend_parse_parameters_none()) {
-               RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
+       if (SUCCESS != zend_parse_parameters_none()) {
+               return;
        }
-       RETURN_FALSE;
+       RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader, 0, 0, 1)
@@ -806,10 +802,10 @@ static PHP_METHOD(HttpEnv, setResponseHeader)
        long code = 0;
        zend_bool replace_header = 1;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
-               RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
+               return;
        }
-       RETURN_FALSE;
+       RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1)
@@ -819,10 +815,10 @@ static PHP_METHOD(HttpEnv, setResponseCode)
 {
        long code;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
-               RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+               return;
        }
-       RETURN_FALSE;
+       RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateLanguage, 0, 0, 1)
@@ -834,16 +830,15 @@ static PHP_METHOD(HttpEnv, negotiateLanguage)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
-
-               PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array);
-       } else {
-               RETURN_FALSE;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+               return;
        }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
+       }
+
+       PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateCharset, 0, 0, 1)
@@ -855,15 +850,14 @@ static PHP_METHOD(HttpEnv, negotiateCharset)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
-               PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array);
-       } else {
-               RETURN_FALSE;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+               return;
+       }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
        }
+       PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateEncoding, 0, 0, 1)
@@ -875,15 +869,14 @@ static PHP_METHOD(HttpEnv, negotiateEncoding)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
-               PHP_HTTP_DO_NEGOTIATE(encoding, supported, rs_array);
-       } else {
-               RETURN_FALSE;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+               return;
        }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
+       }
+       PHP_HTTP_DO_NEGOTIATE(encoding, supported, rs_array);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateContentType, 0, 0, 1)
@@ -895,45 +888,43 @@ static PHP_METHOD(HttpEnv, negotiateContentType)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
-               PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
-       } else {
-               RETURN_FALSE;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+               return;
+       }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
        }
+       PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiate, 0, 0, 2)
-       ZEND_ARG_INFO(0, value)
+       ZEND_ARG_INFO(0, params)
        ZEND_ARG_INFO(0, supported)
        ZEND_ARG_INFO(0, primary_type_separator)
        ZEND_ARG_INFO(1, result_array)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, negotiate)
 {
-       HashTable *supported;
+       HashTable *supported, *rs;
        zval *rs_array = NULL;
        char *value_str, *sep_str = NULL;
        int value_len, sep_len = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
-               HashTable *rs;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
+               return;
+       }
 
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
 
-               if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len TSRMLS_CC))) {
-                       PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
-               } else {
-                       PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
-               }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
+       }
+
+       if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len TSRMLS_CC))) {
+               PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
        } else {
-               RETURN_FALSE;
+               PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
        }
 }
 
@@ -969,7 +960,7 @@ static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
 
 #if PHP_VERSION_ID >= 50600
        php_http_message_body_to_string(php_http_env_get_request_body(TSRMLS_C),
-                       &json_str, &json_len, 0, -1 TSRMLS_CC);
+                       &json_str, &json_len, 0, -1);
 #else
        json_str = SG(request_info).raw_post_data;
        json_len = SG(request_info).raw_post_data_length;
index 68e2f6affb8a0d7c35d3161540062e434c401070..eaa6105725f87cc425c1204a96f818fade13bc33 100644 (file)
@@ -209,11 +209,11 @@ PHP_METHOD(HttpHeader, match)
 {
        char *val_str;
        int val_len;
-       long flags = 0;
+       long flags = PHP_HTTP_MATCH_LOOSE;
        zval *zvalue;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &val_str, &val_len, &flags)) {
-               RETURN_NULL();
+               return;
        }
 
        zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
@@ -232,32 +232,31 @@ PHP_METHOD(HttpHeader, negotiate)
        char *sep_str = NULL;
        size_t sep_len = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
-               if (rs_array) {
-                       zval_dtor(rs_array);
-                       array_init(rs_array);
-               }
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+               return;
+       }
+       if (rs_array) {
+               zval_dtor(rs_array);
+               array_init(rs_array);
+       }
 
-               zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
-               if (!strcasecmp(Z_STRVAL_P(zname), "Accept")) {
-                       sep_str = "/";
-                       sep_len = 1;
-               } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
-                       sep_str = "-";
-                       sep_len = 1;
-               }
-               zval_ptr_dtor(&zname);
+       zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
+       if (!strcasecmp(Z_STRVAL_P(zname), "Accept")) {
+               sep_str = "/";
+               sep_len = 1;
+       } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
+               sep_str = "-";
+               sep_len = 1;
+       }
+       zval_ptr_dtor(&zname);
 
-               zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
-               if ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
-                       PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
-               } else {
-                       PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
-               }
-               zval_ptr_dtor(&zvalue);
+       zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
+       if ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
+               PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
        } else {
-               RETURN_FALSE;
+               PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
        }
+       zval_ptr_dtor(&zvalue);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_getParams, 0, 0, 0)
@@ -293,7 +292,7 @@ PHP_METHOD(HttpHeader, getParams)
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_parse, 0, 0, 1)
        ZEND_ARG_INFO(0, string)
-       ZEND_ARG_INFO(0, flags)
+       ZEND_ARG_INFO(0, header_class)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpHeader, parse)
 {
index fd5b76293b9384b279089a9301d1084467cc5526..03ca5c3e11f3eb2d31e3b353b3041fe2eb5cc252 100644 (file)
@@ -202,7 +202,10 @@ PHP_HTTP_API size_t php_http_message_body_append(php_http_message_body_t *body,
        php_stream *s;
        TSRMLS_FETCH_FROM_CTX(body->ts);
 
-       s = php_http_message_body_stream(body);
+       if (!(s = php_http_message_body_stream(body))) {
+               return -1;
+       }
+
        php_stream_seek(s, 0, SEEK_END);
        return php_stream_write(s, buf, len);
 }
index 2356dc96170bb525f342d1085d4ef03362bb749a..f8234959f03ca4875ff22a23d92cb35332e0adcd 100644 (file)
@@ -794,11 +794,13 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toArray, 0, 0, 0)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpParams, toArray)
 {
-       if (SUCCESS == zend_parse_parameters_none()) {
-               zval *zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC);
-               RETURN_ZVAL(zparams, 1, 0);
+       zval *zparams;
+
+       if (SUCCESS != zend_parse_parameters_none()) {
+               return;
        }
-       RETURN_FALSE;
+       zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC);
+       RETURN_ZVAL(zparams, 1, 0);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toString, 0, 0, 0)
index 3dde39b8046d36a2fdc4dca69c61082ac4ad9b3a..d1b7845efbee47abf0c8ab0302c4e70b158ea53f 100644 (file)
@@ -395,7 +395,7 @@ ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, toString)
 {
        if (SUCCESS != zend_parse_parameters_none()) {
-               RETURN_FALSE;
+               return;
        }
        php_http_querystring_str(getThis(), return_value TSRMLS_CC);
 }
@@ -408,7 +408,6 @@ PHP_METHOD(HttpQueryString, toArray)
                zval *zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
                RETURN_ZVAL(zqa, 1, 0);
        }
-       RETURN_FALSE;
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_get, 0, 0, 0)
@@ -550,7 +549,7 @@ ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, serialize)
 {
        if (SUCCESS != zend_parse_parameters_none()) {
-               RETURN_FALSE;
+               return;
        }
        php_http_querystring_str(getThis(), return_value TSRMLS_CC);
 }
index d95eb5aeae969459ae4cf23ec7622d1524778781..175886d561f2cffe7ccb423114827dfa5edebd42 100644 (file)
@@ -529,11 +529,16 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpUrl, toArray)
 {
+       php_url *purl;
+
        if (SUCCESS != zend_parse_parameters_none()) {
-               RETURN_FALSE;
+               return;
        }
-       array_init(return_value);
-       array_copy(HASH_OF(getThis()), HASH_OF(return_value));
+
+       /* strip any non-URL properties */
+       purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC);
+       php_http_url_to_struct(purl, return_value TSRMLS_CC);
+       php_url_free(purl);
 }
 
 static zend_function_entry php_http_url_methods[] = {
index 37747be51c48702b537dce5e153ed74b953804e2..e486012037fde36f229a296b06431137e7277a49 100755 (executable)
@@ -28,104 +28,178 @@ function c($n, $c) {
     return true;
 }
 
-if (!strlen($ext = $argv[1]))
-       die(sprintf("Usage: %s <ext>\n", $argv[0]));
+ob_start(function($s) {
+    // redirect any output to stderr
+    fwrite(STDERR, $s);
+    return true;
+});
+
+$out = STDOUT;
+switch ($argc) {
+    default:
+    case 3:
+        $out = fopen($argv[2], "w") or die;
+    case 2:
+        $ext = $argv[1];
+        break;
+    
+    case 1:
+        die(sprintf($out, "Usage: %s <ext>\n", $argv[0]));
+}
 
-printf("<?php\n\n");
+fprintf($out, "<?php\n\n");
 
 $ext = new ReflectionExtension($ext);
+
+$constants  = array();
+$functions  = array();
+$structures = array();
+
+// split up by namespace first
 foreach ($ext->getConstants() as $constant => $value) {
-    printf("define('%s', '%s');\n", $constant, $value);
+    $ns = ($nsend = strrpos($constant, "\\")) ? substr($constant, 0, $nsend++) : "";
+    $cn = substr($constant, $nsend);
+    $constants[$ns][$cn] = $value;
 }
-printf("\n");
-
 foreach ($ext->getFunctions() as $f) {
-    printf("function %s(", $f->getName());
-    $ps = array();
-    foreach ($f->getParameters() as $p) {
-        $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName());
-        if ($p->isOptional()) {
-            if ($p->isDefaultValueAvailable()) {
-                $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true));
-            } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
-                $p1 .= " = NULL";
-            } elseif ($p->isArray()) {
-                $p1 .= " = array()";
-            }
-        }
-        $ps[] = $p1;
-    }
-    printf("%s) {\n}\n", implode(", ", $ps));
+    /* @var $f ReflectionFunction */
+    $ns = $f->inNamespace() ? $f->getNamespaceName() : "";
+    $functions[$ns][$f->getShortName()] = $f;
+}
+foreach ($ext->getClasses() as $c) {
+    /* @var $c ReflectionClass */
+    $ns = $c->inNamespace() ? $c->getNamespaceName() : "";
+    $structures[$ns][$c->getShortName()] = $c;
 }
-printf("\n");
 
-$classes = $ext->getClasses();
-usort($classes, function($a,$b) {
-        $cmp = strcmp($a->getNamespaceName(), $b->getNamespaceName());
-        if (!$cmp) {
-            $cmp = strcmp($a->getShortName(), $b->getShortName());
-        }
-        return $cmp;
-    }
-);
+$namespaces = array_unique(array_merge(
+        array_keys($constants),
+        array_keys($functions),
+        array_keys($structures)
+));
 
-foreach ($classes as $class) {
+// simple sort
+natsort($namespaces);
 
-    if ($class->inNamespace()) {
-        printf("namespace %s\n{\n", $class->getNamespaceName());
+foreach ($namespaces as $ns) {
+    fprintf($out, "namespace %s%s\n{\n", $ns, strlen($ns) ? " " : "");
+    //
+    if (isset($constants[$ns])) {
+        ksort($constants[$ns], SORT_NATURAL);
+        foreach ($constants[$ns] as $cn => $value) {
+            fprintf($out, "\tconst %s = %s;\n", $cn, var_export($value, true));
+        }
     }
-       printf("\t%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getShortName());
-       if ($p = $class->getParentClass()) {
-               printf("extends \\%s ", $p->getName());
-       }
-       if ($i = $class->getInterfaceNames()) {
-               printf("implements \\%s ", implode(", \\", array_filter($i,function($v){return$v!="Traversable";})));
-       }
-       printf("\n\t{\n");
-
-       $_=0;
-       foreach ($class->getConstants() as $n => $v) {
-               c($n, $class) and $_+=printf("\t\tconst %s = %s;\n", $n, var_export($v, true));
-       }
-       $_ and printf("\n");
-       $_=0;
-       foreach ($class->getProperties() as $p) {
-               if ($p->getDeclaringClass()->getName() == $class->getName()) {
-                       $_+=printf("\t\t%s\$%s;\n", m($p->getModifiers()), $p->getName());
-               }
-       }
-       $_ and printf("\n");
-
-       foreach ($class->getMethods() as $m) {
-               if ($m->getDeclaringClass()->getName() == $class->getName()) {
-                       printf("\t\t%sfunction %s(", m($m->getModifiers()), $m->getName());
-                       $ps = array();
-                       foreach ($m->getParameters() as $p) {
-                               $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName());
+    //
+    if (isset($functions[$ns])) {
+        ksort($functions[$ns], SORT_NATURAL);
+        foreach ($functions[$ns] as $fn => $f) {
+            /* @var $f ReflectionFunction */
+            fprintf($out, "\n\tfunction %s(", $fn);
+            $ps = array();
+            foreach ($f->getParameters() as $p) {
+                $p1 = sfprintf($out, "%s%s\$%s", t($p), 
+                        $p->isPassedByReference()?"&":"", $p->getName());
                 if ($p->isOptional()) {
                     if ($p->isDefaultValueAvailable()) {
-                        $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true));
+                        $p1 .= sfprintf($out, " = %s", 
+                                var_export($p->getDefaultValue(), true));
                     } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
-                        $p1 .= sprintf(" = NULL");
+                        $p1 .= " = NULL";
                     } elseif ($p->isArray()) {
                         $p1 .= " = array()";
                     }
                 }
-                               $ps[] = $p1;
-                       }
-                       printf("%s)", implode(", ", $ps));
-                       if ($m->isAbstract()) {
-                               printf(";\n\n");
-                       } else {
-                               printf(" {\n\t\t}\n\n");
-                       }
-               }
-       }
+                $ps[] = $p1;
+            }
+            fprintf($out, "%s) {\n\t}\n", implode(", ", $ps));
+        }
+    }
+    //
+    if (isset($structures[$ns])) {
+        uasort($structures[$ns], function ($a, $b) {
+            /* @var $a ReflectionClass */
+            /* @var $b ReflectionClass */
+            $score = array_sum([
+                -!$a->isInterface()+
+                -!$a->isAbstract()+
+                -!$a->isTrait()+
+                -!substr_compare($a->getShortName(), "Exception", -strlen("Exception")),
+                +!$b->isInterface()+
+                +!$b->isAbstract()+
+                +!$b->isTrait()+
+                -!substr_compare($b->getShortName(), "Exception", -strlen("Exception")),
+            ]);
+            
+            if ($score) {
+                return -$score;
+            }
+            return strnatcmp($a->getShortName(), $b->getShortName());
+        });
+        foreach ($structures[$ns] as $cn => $c) {
+            fprintf($out, "\n\t%s%s %s ", m($c->getModifiers()), 
+                    $c->isInterface() ? "interface":"class", $c->getShortName());
+            if ($p = $c->getParentClass()) {
+                fprintf($out, "extends \\%s ", $p->getName());
+            }
+            if ($i = $c->getInterfaceNames()) {
+                fprintf($out, "implements \\%s ", 
+                        implode(", \\", array_filter($i, function($v) {
+                            return $v != "Traversable";
+                            
+                        }))
+                );
+            }
+            fprintf($out, "\n\t{\n");
+
+            $_=0;
+            foreach ($c->getConstants() as $n => $v) {
+                c($n, $c) and $_+=fprintf($out, "\t\tconst %s = %s;\n", $n, 
+                        var_export($v, true));
+            }
+            $_ and fprintf($out, "\n");
+            $_=0;
+            foreach ($c->getProperties() as $p) {
+                if ($p->getDeclaringClass()->getName() == $c->getName()) {
+                    $_+=fprintf($out, "\t\t%s\$%s;\n", m($p->getModifiers()), 
+                            $p->getName());
+                }
+            }
+            $_ and fprintf($out, "\n");
 
-    printf("\t}\n");
-    if ($class->inNamespace()) {
-        printf("}\n");
+            foreach ($c->getMethods() as $m) {
+                if ($m->getDeclaringClass()->getName() == $c->getName()) {
+                    fprintf($out, "\t\t%sfunction %s(", m($m->getModifiers()), 
+                            $m->getName());
+                    $ps = array();
+                    foreach ($m->getParameters() as $p) {
+                        $p1 = sprintf("%s%s\$%s", t($p), 
+                                $p->isPassedByReference()?"&":"", $p->getName());
+                        if ($p->isOptional()) {
+                            if ($p->isDefaultValueAvailable()) {
+                                $p1 .= sprintf(" = %s", 
+                                        var_export($p->getDefaultValue(), true));
+                            } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
+                                $p1 .= sprintf(" = NULL");
+                            } elseif ($p->isArray()) {
+                                $p1 .= " = array()";
+                            }
+                        }
+                        $ps[] = $p1;
+                    }
+                    fprintf($out, "%s)", implode(", ", $ps));
+                    if ($m->isAbstract()) {
+                        fprintf($out, ";\n\n");
+                    } else {
+                        fprintf($out, " {\n\t\t}\n\n");
+                    }
+                }
+            }
+
+            fprintf($out, "\t}\n");
+            
+        }
     }
-    printf("\n");
+    //
+    fprintf($out, "}\n\n");
 }
-
index f9ae69092c3b0f035900c0f6a7d1d096078ed437..71e5081a5f938220b3f7639ef9bd08702b756125 100644 (file)
@@ -23,7 +23,7 @@ var_dump(
 $client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
 $client->send();
 
-$ti = $client->getTransferInfo($req);
+$ti = (array) $client->getTransferInfo($req);
 var_dump(array_key_exists("ssl_engines", $ti));
 var_dump(0 < count($ti["ssl_engines"]));
 ?>
index a119951f242abd8a33cbdc8b62f9df32d2e83261..20dcef2270a75ba1aa155209bdd3c853fe6cb1a8 100644 (file)
@@ -14,7 +14,7 @@ foreach (http\Client::getAvailableDrivers() as $driver) {
        $client = new http\Client($driver);
        $response = $client->enqueue($request)->send()->getResponse();
        var_dump($response->getTransferInfo("response_code"));
-       var_dump(count($response->getTransferInfo()));
+       var_dump(count((array)$response->getTransferInfo()));
 }
 ?>
 Done