Skip to content

Commit 3c60f0e

Browse files
committed
Added arg info
1 parent 6513d52 commit 3c60f0e

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

hashids.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,29 @@ hashids_t *hashids_entry;
3232

3333
ZEND_DECLARE_MODULE_GLOBALS(hashids)
3434

35-
ZEND_BEGIN_ARG_INFO_EX(arginfo__construct, 0, 0, 3)
35+
ZEND_BEGIN_ARG_INFO(arginfo_hashids_construct, 0)
3636
ZEND_ARG_INFO(0, salt)
3737
ZEND_ARG_INFO(0, min_hash_length)
3838
ZEND_ARG_INFO(0, alphabet)
3939
ZEND_END_ARG_INFO()
4040

41+
ZEND_BEGIN_ARG_INFO(arginfo_hashids_encode, 0)
42+
ZEND_ARG_VARIADIC_INFO(0, argc)
43+
ZEND_END_ARG_INFO()
44+
45+
ZEND_BEGIN_ARG_INFO(arginfo_hashids_decode, 0)
46+
ZEND_ARG_INFO(0, hash)
47+
ZEND_END_ARG_INFO()
48+
49+
ZEND_BEGIN_ARG_INFO(arginfo_hashids_encode_hex, 0)
50+
ZEND_ARG_INFO(0, hex_str)
51+
ZEND_END_ARG_INFO()
52+
53+
ZEND_BEGIN_ARG_INFO(arginfo_hashids_decode_hex, 0)
54+
ZEND_ARG_INFO(0, hash)
55+
ZEND_END_ARG_INFO()
56+
57+
4158
PHP_INI_BEGIN()
4259
STD_PHP_INI_ENTRY("hashids.salt", HASHIDS_DEFAULT_SALT, PHP_INI_ALL, OnUpdateString, salt, zend_hashids_globals, hashids_globals)
4360
STD_PHP_INI_ENTRY("hashids.min_hash_length", "0", PHP_INI_ALL, OnUpdateLong, min_hash_length, zend_hashids_globals, hashids_globals)
@@ -259,7 +276,7 @@ PHP_METHOD(hashids, encode) {
259276

260277
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL(args[0]), i, value) {
261278
numbers[i] = Z_LVAL_P(value);
262-
}ZEND_HASH_FOREACH_END();
279+
} ZEND_HASH_FOREACH_END();
263280
} else {
264281
//get all the variables
265282
for (i = 0; i < argc; i++) {
@@ -331,11 +348,11 @@ PHP_METHOD(hashids, decodeHex) {
331348
}
332349

333350
static const zend_function_entry hashids_methods[] = {
334-
PHP_ME(hashids, __construct, arginfo__construct, ZEND_ACC_CTOR | ZEND_ACC_PUBLIC)
335-
PHP_ME(hashids, encode, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
336-
PHP_ME(hashids, decode, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
337-
PHP_ME(hashids, encodeHex, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
338-
PHP_ME(hashids, decodeHex, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
351+
PHP_ME(hashids, __construct, arginfo_hashids_construct, ZEND_ACC_CTOR | ZEND_ACC_PUBLIC)
352+
PHP_ME(hashids, encode, arginfo_hashids_encode, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
353+
PHP_ME(hashids, decode, arginfo_hashids_decode, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
354+
PHP_ME(hashids, encodeHex, arginfo_hashids_encode_hex, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
355+
PHP_ME(hashids, decodeHex, arginfo_hashids_decode_hex, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
339356
PHP_FE_END
340357
};
341358

tests/006.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Check for hashids encode array arguments
3+
--SKIPIF--
4+
<?php if (!extension_loaded("hashids")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
$hashids = new Hashids();
9+
10+
$hash = $hashids->encode([1, 2, 3, 4, 5]); // ADf9h9i0sQ
11+
$numbers = $hashids->decode($hash); // [1, 2, 3, 4, 5]
12+
13+
echo $hash . "\n";
14+
print_r($numbers);
15+
?>
16+
--EXPECT--
17+
ADf9h9i0sQ
18+
Array
19+
(
20+
[0] => 1
21+
[1] => 2
22+
[2] => 3
23+
[3] => 4
24+
[4] => 5
25+
)

0 commit comments

Comments
 (0)