mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
coding standards for woocommerce-logging module
This commit is contained in:
parent
7af7ace569
commit
653a765235
9 changed files with 176 additions and 124 deletions
|
@ -1,13 +1,15 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration
|
||||
* The logging extensions.
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Inpsyde\IZettle\Logging;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
return array();
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
/**
|
||||
* The logging module.
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
|
||||
return function (): ModuleInterface {
|
||||
return new WoocommerceLoggingModule();
|
||||
return new WoocommerceLoggingModule();
|
||||
};
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration
|
||||
* The logging services.
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
|
||||
|
@ -11,20 +14,20 @@ use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
|
|||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
return [
|
||||
'woocommerce.logger.source' => function(): string {
|
||||
return 'woocommerce-paypal-commerce-gateway';
|
||||
},
|
||||
'woocommerce.logger.woocommerce' => function (ContainerInterface $container): LoggerInterface {
|
||||
if (!class_exists(\WC_Logger::class)) {
|
||||
return new NullLogger();
|
||||
}
|
||||
return array(
|
||||
'woocommerce.logger.source' => function(): string {
|
||||
return 'woocommerce-paypal-commerce-gateway';
|
||||
},
|
||||
'woocommerce.logger.woocommerce' => function ( ContainerInterface $container ): LoggerInterface {
|
||||
if ( ! class_exists( \WC_Logger::class ) ) {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
$source = $container->get('woocommerce.logger.source');
|
||||
$source = $container->get( 'woocommerce.logger.source' );
|
||||
|
||||
return new WooCommerceLogger(
|
||||
wc_get_logger(),
|
||||
$source
|
||||
);
|
||||
},
|
||||
];
|
||||
return new WooCommerceLogger(
|
||||
wc_get_logger(),
|
||||
$source
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
*/
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
class NullLogger implements LoggerInterface
|
||||
{
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
/**
|
||||
* Class WooCommerceLogger
|
||||
* WooCommerce includes a logger interface, which is fully compatible to PSR-3,
|
||||
* but for some reason does not extend/implement it.
|
||||
*
|
||||
* This is a decorator that makes any WooCommerce Logger PSR-3-compatible
|
||||
*
|
||||
* @package Inpsyde\IZettle\Logging\Logger
|
||||
*/
|
||||
class WooCommerceLogger implements LoggerInterface
|
||||
{
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* @var \WC_Logger_Interface
|
||||
*/
|
||||
private $wcLogger;
|
||||
private $source;
|
||||
|
||||
public function __construct(\WC_Logger_Interface $wcLogger, string $source)
|
||||
{
|
||||
$this->wcLogger = $wcLogger;
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
if (!isset($context['source'])) {
|
||||
$context['source'] = $this->source;
|
||||
}
|
||||
$this->wcLogger->log($level, $message, $context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* The Null logger is used, when logging is disabled. It does not log at all
|
||||
* but complies with the LoggerInterface.
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging\Logger
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
/**
|
||||
* Class NullLogger
|
||||
*/
|
||||
class NullLogger implements LoggerInterface {
|
||||
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* Logs a message. Since its a NullLogger, it does not log at all.
|
||||
*
|
||||
* @param mixed $level The logging level.
|
||||
* @param string $message The message.
|
||||
* @param array $context The context.
|
||||
*/
|
||||
public function log( $level, $message, array $context = array() ) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce includes a logger interface, which is fully compatible to PSR-3,
|
||||
* but for some reason does not extend/implement it.
|
||||
*
|
||||
* This is a decorator that makes any WooCommerce Logger PSR-3-compatible
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging\Logger
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
/**
|
||||
* Class WooCommerceLogger
|
||||
*/
|
||||
class WooCommerceLogger implements LoggerInterface {
|
||||
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* The Woocommerce logger.
|
||||
*
|
||||
* @var \WC_Logger_Interface
|
||||
*/
|
||||
private $wc_logger;
|
||||
|
||||
/**
|
||||
* The source (Plugin), which logs the message.
|
||||
*
|
||||
* @var string The source.
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* WooCommerceLogger constructor.
|
||||
*
|
||||
* @param \WC_Logger_Interface $wc_logger The Woocommerce logger.
|
||||
* @param string $source The source.
|
||||
*/
|
||||
public function __construct( \WC_Logger_Interface $wc_logger, string $source ) {
|
||||
$this->wc_logger = $wc_logger;
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*
|
||||
* @param mixed $level The logging level.
|
||||
* @param string $message The message.
|
||||
* @param array $context The context.
|
||||
*/
|
||||
public function log( $level, $message, array $context = array() ) {
|
||||
if ( ! isset( $context['source'] ) ) {
|
||||
$context['source'] = $this->source;
|
||||
}
|
||||
$this->wc_logger->log( $level, $message, $context );
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class WoocommerceLoggingModule implements ModuleInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface
|
||||
{
|
||||
return new ServiceProvider(
|
||||
require __DIR__.'/../services.php',
|
||||
require __DIR__.'/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function run(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* The logging module.
|
||||
*
|
||||
* @package Inpsyde\Woocommerce\Logging
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class WoocommerceLoggingModule
|
||||
*/
|
||||
class WoocommerceLoggingModule implements ModuleInterface {
|
||||
|
||||
/**
|
||||
* Setup the module.
|
||||
*
|
||||
* @return ServiceProviderInterface
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface {
|
||||
return new ServiceProvider(
|
||||
require __DIR__ . '/../services.php',
|
||||
require __DIR__ . '/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the module.
|
||||
*
|
||||
* @param ContainerInterface $container The container.
|
||||
*/
|
||||
public function run( ContainerInterface $container ) {
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue