Skip to content

Commit 6a2cafd

Browse files
authored
Support object style callback parameters (#3888)
* Support object style callback parameters * Optimize code * fix tests * Optimize code [2] * Remove duplicate codes * fix typo * fix tests * Add StatusInfo, Refactor * Compatibility with PHP8
1 parent 19bf1bf commit 6a2cafd

21 files changed

+769
-123
lines changed

ext-src/php_swoole.h

+17-12
Original file line numberDiff line numberDiff line change
@@ -589,35 +589,40 @@ static sw_inline void add_assoc_ulong_safe(zval *arg, const char *key, zend_ulon
589589

590590
/* PHP 7 class declaration macros */
591591

592-
#define SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_ce) do { \
592+
#define SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_ce) do { \
593593
zend_class_entry _##module##_ce = {}; \
594-
INIT_CLASS_ENTRY(_##module##_ce, namespaceName, methods); \
594+
INIT_CLASS_ENTRY(_##module##_ce, namespace_name, methods); \
595595
module##_ce = zend_register_internal_class_ex(&_##module##_ce, parent_ce); \
596-
SW_CLASS_ALIAS(snake_name, module); \
597-
SW_CLASS_ALIAS_SHORT_NAME(shortName, module); \
596+
if (snake_name) SW_CLASS_ALIAS(snake_name, module); \
597+
if (short_name) SW_CLASS_ALIAS_SHORT_NAME(short_name, module); \
598598
} while (0)
599599

600-
#define SW_INIT_CLASS_ENTRY(module, namespaceName, snake_name, shortName, methods) \
601-
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, NULL); \
600+
#define SW_INIT_CLASS_ENTRY(module, namespace_name, snake_name, short_name, methods) \
601+
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, NULL); \
602602
memcpy(&module##_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers))
603603

604-
#define SW_INIT_CLASS_ENTRY_EX(module, namespaceName, snake_name, shortName, methods, parent_module) \
605-
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_module##_ce); \
604+
#define SW_INIT_CLASS_ENTRY_EX(module, namespace_name, snake_name, short_name, methods, parent_module) \
605+
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_module##_ce); \
606606
memcpy(&module##_handlers, &parent_module##_handlers, sizeof(zend_object_handlers))
607607

608-
#define SW_INIT_CLASS_ENTRY_EX2(module, namespaceName, snake_name, shortName, methods, parent_module_ce, parent_module_handlers) \
609-
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_module_ce); \
608+
#define SW_INIT_CLASS_ENTRY_EX2(module, namespace_name, snake_name, short_name, methods, parent_module_ce, parent_module_handlers) \
609+
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_module_ce); \
610610
memcpy(&module##_handlers, parent_module_handlers, sizeof(zend_object_handlers))
611611

612+
// Data Object: no methods, no parent
613+
#define SW_INIT_CLASS_ENTRY_DATA_OBJECT(module, namespace_name) \
614+
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, NULL, NULL, NULL, NULL); \
615+
memcpy(&module##_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers))
616+
612617
#define SW_CLASS_ALIAS(name, module) do { \
613618
if (name) { \
614619
sw_zend_register_class_alias(ZEND_STRL(name), module##_ce); \
615620
} \
616621
} while (0)
617622

618-
#define SW_CLASS_ALIAS_SHORT_NAME(shortName, module) do { \
623+
#define SW_CLASS_ALIAS_SHORT_NAME(short_name, module) do { \
619624
if (SWOOLE_G(use_shortname)) { \
620-
SW_CLASS_ALIAS(shortName, module); \
625+
SW_CLASS_ALIAS(short_name, module); \
621626
} \
622627
} while (0)
623628

ext-src/php_swoole_library.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Generated by build-library.php, Please DO NOT modify!
33
*/
44

5-
/* $Id: 138bd3ee518144ea6dccceb624d540627537a972 */
5+
/* $Id: d8341036d6d7e97eb77dd2adf823fbb9bbd52e8c */
66

77
static const char* swoole_library_source_constants =
88
"\n"
@@ -6685,6 +6685,8 @@ static const char* swoole_library_source_core_server_helper =
66856685
" 'enable_delay_receive' => true,\n"
66866686
" 'enable_reuse_port' => true,\n"
66876687
" 'task_use_object' => true,\n"
6688+
" 'task_object' => true,\n"
6689+
" 'event_object' => true,\n"
66886690
" 'task_enable_coroutine' => true,\n"
66896691
" 'task_worker_num' => true,\n"
66906692
" 'task_ipc_mode' => true,\n"
@@ -6983,7 +6985,7 @@ static const char* swoole_library_source_functions =
69836985
"declare(strict_types=1);\n"
69846986
"\n"
69856987
"if (PHP_VERSION_ID < 70200) {\n"
6986-
" throw new RuntimeException(\"require PHP version 7.2 or later\");\n"
6988+
" throw new RuntimeException('require PHP version 7.2 or later');\n"
69876989
"}\n"
69886990
"\n"
69896991
"if (SWOOLE_USE_SHORTNAME) {\n"

ext-src/swoole_event.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static PHP_FUNCTION(swoole_event_rshutdown) {
730730
if (!sw_reactor()) {
731731
return;
732732
}
733-
php_swoole_fatal_error(E_DEPRECATED, "Do Event::wait() in shutdown function is deprecated");
733+
php_swoole_fatal_error(E_DEPRECATED, "Event::wait() in shutdown function is deprecated");
734734
php_swoole_event_wait();
735735
}
736736
zend_end_try();

0 commit comments

Comments
 (0)