- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &string, &length, &class_name, &class_length)) {
- if ((msg = http_message_parse(string, length))) {
- zend_class_entry *ce = http_message_object_ce;
-
- if (class_name && *class_name) {
- ce = zend_fetch_class(class_name, class_length, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);
- if (ce && !instanceof_function(ce, http_message_object_ce TSRMLS_CC)) {
- http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Class %s does not extend HttpMessage", class_name);
- ce = NULL;
- }
- }
- if (ce) {
- RETVAL_OBJVAL(http_message_object_new_ex(ce, msg, NULL), 0);
- }
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &string, &length, &cn, &cl)) {
+ if (length) {
+ msg = http_message_parse(string, length);
+ }
+ if ((msg || !length) && SUCCESS == http_object_new(&ov, cn, cl, _http_message_object_new_ex, http_message_object_ce, msg, &obj)) {
+ RETVAL_OBJVAL(ov, 0);
+ }
+ if (obj && !obj->message) {
+ obj->message = http_message_new();
+ }
+ }
+ SET_EH_NORMAL();
+}
+/* }}} */
+
+/* {{{ proto static HttpMessage HttpMessage::fromEnv(int type[, string class_name = "HttpMessage"])
+ Create a new HttpMessage object from environment representing either current request or response */
+PHP_METHOD(HttpMessage, fromEnv)
+{
+ char *cn = NULL;
+ int cl = 0;
+ long type;
+ http_message_object *obj = NULL;
+ zend_object_value ov;
+
+ RETVAL_NULL();
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s", &type, &cn, &cl)) {
+ if (SUCCESS == http_object_new(&ov, cn, cl, _http_message_object_new_ex, http_message_object_ce, http_message_init_env(NULL, type), &obj)) {
+ RETVAL_OBJVAL(ov, 0);
+ }
+ if (obj && !obj->message) {
+ obj->message = http_message_new();