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-2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 PHP_HTTP_API 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
)
21 } else if (parent_ce
&& !instanceof_function(ce
, parent_ce TSRMLS_CC
)) {
22 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "Class %s does not extend %s", ce
->name
, parent_ce
->name
);
26 ov
= create(ce
, intern_ptr
, obj_ptr TSRMLS_CC
);
33 PHP_HTTP_API zend_error_handling_t
php_http_object_get_error_handling(zval
*object TSRMLS_DC
)
38 zeh
= zend_read_property(Z_OBJCE_P(object
), object
, ZEND_STRL("errorHandling"), 0 TSRMLS_CC
);
39 if (Z_TYPE_P(zeh
) != IS_NULL
) {
40 lzeh
= php_http_ztyp(IS_LONG
, zeh
);
45 zeh
= zend_read_static_property(php_http_object_class_entry
, ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC
);
46 if (Z_TYPE_P(zeh
) != IS_NULL
) {
47 lzeh
= php_http_ztyp(IS_LONG
, zeh
);
55 zend_object_value
php_http_object_new(zend_class_entry
*ce TSRMLS_DC
)
57 return php_http_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
60 zend_object_value
php_http_object_new_ex(zend_class_entry
*ce
, void *nothing
, php_http_object_t
**ptr TSRMLS_DC
)
64 o
= ecalloc(1, sizeof(php_http_object_t
));
65 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
66 object_properties_init((zend_object
*) o
, ce
);
72 o
->zv
.handle
= zend_objects_store_put(o
, NULL
, (zend_objects_free_object_storage_t
) zend_objects_free_object_storage
, NULL TSRMLS_CC
);
73 o
->zv
.handlers
= zend_get_std_object_handlers();
78 ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getErrorHandling
, 0, 0, 0)
80 PHP_METHOD(HttpObject
, getErrorHandling
)
82 zval
*zeh
= zend_read_property(php_http_object_class_entry
, getThis(), ZEND_STRL("errorHandling"), 0 TSRMLS_CC
);
83 RETURN_ZVAL(zeh
, 1, 0);
86 ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_setErrorHandling
, 0, 0, 1)
89 PHP_METHOD(HttpObject
, setErrorHandling
)
93 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &eh
)) {
98 zend_update_property_long(php_http_object_class_entry
, getThis(), ZEND_STRL("errorHandling"), eh TSRMLS_CC
);
102 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "unknown error handling code (%ld)", eh
);
107 RETURN_ZVAL(getThis(), 1, 0);
110 ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getDefaultErrorHandling
, 0, 0, 0)
112 PHP_METHOD(HttpObject
, getDefaultErrorHandling
)
114 zval
*zdeh
= zend_read_static_property(php_http_object_class_entry
, ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC
);
115 RETURN_ZVAL(zdeh
, 1, 0);
118 ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_setDefaultErrorHandling
, 0, 0, 1)
121 PHP_METHOD(HttpObject
, setDefaultErrorHandling
)
125 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &eh
)) {
130 zend_update_static_property_long(php_http_object_class_entry
, ZEND_STRL("defaultErrorHandling"), eh TSRMLS_CC
);
134 php_http_error(HE_WARNING
, PHP_HTTP_E_RUNTIME
, "unknown error handling code (%ld)", eh
);
140 ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_triggerError
, 0, 0, 3)
141 ZEND_ARG_INFO(0, error_type
)
142 ZEND_ARG_INFO(0, error_code
)
143 ZEND_ARG_INFO(0, error_message
)
145 PHP_METHOD(HttpObject
, triggerError
)
151 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "lls", &eh
, &code
, &msg_str
, &msg_len
)) {
152 php_http_error(eh TSRMLS_CC
, code
, "%.*s", msg_len
, msg_str
);
156 static zend_function_entry php_http_object_methods
[] = {
157 PHP_ME(HttpObject
, setErrorHandling
, ai_HttpObject_setErrorHandling
, ZEND_ACC_PUBLIC
)
158 PHP_ME(HttpObject
, getErrorHandling
, ai_HttpObject_getErrorHandling
, ZEND_ACC_PUBLIC
)
159 PHP_ME(HttpObject
, setDefaultErrorHandling
, ai_HttpObject_setDefaultErrorHandling
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
160 PHP_ME(HttpObject
, getDefaultErrorHandling
, ai_HttpObject_getDefaultErrorHandling
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
161 PHP_ME(HttpObject
, triggerError
, ai_HttpObject_triggerError
, ZEND_ACC_PUBLIC
)
166 zend_class_entry
*php_http_object_class_entry
;
168 PHP_MINIT_FUNCTION(http_object
)
170 zend_class_entry ce
= {0};
172 INIT_NS_CLASS_ENTRY(ce
, "http", "Object", php_http_object_methods
);
173 php_http_object_class_entry
= zend_register_internal_class_ex(&ce
, NULL
, NULL TSRMLS_CC
);
174 php_http_object_class_entry
->ce_flags
|= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
;
175 php_http_object_class_entry
->create_object
= php_http_object_new
;
177 zend_declare_property_null(php_http_object_class_entry
, ZEND_STRL("defaultErrorHandling"), (ZEND_ACC_STATIC
|ZEND_ACC_PROTECTED
) TSRMLS_CC
);
178 zend_declare_property_null(php_http_object_class_entry
, ZEND_STRL("errorHandling"), ZEND_ACC_PROTECTED TSRMLS_CC
);
180 zend_declare_class_constant_long(php_http_object_class_entry
, ZEND_STRL("EH_NORMAL"), EH_NORMAL TSRMLS_CC
);
181 zend_declare_class_constant_long(php_http_object_class_entry
, ZEND_STRL("EH_SUPPRESS"), EH_SUPPRESS TSRMLS_CC
);
182 zend_declare_class_constant_long(php_http_object_class_entry
, ZEND_STRL("EH_THROW"), EH_THROW TSRMLS_CC
);
193 * vim600: noet sw=4 ts=4 fdm=marker
194 * vim<600: noet sw=4 ts=4