@@ -269,30 +269,38 @@ NR_PHP_WRAPPER_END
269
269
/*
270
270
* CakePHP 4.0+
271
271
*
272
- * If the action or controller is not found during the dispatch process, the
273
- * appropriate Exception will be created and thrown. We wrap the CakeException
274
- * constructor instead of the Exception handler, since CakePHP allows for the
275
- * handler to be completely replaced.
276
- *
277
- * txn naming scheme:
278
- * In this case, `nr_txn_set_path` is called before `NR_PHP_WRAPPER_CALL` with
279
- * `NR_NOT_OK_TO_OVERWRITE` and as this corresponds to calling the wrapped
280
- * function in func_begin it needs to be explicitly set as a before_callback to
281
- * ensure OAPI compatibility. This entails that the first wrapped call gets to
282
- * name the txn.
272
+ * Report errors and exceptions caught by CakePHP's error handler.
283
273
*/
284
- NR_PHP_WRAPPER (nr_cakephp_problem_4 ) {
285
- const char * name = "Exception" ;
274
+ NR_PHP_WRAPPER (nr_cakephp_error_handler_wrapper ) {
275
+ zval * exception = NULL ;
276
+ char * request_uri
277
+ = nr_strdup (nr_php_get_server_global ("REQUEST_URI" TSRMLS_CC ));
286
278
287
- (void )wraprec ;
288
279
NR_UNUSED_SPECIALFN ;
280
+ (void )wraprec ;
289
281
290
282
NR_PHP_WRAPPER_REQUIRE_FRAMEWORK (NR_FW_CAKEPHP );
291
283
292
- nr_txn_set_path ("CakePHP" , NRPRG (txn ), name , NR_PATH_TYPE_ACTION ,
284
+ exception = nr_php_arg_get (1 , NR_EXECUTE_ORIG_ARGS TSRMLS_CC );
285
+ if (!nr_php_is_zval_valid_object (exception )) {
286
+ nrl_verbosedebug (NRL_FRAMEWORK , "%s: exception is NULL or not an object" ,
287
+ __func__ );
288
+ goto end ;
289
+ }
290
+
291
+ if (NR_SUCCESS
292
+ != nr_php_error_record_exception (
293
+ NRPRG (txn ), exception , nr_php_error_get_priority (E_ERROR ), true,
294
+ "Uncaught exception " , & NRPRG (exception_filters ) TSRMLS_CC )) {
295
+ nrl_verbosedebug (NRL_FRAMEWORK , "%s: unable to record exception" , __func__ );
296
+ }
297
+
298
+ nr_txn_set_path ("CakePHP" , NRPRG (txn ), request_uri , NR_PATH_TYPE_ACTION ,
293
299
NR_NOT_OK_TO_OVERWRITE );
294
300
295
- NR_PHP_WRAPPER_CALL ;
301
+ end :
302
+ nr_php_arg_release (& exception );
303
+ nr_free (request_uri );
296
304
}
297
305
NR_PHP_WRAPPER_END
298
306
@@ -313,16 +321,10 @@ void nr_cakephp_enable(TSRMLS_D) {
313
321
nr_php_wrap_user_function (
314
322
NR_PSTR ("Cake\\Controller\\Controller::invokeAction" ),
315
323
nr_cakephp_name_the_wt_4 TSRMLS_CC );
324
+ nr_php_wrap_user_function (
325
+ NR_PSTR (
326
+ "Cake\\Error\\Middleware\\ErrorHandlerMiddleware::handleException" ),
327
+ nr_cakephp_error_handler_wrapper TSRMLS_CC );
316
328
nr_txn_suggest_package_supportability_metric (NRPRG (txn ), PHP_PACKAGE_NAME ,
317
329
PHP_PACKAGE_VERSION_UNKNOWN );
318
- #if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
319
- && !defined OVERWRITE_ZEND_EXECUTE_DATA
320
- nr_php_wrap_user_function_before_after_clean (
321
- NR_PSTR ("Cake\\Core\\Exception\\CakeException::__construct" ),
322
- nr_cakephp_problem_4 , NULL , NULL );
323
- #else
324
- nr_php_wrap_user_function (
325
- NR_PSTR ("Cake\\Core\\Exception\\CakeException::__construct" ),
326
- nr_cakephp_problem_4 TSRMLS_CC );
327
- #endif
328
330
}
0 commit comments