Commit 29c1e093 authored by Michael Iseard's avatar Michael Iseard
Browse files

Use LoggerService factory method

parent 5c81d6de
......@@ -70,7 +70,7 @@ class Admin {
add_action( 'kudos_transactions_update',
function ( $column, $value ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$logger->debug( 'kudos_transactions_update', [ $column, $value ] );
},
10,
......@@ -78,7 +78,7 @@ class Admin {
add_action( 'kudos_donors_add',
function ( $column, $value ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$logger->debug( 'kudos_donors_add', [ $column, $value ] );
},
10,
......@@ -500,7 +500,7 @@ class Admin {
// Check if action is a kudos action then log if true
if(substr($action, 0, 6) === "kudos_" ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$logger->warning( 'Nonce verification failed', [ 'nonce' => $nonce, 'action' => $action ] );
}
......
......@@ -100,7 +100,7 @@ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $default_tab;
return;
}
$kudos_logger = new LoggerService();
$kudos_logger = LoggerService::factory();
$logArray = $kudos_logger->get_as_array();
?>
......
......@@ -68,7 +68,7 @@ abstract class AbstractEntity implements EntityInterface {
throw new EntityException( 'Property does not exist!', 0, $property, static::class );
}
} catch ( EntityException $e ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$logger->warning( 'Error setting property.', [ "message" => $e->getMessage() ] );
}
......@@ -102,7 +102,7 @@ abstract class AbstractEntity implements EntityInterface {
*/
public function create_secret( $timeout = '+10 minutes' ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$table = static::get_table_name( false );
try {
......
......@@ -69,7 +69,7 @@ class Front {
*/
public static function process_transaction( string $order_id ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
$logger->debug( 'Processing transaction', [ $order_id ] );
// Bail if no order ID
......
......@@ -2,7 +2,6 @@
namespace Kudos\Front;
use Kudos\Service\LoggerService;
use Kudos\Service\TwigService;
class KudosButton {
......@@ -23,10 +22,6 @@ class KudosButton {
* @var string
*/
private $id;
/**
* @var LoggerService
*/
private $logger;
/**
* @var string
*/
......@@ -58,7 +53,6 @@ class KudosButton {
public function __construct( array $atts ) {
$this->twig = TwigService::factory();
$this->logger = new LoggerService();
$this->title = $atts['modal_title'];
$this->text = $atts['welcome_text'];
$this->label = $atts['button_label'];
......
......@@ -4,15 +4,10 @@ namespace Kudos\Front;
use Kudos\Helpers\Settings;
use Kudos\Helpers\Utils;
use Kudos\Service\LoggerService;
use Kudos\Service\TwigService;
class KudosModal {
/**
* @var LoggerService
*/
private $logger;
/**
* @var TwigService
*/
......@@ -25,7 +20,6 @@ class KudosModal {
*/
public function __construct() {
$this->logger = new LoggerService();
$this->twig = TwigService::factory();
}
......
......@@ -16,7 +16,7 @@ abstract class AbstractService {
*/
public function __construct() {
$this->logger = new LoggerService();
$this->logger = LoggerService::factory();
}
......
......@@ -32,9 +32,9 @@ class ActivatorService {
*/
public static function activate( $old_version = null ) {
$logger = new LoggerService();
$logger = LoggerService::factory();
LoggerService::init();
$logger::init();
TwigService::initCache();
self::create_donors_table();
self::create_transactions_table();
......
......@@ -26,8 +26,9 @@ class DeactivatorService {
* @since 1.0.0
*/
public static function deactivate() {
$logger = new LoggerService();
$logger->info( 'Kudos Donations plugin deactivated' );
LoggerService::factory()->info( 'Kudos Donations plugin deactivated' );
}
}
......@@ -39,11 +39,7 @@ class LoggerService extends Monolog {
*/
public static function init() {
$logger = new LoggerService();
if ( wp_mkdir_p( self::LOG_DIR ) ) {
$logger->info( 'Log directory created successfully' );
return;
}
......@@ -51,6 +47,26 @@ class LoggerService extends Monolog {
}
/**
* The class factory. In most cases this
* should be used instead of instantiating the object
* directly.
*
* @return static
* @since 2.0.0
*/
public static function factory() {
static $instance = false;
if ( ! $instance ) {
$instance = new static;
}
return $instance;
}
/**
* Clears the log file
*
......
......@@ -121,7 +121,7 @@ class TwigService extends AbstractService {
*/
public static function initCache() {
$logger = new LoggerService();
$logger = LoggerService::factory();
if ( wp_mkdir_p( self::CACHE_DIR ) ) {
$logger->info( 'Twig cache directory created successfully' );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment