From 3424582bc72de6ce119e182fbd987cbff241cd18 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Fri, 19 Jul 2013 10:47:16 +0800 Subject: [PATCH] Add functon getKey for request/file --- build/32bits/phalcon.c | 50 +++++++++++++++++++++++++++++++++++------ build/32bits/phalcon.h | 2 ++ build/64bits/phalcon.c | 50 +++++++++++++++++++++++++++++++++++------ build/64bits/phalcon.h | 2 ++ build/safe/phalcon.c | 50 +++++++++++++++++++++++++++++++++++------ build/safe/phalcon.h | 2 ++ ext/http/request.c | 36 ++++++++++++++++++++++++----- ext/http/request/file.c | 19 ++++++++++++++-- ext/http/request/file.h | 2 ++ 9 files changed, 185 insertions(+), 28 deletions(-) diff --git a/build/32bits/phalcon.c b/build/32bits/phalcon.c index f3c08f8e6d8..6653a8e7982 100644 --- a/build/32bits/phalcon.c +++ b/build/32bits/phalcon.c @@ -88729,10 +88729,13 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); + if (zend_is_true(not_errored)) { + PHALCON_INIT_VAR(number_files); phalcon_fast_count(number_files, _FILES TSRMLS_CC); } else { + PHALCON_INIT_NVAR(number_files); ZVAL_LONG(number_files, 0); @@ -88749,11 +88752,12 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_SEPARATE(number_files); phalcon_increment(number_files); } - zend_hash_move_forward_ex(ah0, &hp0); } @@ -88794,6 +88798,25 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(file); + + zval *key; + char *string_key; + uint string_key_len; + ulong num_key; + + PHALCON_INIT_VAR(key); + + if (zend_hash_get_current_key_ex(ah0, &string_key, &string_key_len, &num_key, 0, &hp0) == HASH_KEY_IS_STRING) { + Z_TYPE_P(key) = IS_STRING; + Z_STRLEN_P(key) = string_key_len; + Z_STRVAL_P(key) = (char *) emalloc(string_key_len + 1); + memcpy(Z_STRVAL_P(key), string_key, string_key_len); + Z_STRVAL_P(key)[Z_STRLEN_P(key)] = 0; + } else { + Z_TYPE_P(key) = IS_LONG; + Z_LVAL_P(key) = num_key; + } + if (zend_is_true(not_errored)) { if (phalcon_array_isset_quick_string(file, SS("error"), 4224147407UL)) { @@ -88803,17 +88826,20 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_key(NULL, request_file, "__construct", file, 1107214344UL); + phalcon_call_method_p2_key(NULL, request_file, "__construct", file, key, 1107214344UL); + phalcon_array_append(&files, request_file, PH_SEPARATE); } } else { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_key(NULL, request_file, "__construct", file, 1107214344UL); + phalcon_call_method_p2_key(NULL, request_file, "__construct", file, key, 1107214344UL); phalcon_array_append(&files, request_file, PH_SEPARATE); } @@ -89147,6 +89173,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -89159,16 +89186,19 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ - zval *file, *name, *temp_name, *size, *type; + zval *file, *key, *name, *temp_name, *size, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &file); + phalcon_fetch_params(1, 1, 1, &file, &key); if (Z_TYPE_P(file) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); return; } + + phalcon_update_property_this_quick(this_ptr, SL("_key"), key, 250773965UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(file, SS("name"), 268211462UL)) { PHALCON_OBS_VAR(name); phalcon_array_fetch_quick_string(&name, file, SS("name"), 268211462UL, PH_NOISY); @@ -89196,6 +89226,12 @@ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Http_Request_File, getKey){ + + + RETURN_MEMBER_QUICK(this_ptr, "_key", 250773965UL); +} + static PHP_METHOD(Phalcon_Http_Request_File, getSize){ diff --git a/build/32bits/phalcon.h b/build/32bits/phalcon.h index 13c87b65926..a2b01143182 100644 --- a/build/32bits/phalcon.h +++ b/build/32bits/phalcon.h @@ -10896,6 +10896,7 @@ zend_class_entry *phalcon_http_request_file_ce; PHALCON_INIT_CLASS(Phalcon_Http_Request_File); static PHP_METHOD(Phalcon_Http_Request_File, __construct); +static PHP_METHOD(Phalcon_Http_Request_File, getKey); static PHP_METHOD(Phalcon_Http_Request_File, getSize); static PHP_METHOD(Phalcon_Http_Request_File, getName); static PHP_METHOD(Phalcon_Http_Request_File, getTempName); @@ -10913,6 +10914,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_http_request_file_method_entry){ PHP_ME(Phalcon_Http_Request_File, __construct, arginfo_phalcon_http_request_file___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Http_Request_File, getKey, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getSize, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getTempName, NULL, ZEND_ACC_PUBLIC) diff --git a/build/64bits/phalcon.c b/build/64bits/phalcon.c index c6a6a73721e..74d595916fb 100644 --- a/build/64bits/phalcon.c +++ b/build/64bits/phalcon.c @@ -88729,10 +88729,13 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); + if (zend_is_true(not_errored)) { + PHALCON_INIT_VAR(number_files); phalcon_fast_count(number_files, _FILES TSRMLS_CC); } else { + PHALCON_INIT_NVAR(number_files); ZVAL_LONG(number_files, 0); @@ -88749,11 +88752,12 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_SEPARATE(number_files); phalcon_increment(number_files); } - zend_hash_move_forward_ex(ah0, &hp0); } @@ -88794,6 +88798,25 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(file); + + zval *key; + char *string_key; + uint string_key_len; + ulong num_key; + + PHALCON_INIT_VAR(key); + + if (zend_hash_get_current_key_ex(ah0, &string_key, &string_key_len, &num_key, 0, &hp0) == HASH_KEY_IS_STRING) { + Z_TYPE_P(key) = IS_STRING; + Z_STRLEN_P(key) = string_key_len; + Z_STRVAL_P(key) = (char *) emalloc(string_key_len + 1); + memcpy(Z_STRVAL_P(key), string_key, string_key_len); + Z_STRVAL_P(key)[Z_STRLEN_P(key)] = 0; + } else { + Z_TYPE_P(key) = IS_LONG; + Z_LVAL_P(key) = num_key; + } + if (zend_is_true(not_errored)) { if (phalcon_array_isset_quick_string(file, SS("error"), 6953481232335UL)) { @@ -88803,17 +88826,20 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_key(NULL, request_file, "__construct", file, 14747615951113338888UL); + phalcon_call_method_p2_key(NULL, request_file, "__construct", file, key, 14747615951113338888UL); + phalcon_array_append(&files, request_file, PH_SEPARATE); } } else { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_key(NULL, request_file, "__construct", file, 14747615951113338888UL); + phalcon_call_method_p2_key(NULL, request_file, "__construct", file, key, 14747615951113338888UL); phalcon_array_append(&files, request_file, PH_SEPARATE); } @@ -89147,6 +89173,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -89159,16 +89186,19 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ - zval *file, *name, *temp_name, *size, *type; + zval *file, *key, *name, *temp_name, *size, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &file); + phalcon_fetch_params(1, 1, 1, &file, &key); if (Z_TYPE_P(file) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); return; } + + phalcon_update_property_this_quick(this_ptr, SL("_key"), key, 210704171469UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(file, SS("name"), 210721608966UL)) { PHALCON_OBS_VAR(name); phalcon_array_fetch_quick_string(&name, file, SS("name"), 210721608966UL, PH_NOISY); @@ -89196,6 +89226,12 @@ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Http_Request_File, getKey){ + + + RETURN_MEMBER_QUICK(this_ptr, "_key", 210704171469UL); +} + static PHP_METHOD(Phalcon_Http_Request_File, getSize){ diff --git a/build/64bits/phalcon.h b/build/64bits/phalcon.h index 13c87b65926..a2b01143182 100644 --- a/build/64bits/phalcon.h +++ b/build/64bits/phalcon.h @@ -10896,6 +10896,7 @@ zend_class_entry *phalcon_http_request_file_ce; PHALCON_INIT_CLASS(Phalcon_Http_Request_File); static PHP_METHOD(Phalcon_Http_Request_File, __construct); +static PHP_METHOD(Phalcon_Http_Request_File, getKey); static PHP_METHOD(Phalcon_Http_Request_File, getSize); static PHP_METHOD(Phalcon_Http_Request_File, getName); static PHP_METHOD(Phalcon_Http_Request_File, getTempName); @@ -10913,6 +10914,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_http_request_file_method_entry){ PHP_ME(Phalcon_Http_Request_File, __construct, arginfo_phalcon_http_request_file___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Http_Request_File, getKey, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getSize, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getTempName, NULL, ZEND_ACC_PUBLIC) diff --git a/build/safe/phalcon.c b/build/safe/phalcon.c index 11c471e64ff..ce73617c0e1 100644 --- a/build/safe/phalcon.c +++ b/build/safe/phalcon.c @@ -88729,10 +88729,13 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); + if (zend_is_true(not_errored)) { + PHALCON_INIT_VAR(number_files); phalcon_fast_count(number_files, _FILES TSRMLS_CC); } else { + PHALCON_INIT_NVAR(number_files); ZVAL_LONG(number_files, 0); @@ -88749,11 +88752,12 @@ static PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_SEPARATE(number_files); phalcon_increment(number_files); } - zend_hash_move_forward_ex(ah0, &hp0); } @@ -88794,6 +88798,25 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(file); + + zval *key; + char *string_key; + uint string_key_len; + ulong num_key; + + PHALCON_INIT_VAR(key); + + if (zend_hash_get_current_key_ex(ah0, &string_key, &string_key_len, &num_key, 0, &hp0) == HASH_KEY_IS_STRING) { + Z_TYPE_P(key) = IS_STRING; + Z_STRLEN_P(key) = string_key_len; + Z_STRVAL_P(key) = (char *) emalloc(string_key_len + 1); + memcpy(Z_STRVAL_P(key), string_key, string_key_len); + Z_STRVAL_P(key)[Z_STRLEN_P(key)] = 0; + } else { + Z_TYPE_P(key) = IS_LONG; + Z_LVAL_P(key) = num_key; + } + if (zend_is_true(not_errored)) { if (phalcon_array_isset_string(file, SS("error"))) { @@ -88803,17 +88826,20 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_noret(request_file, "__construct", file); + phalcon_call_method_p2_noret(request_file, "__construct", file, key); + phalcon_array_append(&files, request_file, PH_SEPARATE); } } else { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_noret(request_file, "__construct", file); + phalcon_call_method_p2_noret(request_file, "__construct", file, key); phalcon_array_append(&files, request_file, PH_SEPARATE); } @@ -89147,6 +89173,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -89159,16 +89186,19 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ - zval *file, *name, *temp_name, *size, *type; + zval *file, *key, *name, *temp_name, *size, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &file); + phalcon_fetch_params(1, 1, 1, &file, &key); if (Z_TYPE_P(file) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); return; } + + phalcon_update_property_this(this_ptr, SL("_key"), key TSRMLS_CC); + if (phalcon_array_isset_string(file, SS("name"))) { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, file, SL("name"), PH_NOISY); @@ -89196,6 +89226,12 @@ static PHP_METHOD(Phalcon_Http_Request_File, __construct){ PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Http_Request_File, getKey){ + + + RETURN_MEMBER(this_ptr, "_key"); +} + static PHP_METHOD(Phalcon_Http_Request_File, getSize){ diff --git a/build/safe/phalcon.h b/build/safe/phalcon.h index 13c87b65926..a2b01143182 100644 --- a/build/safe/phalcon.h +++ b/build/safe/phalcon.h @@ -10896,6 +10896,7 @@ zend_class_entry *phalcon_http_request_file_ce; PHALCON_INIT_CLASS(Phalcon_Http_Request_File); static PHP_METHOD(Phalcon_Http_Request_File, __construct); +static PHP_METHOD(Phalcon_Http_Request_File, getKey); static PHP_METHOD(Phalcon_Http_Request_File, getSize); static PHP_METHOD(Phalcon_Http_Request_File, getName); static PHP_METHOD(Phalcon_Http_Request_File, getTempName); @@ -10913,6 +10914,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_http_request_file_method_entry){ PHP_ME(Phalcon_Http_Request_File, __construct, arginfo_phalcon_http_request_file___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Http_Request_File, getKey, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getSize, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getTempName, NULL, ZEND_ACC_PUBLIC) diff --git a/ext/http/request.c b/ext/http/request.c index 8b08147cbed..183368166f7 100755 --- a/ext/http/request.c +++ b/ext/http/request.c @@ -1105,10 +1105,13 @@ PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); + if (zend_is_true(not_errored)) { + PHALCON_INIT_VAR(number_files); phalcon_fast_count(number_files, _FILES TSRMLS_CC); } else { + PHALCON_INIT_NVAR(number_files); ZVAL_LONG(number_files, 0); @@ -1125,11 +1128,12 @@ PHP_METHOD(Phalcon_Http_Request, hasFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_SEPARATE(number_files); phalcon_increment(number_files); } - zend_hash_move_forward_ex(ah0, &hp0); } @@ -1176,6 +1180,25 @@ PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(file); + + zval *key; + char *string_key; + uint string_key_len; + ulong num_key; + + PHALCON_INIT_VAR(key); + + if (zend_hash_get_current_key_ex(ah0, &string_key, &string_key_len, &num_key, 0, &hp0) == HASH_KEY_IS_STRING) { + Z_TYPE_P(key) = IS_STRING; + Z_STRLEN_P(key) = string_key_len; + Z_STRVAL_P(key) = (char *) emalloc(string_key_len + 1); + memcpy(Z_STRVAL_P(key), string_key, string_key_len); + Z_STRVAL_P(key)[Z_STRLEN_P(key)] = 0; + } else { + Z_TYPE_P(key) = IS_LONG; + Z_LVAL_P(key) = num_key; + } + if (zend_is_true(not_errored)) { if (phalcon_array_isset_string(file, SS("error"))) { @@ -1185,17 +1208,20 @@ PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ PHALCON_INIT_NVAR(error); ZVAL_BOOL(error, 1); } - if (!zend_is_true(error)) { + if (Z_TYPE_P(error) == IS_ARRAY) { + // TODO: Waiting for Superman to perfect + } else if (!zend_is_true(error)) { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_noret(request_file, "__construct", file); + phalcon_call_method_p2_noret(request_file, "__construct", file, key); + phalcon_array_append(&files, request_file, PH_SEPARATE); } } else { PHALCON_INIT_NVAR(request_file); object_init_ex(request_file, phalcon_http_request_file_ce); - phalcon_call_method_p1_noret(request_file, "__construct", file); + phalcon_call_method_p2_noret(request_file, "__construct", file, key); phalcon_array_append(&files, request_file, PH_SEPARATE); } diff --git a/ext/http/request/file.c b/ext/http/request/file.c index f861a3c74e8..f8dccc621b9 100644 --- a/ext/http/request/file.c +++ b/ext/http/request/file.c @@ -69,6 +69,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -86,16 +87,19 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ */ PHP_METHOD(Phalcon_Http_Request_File, __construct){ - zval *file, *name, *temp_name, *size, *type; + zval *file, *key, *name, *temp_name, *size, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &file); + phalcon_fetch_params(1, 1, 1, &file, &key); if (Z_TYPE_P(file) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); return; } + + phalcon_update_property_this(this_ptr, SL("_key"), key TSRMLS_CC); + if (phalcon_array_isset_string(file, SS("name"))) { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, file, SL("name"), PH_NOISY); @@ -123,6 +127,17 @@ PHP_METHOD(Phalcon_Http_Request_File, __construct){ PHALCON_MM_RESTORE(); } +/** + * Returns the file key of the uploaded file + * + * @return mixed + */ +PHP_METHOD(Phalcon_Http_Request_File, getKey){ + + + RETURN_MEMBER(this_ptr, "_key"); +} + /** * Returns the file size of the uploaded file * diff --git a/ext/http/request/file.h b/ext/http/request/file.h index f5751883822..161011bb8c0 100644 --- a/ext/http/request/file.h +++ b/ext/http/request/file.h @@ -22,6 +22,7 @@ extern zend_class_entry *phalcon_http_request_file_ce; PHALCON_INIT_CLASS(Phalcon_Http_Request_File); PHP_METHOD(Phalcon_Http_Request_File, __construct); +PHP_METHOD(Phalcon_Http_Request_File, getKey); PHP_METHOD(Phalcon_Http_Request_File, getSize); PHP_METHOD(Phalcon_Http_Request_File, getName); PHP_METHOD(Phalcon_Http_Request_File, getTempName); @@ -39,6 +40,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_http_request_file_method_entry){ PHP_ME(Phalcon_Http_Request_File, __construct, arginfo_phalcon_http_request_file___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Http_Request_File, getKey, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getSize, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request_File, getTempName, NULL, ZEND_ACC_PUBLIC)