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 STATUS
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 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
)
61 cb
= ecalloc(1, sizeof(*cb
));
63 memset(cb
, 0, sizeof(*cb
));
67 ZVAL_STRINGL(zfn
, method_str
, method_len
, 1);
69 cb
->fci
.size
= sizeof(cb
->fci
);
70 cb
->fci
.function_name
= zfn
;
71 cb
->fcc
.initialized
= 1;
72 cb
->fcc
.calling_scope
= cb
->fcc
.called_scope
= Z_OBJCE_P(zobject
);
73 cb
->fcc
.function_handler
= Z_OBJ_HT_P(zobject
)->get_method(&zobject
, Z_STRVAL_P(cb
->fci
.function_name
), Z_STRLEN_P(cb
->fci
.function_name
), NULL TSRMLS_CC
);
78 void php_http_object_method_dtor(php_http_object_method_t
*cb
)
80 if (cb
->fci
.function_name
) {
81 zval_ptr_dtor(&cb
->fci
.function_name
);
82 cb
->fci
.function_name
= NULL
;
86 void php_http_object_method_free(php_http_object_method_t
**cb
)
89 php_http_object_method_dtor(*cb
);
95 STATUS
php_http_object_method_call(php_http_object_method_t
*cb
, zval
*zobject
, zval
**retval_ptr
, int argc
, zval
***args TSRMLS_DC
)
101 cb
->fci
.object_ptr
= zobject
;
102 cb
->fcc
.object_ptr
= zobject
;
104 cb
->fci
.retval_ptr_ptr
= retval_ptr
? retval_ptr
: &retval
;
106 cb
->fci
.param_count
= argc
;
107 cb
->fci
.params
= args
;
109 if (cb
->fcc
.called_scope
!= Z_OBJCE_P(zobject
)) {
110 cb
->fcc
.called_scope
= Z_OBJCE_P(zobject
);
111 cb
->fcc
.function_handler
= Z_OBJ_HT_P(zobject
)->get_method(&zobject
, Z_STRVAL_P(cb
->fci
.function_name
), Z_STRLEN_P(cb
->fci
.function_name
), NULL TSRMLS_CC
);
114 rv
= zend_call_function(&cb
->fci
, &cb
->fcc TSRMLS_CC
);
116 zval_ptr_dtor(&zobject
);
117 if (!retval_ptr
&& retval
) {
118 zval_ptr_dtor(&retval
);
129 * vim600: noet sw=4 ts=4 fdm=marker
130 * vim<600: noet sw=4 ts=4