Skip to content

Commit

Permalink
Split initialization steps for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvrtx committed Jan 13, 2025
1 parent 23ca72e commit 2053c1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public static function init() {
include_once __DIR__ . '/compat/multi-currency/class-wc-payments-currency-manager.php';
include_once __DIR__ . '/class-duplicates-detection-service.php';

wcpay_get_container()->get( \WCPay\Internal\LoggerContext::class )->init();
wcpay_get_container()->get( \WCPay\Internal\LoggerContext::class )->init_hooks();

self::$woopay_checkout_service = new Checkout_Service();
self::$woopay_checkout_service->init();
Expand Down
35 changes: 15 additions & 20 deletions src/Internal/LoggerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ class LoggerContext {
private $entry_number = 0;

/**
* Initialises the logger context.
*
* @return void
* LoggerContext constructor.
*/
public function init() {
public function __construct() {
$this->request_id = uniqid();
$this->entry_number = 0;

$this->setup_hooks();
}

/**
* Adds hooks to filter and enhance log entries.
*
* @return void
*/
public function init_hooks() {
if ( $this->hooks_set ) {
return;
}

add_filter( 'woocommerce_format_log_entry', [ $this, 'filter_log_entry' ], 10, 2 );
$this->hooks_set = true;
}
/**
* Sets a context value.
*
Expand Down Expand Up @@ -134,20 +143,6 @@ function ( $line ) use ( $format_string ) {
);
}

/**
* Adds hooks to filter and enhance log entries.
*
* @return void
*/
private function setup_hooks() {
if ( $this->hooks_set ) {
return;
}

add_filter( 'woocommerce_format_log_entry', [ $this, 'filter_log_entry' ], 10, 2 );
$this->hooks_set = true;
}

/**
* Initialises the context.
*
Expand Down

0 comments on commit 2053c1b

Please sign in to comment.