Skip to content

Commit

Permalink
Fixed #1932 Phalcon\Http\Request\File extend SplFileInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsxin committed Mar 27, 2014
1 parent aa7a920 commit e53775d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 0 additions & 1 deletion ext/db/result/pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,3 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, nextRowset){

RETURN_MM();
}

31 changes: 29 additions & 2 deletions ext/http/request/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "http/request/exception.h"

#include <main/SAPI.h>
#include <ext/spl/spl_directory.h>

#include "kernel/main.h"
#include "kernel/memory.h"
Expand Down Expand Up @@ -66,6 +67,7 @@ PHP_METHOD(Phalcon_Http_Request_File, getKey);
PHP_METHOD(Phalcon_Http_Request_File, isUploadedFile);
PHP_METHOD(Phalcon_Http_Request_File, moveTo);
PHP_METHOD(Phalcon_Http_Request_File, __set_state);
PHP_METHOD(Phalcon_Http_Request_File, getExtension);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_request_file___construct, 0, 0, 1)
ZEND_ARG_INFO(0, file)
Expand All @@ -87,6 +89,7 @@ static const zend_function_entry phalcon_http_request_file_method_entry[] = {
PHP_ME(Phalcon_Http_Request_File, isUploadedFile, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Http_Request_File, moveTo, arginfo_phalcon_http_request_fileinterface_moveto, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Http_Request_File, __set_state, arginfo_phalcon_http_request_file___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Http_Request_File, getExtension, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Expand All @@ -95,7 +98,7 @@ static const zend_function_entry phalcon_http_request_file_method_entry[] = {
*/
PHALCON_INIT_CLASS(Phalcon_Http_Request_File){

PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0);
PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Request, File, http_request_file, spl_ce_SplFileInfo, phalcon_http_request_file_method_entry, 0);

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);
Expand All @@ -104,6 +107,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){
zend_declare_property_null(phalcon_http_request_file_ce, SL("_real_type"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_http_request_file_ce, SL("_error"), ZEND_ACC_PROTECTED TSRMLS_CC);
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("_extension"), ZEND_ACC_PROTECTED TSRMLS_CC);

zend_class_implements(phalcon_http_request_file_ce TSRMLS_CC, 1, phalcon_http_request_fileinterface_ce);

Expand All @@ -118,6 +122,7 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_File){
PHP_METHOD(Phalcon_Http_Request_File, __construct){

zval *file, *name, *temp_name, *size, *type, *error, *key = NULL;
zval *constant, *extension = NULL;

PHALCON_MM_GROW();

Expand All @@ -131,13 +136,22 @@ PHP_METHOD(Phalcon_Http_Request_File, __construct){
PHALCON_OBS_VAR(name);
phalcon_array_fetch_string(&name, file, SL("name"), PH_NOISY);
phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC);

PHALCON_INIT_VAR(constant);
if (zend_get_constant(SL("PATHINFO_EXTENSION"), constant TSRMLS_CC)) {
PHALCON_CALL_FUNCTION(&extension, "pathinfo", name, constant);
phalcon_update_property_this(this_ptr, SL("_extension"), extension TSRMLS_CC);
}
}

if (phalcon_array_isset_string(file, SS("tmp_name"))) {
PHALCON_OBS_VAR(temp_name);
phalcon_array_fetch_string(&temp_name, file, SL("tmp_name"), PH_NOISY);
phalcon_update_property_this(this_ptr, SL("_tmp"), temp_name TSRMLS_CC);
}
} else {
PHALCON_INIT_VAR(temp_name);
ZVAL_NULL(temp_name);
}

if (phalcon_array_isset_string(file, SS("size"))) {
PHALCON_OBS_VAR(size);
Expand All @@ -161,6 +175,8 @@ PHP_METHOD(Phalcon_Http_Request_File, __construct){
phalcon_update_property_this(this_ptr, SL("_key"), key TSRMLS_CC);
}

PHALCON_CALL_PARENT(NULL, phalcon_http_request_file_ce, this_ptr, "__construct", temp_name);

PHALCON_MM_RESTORE();
}

Expand Down Expand Up @@ -319,3 +335,14 @@ PHP_METHOD(Phalcon_Http_Request_File, __set_state) {
PHALCON_CALL_METHOD(NULL, return_value, "__construct", data);
PHALCON_MM_RESTORE();
}

/**
* Returns the file extension
*
* @return string
*/
PHP_METHOD(Phalcon_Http_Request_File, getExtension){


RETURN_MEMBER(this_ptr, "_extension ");
}

0 comments on commit e53775d

Please sign in to comment.