diff --git a/library.h b/library.h index 2ae5599..f6d5936 100644 --- a/library.h +++ b/library.h @@ -23,12 +23,38 @@ #define redis_sock_write_sstr(redis_sock, sstr) \ redis_sock_write(redis_sock, (sstr)->c, (sstr)->len) +#if PHP_VERSION_ID < 70200 +/* drop return type hinting in PHP 7.0 and 7.1*/ +#undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX +#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) +#endif + #if PHP_VERSION_ID < 80000 #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(ZSTR_VAL((zstr)), ZSTR_LEN((zstr))) + + /* use RedisException when ValueError not available */ + #define REDIS_VALUE_EXCEPTION(m) REDIS_THROW_EXCEPTION(m, 0) + #define RETURN_THROWS() RETURN_FALSE + + /* default value only managed in 8+ */ + #define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \ + ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) + + /* union type only managed in 8+ */ + #define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) ZEND_ARG_INFO(pass_by_ref, name) + + #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) + + #define IS_MIXED 0 #else #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(zstr) + + #define REDIS_VALUE_EXCEPTION(m) zend_value_error(m) #endif + void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id); PHP_REDIS_API int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass); diff --git a/redis.c b/redis.c index ad6acff..054ed92 100644 --- a/redis.c +++ b/redis.c @@ -64,7 +64,6 @@ extern int le_cluster_slot_cache; extern zend_function_entry redis_array_functions[]; extern zend_function_entry redis_cluster_functions[]; -extern zend_function_entry redis_sentinel_functions[]; int le_redis_pconnect; @@ -873,7 +872,7 @@ PHP_MINIT_FUNCTION(redis) redis_cluster_ce->create_object = create_cluster_context; /* RedisSentinel class */ - INIT_CLASS_ENTRY(redis_sentinel_class_entry, "RedisSentinel", redis_sentinel_functions); + INIT_CLASS_ENTRY(redis_sentinel_class_entry, "RedisSentinel", redis_sentinel_get_methods()); redis_sentinel_ce = zend_register_internal_class(&redis_sentinel_class_entry); redis_sentinel_ce->create_object = create_sentinel_object; @@ -1080,17 +1079,17 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } if (timeout < 0L || timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid connect timeout", 0); + REDIS_VALUE_EXCEPTION("Invalid connect timeout"); return FAILURE; } if (read_timeout < 0L || read_timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid read timeout", 0); + REDIS_VALUE_EXCEPTION("Invalid read timeout"); return FAILURE; } if (retry_interval < 0L || retry_interval > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid retry interval", 0); + REDIS_VALUE_EXCEPTION("Invalid retry interval"); return FAILURE; } diff --git a/redis_array.c b/redis_array.c index 9d6883c..7e7f600 100644 --- a/redis_array.c +++ b/redis_array.c @@ -38,7 +38,7 @@ extern zend_class_entry *redis_ce; zend_class_entry *redis_array_ce; ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) - ZEND_ARG_INFO(0, name_or_hosts) + ZEND_ARG_TYPE_MASK(0, name_or_hosts, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_ARRAY_INFO(0, options, 0) ZEND_END_ARG_INFO() @@ -239,7 +239,12 @@ PHP_METHOD(RedisArray, __construct) * for ages so we can't really change it until the next major version. */ if (Z_TYPE_P(z0) != IS_ARRAY && Z_TYPE_P(z0) != IS_STRING) +#if PHP_VERSION_ID < 80000 WRONG_PARAM_COUNT; +#else + zend_argument_type_error(1, "must be of type string|array, %s given", zend_zval_type_name(z0)); + RETURN_THROWS(); +#endif /* If it's a string we want to load the array from ini information */ if (Z_TYPE_P(z0) == IS_STRING) { diff --git a/redis_sentinel.c b/redis_sentinel.c index e5148e9..b89cdb3 100644 --- a/redis_sentinel.c +++ b/redis_sentinel.c @@ -23,30 +23,12 @@ zend_class_entry *redis_sentinel_ce; extern zend_class_entry *redis_exception_ce; -ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, port) - ZEND_ARG_INFO(0, timeout) - ZEND_ARG_INFO(0, persistent) - ZEND_ARG_INFO(0, retry_interval) - ZEND_ARG_INFO(0, read_timeout) -ZEND_END_ARG_INFO() +#include "redis_sentinel_arginfo.h" -zend_function_entry redis_sentinel_functions[] = { - PHP_ME(RedisSentinel, __construct, arginfo_ctor, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, ckquorum, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, failover, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, flushconfig, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, getMasterAddrByName, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, master, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, masters, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, myid, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, ping, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, reset, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, sentinels, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, slaves, arginfo_value, ZEND_ACC_PUBLIC) - PHP_FE_END -}; +extern const zend_function_entry *redis_sentinel_get_methods(void) +{ + return class_RedisSentinel_methods; +} PHP_METHOD(RedisSentinel, __construct) { @@ -66,23 +48,23 @@ PHP_METHOD(RedisSentinel, __construct) } if (port < 0 || port > UINT16_MAX) { - REDIS_THROW_EXCEPTION("Invalid port", 0); - RETURN_FALSE; + REDIS_VALUE_EXCEPTION("Invalid port"); + RETURN_THROWS(); } if (timeout < 0L || timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid connect timeout", 0); - RETURN_FALSE; + REDIS_VALUE_EXCEPTION("Invalid connect timeout"); + RETURN_THROWS(); } if (read_timeout < 0L || read_timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid read timeout", 0); - RETURN_FALSE; + REDIS_VALUE_EXCEPTION("Invalid read timeout"); + RETURN_THROWS(); } if (retry_interval < 0L || retry_interval > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid retry interval", 0); - RETURN_FALSE; + REDIS_VALUE_EXCEPTION("Invalid retry interval"); + RETURN_THROWS(); } if (zv) { diff --git a/redis_sentinel.h b/redis_sentinel.h index b09ce0c..a24c5c0 100644 --- a/redis_sentinel.h +++ b/redis_sentinel.h @@ -5,17 +5,6 @@ #define PHP_REDIS_SENTINEL_VERSION "0.1" -PHP_METHOD(RedisSentinel, __construct); -PHP_METHOD(RedisSentinel, ckquorum); -PHP_METHOD(RedisSentinel, failover); -PHP_METHOD(RedisSentinel, flushconfig); -PHP_METHOD(RedisSentinel, getMasterAddrByName); -PHP_METHOD(RedisSentinel, master); -PHP_METHOD(RedisSentinel, masters); -PHP_METHOD(RedisSentinel, myid); -PHP_METHOD(RedisSentinel, ping); -PHP_METHOD(RedisSentinel, reset); -PHP_METHOD(RedisSentinel, sentinels); -PHP_METHOD(RedisSentinel, slaves); +extern const zend_function_entry *redis_sentinel_get_methods(void); #endif /* REDIS_SENTINEL_H */ diff --git a/redis_sentinel.stub.php b/redis_sentinel.stub.php new file mode 100644 index 0000000..11309c0 --- /dev/null +++ b/redis_sentinel.stub.php @@ -0,0 +1,28 @@ +