Skip to content

Commit 5b7029c

Browse files
committed
Add support for namespaces and alternative name for Tarantool class
Namespaces: * Tarantool -> Tarantool\Connection * TarantoolException -> Tarantool\Exception * TarantoolIOException -> Tarantool\Exception\IOException * TarantoolParsingException -> Tarantool\Exception\ParsingException * TarantoolClientError -> Tarantool\Exception\ClientError * Tarantool -> Tarantool16 * Tarantool\Connection -> Tarantool\Connection16
1 parent 31cf8a8 commit 5b7029c

7 files changed

+59
-19
lines changed

src/php_tarantool.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ PHP_METHOD(Tarantool, flush_schema);
7979

8080
ZEND_BEGIN_MODULE_GLOBALS(tarantool)
8181
zend_bool persistent;
82+
zend_bool use_namespace;
83+
zend_bool connection_alias;
8284
long sync_counter;
8385
long retry_count;
8486
double retry_sleep;
@@ -115,6 +117,11 @@ typedef struct tarantool_object {
115117
typedef struct tarantool_connection tarantool_connection;
116118

117119
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_ce(void);
120+
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_exception(void);
121+
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_ioexception(void);
122+
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_clienterror(void);
123+
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_parsingexception(void);
124+
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_exception_base(int root TSRMLS_DC);
118125

119126
#ifdef ZTS
120127
# define TARANTOOL_G(v) TSRMG(tarantool_globals_id, zend_tarantool_globals *, v)

src/tarantool.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <limits.h>
44

55
#include "php_tarantool.h"
6+
#include "tarantool_internal.h"
67

78
#include "tarantool_tp.h"
89
#include "tarantool_proto.h"
@@ -98,9 +99,15 @@ zend_module_entry tarantool_module_entry = {
9899
};
99100

100101
PHP_INI_BEGIN()
101-
STD_PHP_INI_ENTRY("tarantool.persistent", "0", PHP_INI_ALL,
102-
OnUpdateBool, persistent, zend_tarantool_globals,
103-
tarantool_globals)
102+
STD_PHP_INI_BOOLEAN("tarantool.persistent", "0", PHP_INI_ALL,
103+
OnUpdateBool, persistent, zend_tarantool_globals,
104+
tarantool_globals)
105+
STD_PHP_INI_BOOLEAN("tarantool.use_namespace", "0", PHP_INI_SYSTEM,
106+
OnUpdateBool, use_namespace,
107+
zend_tarantool_globals, tarantool_globals)
108+
STD_PHP_INI_BOOLEAN("tarantool.connection_alias", "0", PHP_INI_SYSTEM,
109+
OnUpdateBool, connection_alias,
110+
zend_tarantool_globals, tarantool_globals)
104111
STD_PHP_INI_ENTRY("tarantool.timeout", "10.0", PHP_INI_ALL,
105112
OnUpdateReal, timeout, zend_tarantool_globals,
106113
tarantool_globals)
@@ -938,7 +945,7 @@ static void php_tarantool_init_globals(zend_tarantool_globals *tarantool_globals
938945
tarantool_globals->sync_counter = 0;
939946
tarantool_globals->retry_count = 1;
940947
tarantool_globals->retry_sleep = 0.1;
941-
tarantool_globals->timeout = 10.0;
948+
tarantool_globals->timeout = 1.0;
942949
tarantool_globals->request_timeout = 10.0;
943950
}
944951

@@ -982,7 +989,15 @@ PHP_MINIT_FUNCTION(tarantool) {
982989
zend_class_entry tarantool_class;
983990

984991
/* Initialize class entry */
985-
INIT_CLASS_ENTRY(tarantool_class, "Tarantool", Tarantool_methods);
992+
if (TARANTOOL_G(connection_alias)) {
993+
TNT_INIT_CLASS_ENTRY(tarantool_class, "Tarantool16",
994+
"Tarantool\\Connection16",
995+
Tarantool_methods);
996+
} else {
997+
TNT_INIT_CLASS_ENTRY(tarantool_class, "Tarantool",
998+
"Tarantool\\Connection",
999+
Tarantool_methods);
1000+
}
9861001
tarantool_class.create_object = tarantool_create;
9871002
Tarantool_ptr = zend_register_internal_class(&tarantool_class);
9881003
/* Initialize object handlers */

src/tarantool_exception.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "php_tarantool.h"
22

3+
#include "tarantool_internal.h"
4+
5+
#include "tarantool_exception.h"
6+
37
zend_class_entry *TarantoolException_ptr;
48
zend_class_entry *TarantoolIOException_ptr;
59
zend_class_entry *TarantoolClientError_ptr;
@@ -112,22 +116,28 @@ ZEND_MINIT_FUNCTION(tarantool_exception) {
112116
zend_class_entry tarantool_client_er_class;
113117
zend_class_entry tarantool_parsing_xc_class;
114118

115-
INIT_CLASS_ENTRY(tarantool_xc_class, "TarantoolException", NULL);
119+
TNT_INIT_CLASS_ENTRY(tarantool_xc_class, "TarantoolException",
120+
"Tarantool\\Exception", NULL);
116121
TarantoolException_ptr = zend_register_internal_class_ex(
117122
&tarantool_xc_class,
118123
php_tarantool_get_exception_base(0)
119124
);
120-
INIT_CLASS_ENTRY(tarantool_io_xc_class, "TarantoolIOException", NULL);
125+
TNT_INIT_CLASS_ENTRY(tarantool_io_xc_class, "TarantoolIOException",
126+
"Tarantool\\Exception\\IOException", NULL);
121127
TarantoolIOException_ptr = zend_register_internal_class_ex(
122128
&tarantool_io_xc_class,
123129
TarantoolException_ptr
124130
);
125-
INIT_CLASS_ENTRY(tarantool_client_er_class, "TarantoolClientError", NULL);
131+
TNT_INIT_CLASS_ENTRY(tarantool_client_er_class, "TarantoolClientError",
132+
"Tarantool\\Exception\\ClientError", NULL);
126133
TarantoolClientError_ptr = zend_register_internal_class_ex(
127134
&tarantool_client_er_class,
128135
TarantoolException_ptr
129136
);
130-
INIT_CLASS_ENTRY(tarantool_parsing_xc_class, "TarantoolParsingException", NULL);
137+
TNT_INIT_CLASS_ENTRY(tarantool_parsing_xc_class,
138+
"TarantoolParsingException",
139+
"Tarantool\\Exception\\ParsingException",
140+
NULL);
131141
TarantoolParsingException_ptr = zend_register_internal_class_ex(
132142
&tarantool_parsing_xc_class,
133143
TarantoolException_ptr

src/tarantool_exception.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ extern zend_class_entry *TarantoolIOException_ptr;
66
extern zend_class_entry *TarantoolClientError_ptr;
77
extern zend_class_entry *TarantoolParsingException_ptr;
88

9-
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_exception(void);
10-
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_ioexception(void);
11-
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_clienterror(void);
12-
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_parsingexception(void);
13-
PHP_TARANTOOL_API zend_class_entry *php_tarantool_get_exception_base(int root TSRMLS_DC);
14-
159
zend_object *tarantool_throw_exception(const char *fmt, ...);
1610
zend_object *tarantool_throw_ioexception(const char *fmt, ...);
1711
zend_object *tarantool_throw_clienterror(uint32_t code, const char *err,

src/tarantool_internal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef PHP_TNT_INTERNAL_H
2+
#define PHP_TNT_INTERNAL_H
3+
4+
#define TNT_INIT_CLASS_ENTRY(ce, name, name_ns, methods) \
5+
if (TARANTOOL_G(use_namespace)) { \
6+
printf("%s", name_ns); \
7+
INIT_CLASS_ENTRY(ce, name_ns, methods); \
8+
} else { \
9+
printf("%s", name); \
10+
INIT_CLASS_ENTRY(ce, name, methods); \
11+
}
12+
13+
#endif /* PHP_TNT_INTERNAL_H */

src/tarantool_network.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int tntll_stream_open(const char *host, int port, zend_string *pid,
7373
if (pid) options |= STREAM_OPEN_PERSISTENT;
7474
flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
7575
double_to_tv(TARANTOOL_G(timeout), &tv);
76+
// printf("'tm - %lu, %lu' ", tv.tv_sec, tv.tv_usec);
7677

7778
const char *pid_str = pid == NULL ? NULL : pid->val;
7879
stream = php_stream_xport_create(addr, addr_len, options, flags,
@@ -88,6 +89,8 @@ int tntll_stream_open(const char *host, int port, zend_string *pid,
8889

8990
/* Set READ_TIMEOUT */
9091
double_to_tv(TARANTOOL_G(request_timeout), &tv);
92+
// printf("'rtv - %lu, %lu' ", tv.tv_sec, tv.tv_usec);
93+
9194
if (tv.tv_sec != 0 || tv.tv_usec != 0) {
9295
php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT,
9396
0, &tv);

src/tarantool_schema.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ schema_add_space(
368368
goto error;
369369
break;
370370
default:
371-
/* unreacheable */
372-
assert(false);
371+
break;
373372
}
374373
}
375374
space_string->index_hash = mh_schema_index_new();
@@ -487,8 +486,7 @@ static inline int schema_add_index(
487486
goto error;
488487
break;
489488
default:
490-
/* unreacheable */
491-
assert(false);
489+
break;
492490
}
493491
}
494492
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);

0 commit comments

Comments
 (0)