2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 zend_object_value
php_http_object_new(zend_class_entry
*ce TSRMLS_DC
)
17 return php_http_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
20 zend_object_value
php_http_object_new_ex(zend_class_entry
*ce
, void *nothing
, php_http_object_t
**ptr TSRMLS_DC
)
24 o
= ecalloc(1, sizeof(php_http_object_t
));
25 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
26 object_properties_init((zend_object
*) o
, ce
);
32 o
->zv
.handle
= zend_objects_store_put(o
, NULL
, (zend_objects_free_object_storage_t
) zend_objects_free_object_storage
, NULL TSRMLS_CC
);
33 o
->zv
.handlers
= zend_get_std_object_handlers();
38 ZEND_RESULT_CODE
php_http_new(zend_object_value
*ovp
, zend_class_entry
*ce
, php_http_new_t create
, zend_class_entry
*parent_ce
, void *intern_ptr
, void **obj_ptr TSRMLS_DC
)
44 } else if (parent_ce
&& !instanceof_function(ce
, parent_ce TSRMLS_CC
)) {
45 php_http_throw(unexpected_val
, "Class %s does not extend %s", ce
->name
, parent_ce
->name
);
49 ov
= create(ce
, intern_ptr
, obj_ptr TSRMLS_CC
);
56 static inline zend_function
*get_object_method(zval
*zobject
, zval
*zmeth TSRMLS_DC
)
58 #if PHP_VERSION_ID >= 50400
59 return Z_OBJ_HT_P(zobject
)->get_method(&zobject
, Z_STRVAL_P(zmeth
), Z_STRLEN_P(zmeth
), NULL TSRMLS_CC
);
61 return Z_OBJ_HT_P(zobject
)->get_method(&zobject
, Z_STRVAL_P(zmeth
), Z_STRLEN_P(zmeth
) TSRMLS_CC
);
65 php_http_object_method_t
*php_http_object_method_init(php_http_object_method_t
*cb
, zval
*zobject
, const char *method_str
, size_t method_len TSRMLS_DC
)
70 cb
= ecalloc(1, sizeof(*cb
));
72 memset(cb
, 0, sizeof(*cb
));
76 ZVAL_STRINGL(zfn
, method_str
, method_len
, 1);
78 cb
->fci
.size
= sizeof(cb
->fci
);
79 cb
->fci
.function_name
= zfn
;
80 cb
->fcc
.initialized
= 1;
81 cb
->fcc
.calling_scope
= cb
->fcc
.called_scope
= Z_OBJCE_P(zobject
);
82 cb
->fcc
.function_handler
= get_object_method(zobject
, cb
->fci
.function_name TSRMLS_CC
);
87 void php_http_object_method_dtor(php_http_object_method_t
*cb
)
89 if (cb
->fci
.function_name
) {
90 zval_ptr_dtor(&cb
->fci
.function_name
);
91 cb
->fci
.function_name
= NULL
;
95 void php_http_object_method_free(php_http_object_method_t
**cb
)
98 php_http_object_method_dtor(*cb
);
104 ZEND_RESULT_CODE
php_http_object_method_call(php_http_object_method_t
*cb
, zval
*zobject
, zval
**retval_ptr
, int argc
, zval
***args TSRMLS_DC
)
110 cb
->fci
.object_ptr
= zobject
;
111 cb
->fcc
.object_ptr
= zobject
;
113 cb
->fci
.retval_ptr_ptr
= retval_ptr
? retval_ptr
: &retval
;
115 cb
->fci
.param_count
= argc
;
116 cb
->fci
.params
= args
;
118 if (cb
->fcc
.called_scope
!= Z_OBJCE_P(zobject
)) {
119 cb
->fcc
.called_scope
= Z_OBJCE_P(zobject
);
120 cb
->fcc
.function_handler
= get_object_method(zobject
, cb
->fci
.function_name TSRMLS_CC
);
123 rv
= zend_call_function(&cb
->fci
, &cb
->fcc TSRMLS_CC
);
125 zval_ptr_dtor(&zobject
);
126 if (!retval_ptr
&& retval
) {
127 zval_ptr_dtor(&retval
);
138 * vim600: noet sw=4 ts=4 fdm=marker
139 * vim<600: noet sw=4 ts=4