Skip to content

Commit

Permalink
Add method_intercept_init function to Ray AOP extension
Browse files Browse the repository at this point in the history
A new function, method_intercept_init, has been added to the Ray AOP PHP extension. This function is designed to reset the intercept hash table, ensuring it starts empty. This change should help improve the handling of method interception by allowing a more controlled initialization of the intercept hash table.
  • Loading branch information
koriym committed Jul 11, 2024
1 parent 98d3b5e commit 761d789
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions php_rayaop.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PHP_RINIT_FUNCTION(rayaop); /* Request initialization function */
PHP_RSHUTDOWN_FUNCTION(rayaop); /* Request shutdown function */
PHP_MINFO_FUNCTION(rayaop); /* Module information function */
PHP_FUNCTION(method_intercept); /* Method intercept function */
PHP_FUNCTION(method_intercept_init); /* Add this line for the new function */

/* Utility function declarations */
void php_rayaop_handle_error(const char *message); /* Error handling function */
Expand Down
23 changes: 23 additions & 0 deletions rayaop.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_method_intercept, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, interceptor, Ray\\Aop\\MethodInterceptorInterface, 0) /* Argument information for intercept handler */
ZEND_END_ARG_INFO()

/* Argument information for method_intercept_init function */
ZEND_BEGIN_ARG_INFO(arginfo_method_intercept_init, 0)
ZEND_END_ARG_INFO()

/* {{{ proto void php_rayaop_handle_error(const char *message)
Error handling function
Expand Down Expand Up @@ -306,6 +310,24 @@ RETURN_FALSE; /* Return false and end */
}
/* }}} */

/* {{{ proto void method_intercept_init()
Function to reset intercept table
This function clears the intercept hash table, ensuring it starts empty.
*/
PHP_FUNCTION(method_intercept_init) {
PHP_RAYAOP_DEBUG_PRINT("method_intercept_init called"); /* Output debug information */
if (RAYAOP_G(intercept_ht)) {
zend_hash_clean(RAYAOP_G(intercept_ht)); /* Clear hash table */
} else {
ALLOC_HASHTABLE(RAYAOP_G(intercept_ht)); /* Allocate memory for hash table if not already allocated */
zend_hash_init(RAYAOP_G(intercept_ht), 8, NULL, php_rayaop_free_intercept_info, 0); /* Initialize hash table */
}
RETURN_TRUE; /* Return true to indicate success */
}
/* }}} */

/* Interface definition */
zend_class_entry *ray_aop_method_interceptor_interface_ce;

Expand Down Expand Up @@ -456,6 +478,7 @@ static void php_rayaop_dump_intercept_info(void)
/* Definition of functions provided by the extension */
static const zend_function_entry rayaop_functions[] = {
PHP_FE(method_intercept, arginfo_method_intercept) /* Register method_intercept function */
PHP_FE(method_intercept_init, arginfo_method_intercept_init) /* Register method_intercept_init function */
PHP_FE_END /* End of function entries */
};

Expand Down

0 comments on commit 761d789

Please sign in to comment.