Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Kudos-Donations
Commits
29c1e093
Commit
29c1e093
authored
Oct 27, 2020
by
Michael Iseard
Browse files
Use LoggerService factory method
parent
5c81d6de
Changes
11
Hide whitespace changes
Inline
Side-by-side
app/Admin/Admin.php
View file @
29c1e093
...
@@ -70,7 +70,7 @@ class Admin {
...
@@ -70,7 +70,7 @@ class Admin {
add_action
(
'kudos_transactions_update'
,
add_action
(
'kudos_transactions_update'
,
function
(
$column
,
$value
)
{
function
(
$column
,
$value
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$logger
->
debug
(
'kudos_transactions_update'
,
[
$column
,
$value
]
);
$logger
->
debug
(
'kudos_transactions_update'
,
[
$column
,
$value
]
);
},
},
10
,
10
,
...
@@ -78,7 +78,7 @@ class Admin {
...
@@ -78,7 +78,7 @@ class Admin {
add_action
(
'kudos_donors_add'
,
add_action
(
'kudos_donors_add'
,
function
(
$column
,
$value
)
{
function
(
$column
,
$value
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$logger
->
debug
(
'kudos_donors_add'
,
[
$column
,
$value
]
);
$logger
->
debug
(
'kudos_donors_add'
,
[
$column
,
$value
]
);
},
},
10
,
10
,
...
@@ -500,7 +500,7 @@ class Admin {
...
@@ -500,7 +500,7 @@ class Admin {
// Check if action is a kudos action then log if true
// Check if action is a kudos action then log if true
if
(
substr
(
$action
,
0
,
6
)
===
"kudos_"
)
{
if
(
substr
(
$action
,
0
,
6
)
===
"kudos_"
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$logger
->
warning
(
'Nonce verification failed'
,
[
'nonce'
=>
$nonce
,
'action'
=>
$action
]
);
$logger
->
warning
(
'Nonce verification failed'
,
[
'nonce'
=>
$nonce
,
'action'
=>
$action
]
);
}
}
...
...
app/Admin/partials/kudos-admin-debug.php
View file @
29c1e093
...
@@ -100,7 +100,7 @@ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $default_tab;
...
@@ -100,7 +100,7 @@ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $default_tab;
return
;
return
;
}
}
$kudos_logger
=
new
LoggerService
();
$kudos_logger
=
LoggerService
::
factory
();
$logArray
=
$kudos_logger
->
get_as_array
();
$logArray
=
$kudos_logger
->
get_as_array
();
?>
?>
...
...
app/Entity/AbstractEntity.php
View file @
29c1e093
...
@@ -68,7 +68,7 @@ abstract class AbstractEntity implements EntityInterface {
...
@@ -68,7 +68,7 @@ abstract class AbstractEntity implements EntityInterface {
throw
new
EntityException
(
'Property does not exist!'
,
0
,
$property
,
static
::
class
);
throw
new
EntityException
(
'Property does not exist!'
,
0
,
$property
,
static
::
class
);
}
}
}
catch
(
EntityException
$e
)
{
}
catch
(
EntityException
$e
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$logger
->
warning
(
'Error setting property.'
,
[
"message"
=>
$e
->
getMessage
()
]
);
$logger
->
warning
(
'Error setting property.'
,
[
"message"
=>
$e
->
getMessage
()
]
);
}
}
...
@@ -102,7 +102,7 @@ abstract class AbstractEntity implements EntityInterface {
...
@@ -102,7 +102,7 @@ abstract class AbstractEntity implements EntityInterface {
*/
*/
public
function
create_secret
(
$timeout
=
'+10 minutes'
)
{
public
function
create_secret
(
$timeout
=
'+10 minutes'
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$table
=
static
::
get_table_name
(
false
);
$table
=
static
::
get_table_name
(
false
);
try
{
try
{
...
...
app/Front/Front.php
View file @
29c1e093
...
@@ -69,7 +69,7 @@ class Front {
...
@@ -69,7 +69,7 @@ class Front {
*/
*/
public
static
function
process_transaction
(
string
$order_id
)
{
public
static
function
process_transaction
(
string
$order_id
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
$logger
->
debug
(
'Processing transaction'
,
[
$order_id
]
);
$logger
->
debug
(
'Processing transaction'
,
[
$order_id
]
);
// Bail if no order ID
// Bail if no order ID
...
...
app/Front/KudosButton.php
View file @
29c1e093
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
namespace
Kudos\Front
;
namespace
Kudos\Front
;
use
Kudos\Service\LoggerService
;
use
Kudos\Service\TwigService
;
use
Kudos\Service\TwigService
;
class
KudosButton
{
class
KudosButton
{
...
@@ -23,10 +22,6 @@ class KudosButton {
...
@@ -23,10 +22,6 @@ class KudosButton {
* @var string
* @var string
*/
*/
private
$id
;
private
$id
;
/**
* @var LoggerService
*/
private
$logger
;
/**
/**
* @var string
* @var string
*/
*/
...
@@ -58,7 +53,6 @@ class KudosButton {
...
@@ -58,7 +53,6 @@ class KudosButton {
public
function
__construct
(
array
$atts
)
{
public
function
__construct
(
array
$atts
)
{
$this
->
twig
=
TwigService
::
factory
();
$this
->
twig
=
TwigService
::
factory
();
$this
->
logger
=
new
LoggerService
();
$this
->
title
=
$atts
[
'modal_title'
];
$this
->
title
=
$atts
[
'modal_title'
];
$this
->
text
=
$atts
[
'welcome_text'
];
$this
->
text
=
$atts
[
'welcome_text'
];
$this
->
label
=
$atts
[
'button_label'
];
$this
->
label
=
$atts
[
'button_label'
];
...
...
app/Front/KudosModal.php
View file @
29c1e093
...
@@ -4,15 +4,10 @@ namespace Kudos\Front;
...
@@ -4,15 +4,10 @@ namespace Kudos\Front;
use
Kudos\Helpers\Settings
;
use
Kudos\Helpers\Settings
;
use
Kudos\Helpers\Utils
;
use
Kudos\Helpers\Utils
;
use
Kudos\Service\LoggerService
;
use
Kudos\Service\TwigService
;
use
Kudos\Service\TwigService
;
class
KudosModal
{
class
KudosModal
{
/**
* @var LoggerService
*/
private
$logger
;
/**
/**
* @var TwigService
* @var TwigService
*/
*/
...
@@ -25,7 +20,6 @@ class KudosModal {
...
@@ -25,7 +20,6 @@ class KudosModal {
*/
*/
public
function
__construct
()
{
public
function
__construct
()
{
$this
->
logger
=
new
LoggerService
();
$this
->
twig
=
TwigService
::
factory
();
$this
->
twig
=
TwigService
::
factory
();
}
}
...
...
app/Service/AbstractService.php
View file @
29c1e093
...
@@ -16,7 +16,7 @@ abstract class AbstractService {
...
@@ -16,7 +16,7 @@ abstract class AbstractService {
*/
*/
public
function
__construct
()
{
public
function
__construct
()
{
$this
->
logger
=
new
LoggerService
();
$this
->
logger
=
LoggerService
::
factory
();
}
}
...
...
app/Service/ActivatorService.php
View file @
29c1e093
...
@@ -32,9 +32,9 @@ class ActivatorService {
...
@@ -32,9 +32,9 @@ class ActivatorService {
*/
*/
public
static
function
activate
(
$old_version
=
null
)
{
public
static
function
activate
(
$old_version
=
null
)
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
L
ogger
Service
::
init
();
$l
ogger
::
init
();
TwigService
::
initCache
();
TwigService
::
initCache
();
self
::
create_donors_table
();
self
::
create_donors_table
();
self
::
create_transactions_table
();
self
::
create_transactions_table
();
...
...
app/Service/DeactivatorService.php
View file @
29c1e093
...
@@ -26,8 +26,9 @@ class DeactivatorService {
...
@@ -26,8 +26,9 @@ class DeactivatorService {
* @since 1.0.0
* @since 1.0.0
*/
*/
public
static
function
deactivate
()
{
public
static
function
deactivate
()
{
$logger
=
new
LoggerService
();
$logger
->
info
(
'Kudos Donations plugin deactivated'
);
LoggerService
::
factory
()
->
info
(
'Kudos Donations plugin deactivated'
);
}
}
}
}
app/Service/LoggerService.php
View file @
29c1e093
...
@@ -39,11 +39,7 @@ class LoggerService extends Monolog {
...
@@ -39,11 +39,7 @@ class LoggerService extends Monolog {
*/
*/
public
static
function
init
()
{
public
static
function
init
()
{
$logger
=
new
LoggerService
();
if
(
wp_mkdir_p
(
self
::
LOG_DIR
)
)
{
if
(
wp_mkdir_p
(
self
::
LOG_DIR
)
)
{
$logger
->
info
(
'Log directory created successfully'
);
return
;
return
;
}
}
...
@@ -51,6 +47,26 @@ class LoggerService extends Monolog {
...
@@ -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
* Clears the log file
*
*
...
...
app/Service/TwigService.php
View file @
29c1e093
...
@@ -121,7 +121,7 @@ class TwigService extends AbstractService {
...
@@ -121,7 +121,7 @@ class TwigService extends AbstractService {
*/
*/
public
static
function
initCache
()
{
public
static
function
initCache
()
{
$logger
=
new
LoggerService
();
$logger
=
LoggerService
::
factory
();
if
(
wp_mkdir_p
(
self
::
CACHE_DIR
)
)
{
if
(
wp_mkdir_p
(
self
::
CACHE_DIR
)
)
{
$logger
->
info
(
'Twig cache directory created successfully'
);
$logger
->
info
(
'Twig cache directory created successfully'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment