remove pass_state callback flag
[m6w6/ext-http] / php_http_client_factory.c
index 45986c417d3f7ca81b604cc26ab1c75087620fcb..1b14f481dac82a2592f3ed056b808ed33a8e8cc6 100644 (file)
@@ -35,7 +35,7 @@ PHP_HTTP_API STATUS php_http_client_factory_get_driver(const char *name_str, siz
        return FAILURE;
 }
 
-static zend_class_entry *php_http_client_factory_get_class_entry(zval *this_ptr, const char *for_str, size_t for_len TSRMLS_DC)
+static zend_class_entry *php_http_client_factory_find_class_entry(zval *this_ptr, const char *for_str, size_t for_len TSRMLS_DC)
 {
        /* stupid non-const api */
        char *sc = estrndup(for_str, for_len);
@@ -55,7 +55,7 @@ static zend_class_entry *php_http_client_factory_get_class_entry(zval *this_ptr,
 #define PHP_HTTP_REQUEST_FACTORY_ALIAS(method, func)   PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpClientFactory, method))
 #define PHP_HTTP_REQUEST_FACTORY_MALIAS(me, al, vis)   ZEND_FENTRY(me, ZEND_MN(HttpClientFactory_##al), PHP_HTTP_ARGS(HttpClientFactory, al), vis)
 
-PHP_HTTP_BEGIN_ARGS(__construct, 1)
+PHP_HTTP_BEGIN_ARGS(__construct, 0)
        PHP_HTTP_ARG_VAL(options, 0)
 PHP_HTTP_END_ARGS;
 PHP_HTTP_BEGIN_ARGS(createClient, 0)
@@ -74,8 +74,14 @@ PHP_HTTP_END_ARGS;
 PHP_HTTP_EMPTY_ARGS(getDriver);
 PHP_HTTP_EMPTY_ARGS(getAvailableDrivers);
 
-zend_class_entry *php_http_client_factory_class_entry;
-zend_function_entry php_http_client_factory_method_entry[] = {
+static zend_class_entry *php_http_client_factory_class_entry;
+
+zend_class_entry *php_http_client_factory_get_class_entry(void)
+{
+       return php_http_client_factory_class_entry;
+}
+
+static zend_function_entry php_http_client_factory_method_entry[] = {
        PHP_HTTP_REQUEST_FACTORY_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_HTTP_REQUEST_FACTORY_ME(createClient, ZEND_ACC_PUBLIC)
        PHP_HTTP_REQUEST_FACTORY_ME(createPool, ZEND_ACC_PUBLIC)
@@ -88,7 +94,7 @@ zend_function_entry php_http_client_factory_method_entry[] = {
 
 PHP_METHOD(HttpClientFactory, __construct)
 {
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                HashTable *options = NULL;
 
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &options)) {
@@ -113,10 +119,10 @@ PHP_METHOD(HttpClientFactory, createClient)
 {
        zval *options = NULL;
 
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &options)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-                               zval *zdriver, *os;
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+                               zval *zdriver;
                                zend_object_value ov;
                                zend_class_entry *class_entry = NULL;
                                php_http_client_t *req = NULL;
@@ -144,14 +150,13 @@ PHP_METHOD(HttpClientFactory, createClient)
 
                                        req = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC);
                                        if (req) {
-                                               if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientClass") TSRMLS_CC))) {
+                                               if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientClass") TSRMLS_CC))) {
                                                        class_entry = driver.client_ops->class_entry();
                                                }
 
                                                if (SUCCESS == php_http_new(&ov, class_entry, driver.client_ops->create_object, driver.client_ops->class_entry(), req, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
-
-                                                       zend_call_method_with_1_params(&return_value, Z_OBJCE_P(return_value), NULL, "__construct", NULL, options);
+                                                       zend_call_method(&return_value, Z_OBJCE_P(return_value), NULL, ZEND_STRL("__construct"), NULL, !!options, options, NULL TSRMLS_CC);
                                                } else {
                                                        php_http_client_free(&req);
                                                }
@@ -169,11 +174,11 @@ PHP_METHOD(HttpClientFactory, createClient)
 PHP_METHOD(HttpClientFactory, createPool)
 {
        int argc = 0;
-       zval ***argv;
+       zval ***argv = NULL;
 
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|*", &argv, &argc)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &argv, &argc)) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                int i;
                                zval *zdriver;
                                zend_object_value ov;
@@ -202,14 +207,14 @@ PHP_METHOD(HttpClientFactory, createPool)
 
                                        pool = php_http_client_pool_init(NULL, driver.client_pool_ops, rf, NULL TSRMLS_CC);
                                        if (pool) {
-                                               if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientPoolClass") TSRMLS_CC))) {
+                                               if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientPoolClass") TSRMLS_CC))) {
                                                        class_entry = driver.client_pool_ops->class_entry();
                                                }
 
                                                if (SUCCESS == php_http_new(&ov, class_entry, driver.client_pool_ops->create_object, driver.client_pool_ops->class_entry(), pool, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
                                                        for (i = 0; i < argc; ++i) {
-                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) {
                                                                        php_http_client_pool_attach(pool, *(argv[i]));
                                                                }
                                                        }
@@ -232,9 +237,9 @@ PHP_METHOD(HttpClientFactory, createDataShare)
        int argc = 0;
        zval ***argv;
 
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|*", &argv, &argc)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &argv, &argc)) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                int i;
                                zval *zdriver;
                                zend_object_value ov;
@@ -263,14 +268,14 @@ PHP_METHOD(HttpClientFactory, createDataShare)
 
                                        share = php_http_client_datashare_init(NULL, driver.client_datashare_ops, rf, NULL TSRMLS_CC);
                                        if (share) {
-                                               if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientDataShareClass") TSRMLS_CC))) {
+                                               if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientDataShareClass") TSRMLS_CC))) {
                                                        class_entry = driver.client_datashare_ops->class_entry();
                                                }
 
                                                if (SUCCESS == php_http_new(&ov, class_entry, driver.client_datashare_ops->create_object, driver.client_datashare_ops->class_entry(), share, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
                                                        for (i = 0; i < argc; ++i) {
-                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) {
                                                                        php_http_client_datashare_attach(share, *(argv[i]));
                                                                }
                                                        }
@@ -315,7 +320,7 @@ PHP_MINIT_FUNCTION(http_client_factory)
 {
        zend_hash_init(&php_http_client_factory_drivers, 0, NULL, NULL, 1);
 
-       PHP_HTTP_REGISTER_CLASS(http\\Client, Factory, http_client_factory, php_http_object_class_entry, 0);
+       PHP_HTTP_REGISTER_CLASS(http\\Client, Factory, http_client_factory, php_http_object_get_class_entry(), 0);
        php_http_client_factory_class_entry->create_object = php_http_client_factory_new;
 
        zend_declare_property_stringl(php_http_client_factory_class_entry, ZEND_STRL("driver"), ZEND_STRL("curl"), ZEND_ACC_PROTECTED TSRMLS_CC);