preconfigure loggerhandler with current OXID logger, use logger handler to get logger instance

This commit is contained in:
Daniel Seifert 2023-01-17 15:27:41 +01:00
parent bd466266cc
commit 637ef9669d
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
14 changed files with 24 additions and 44 deletions

View File

@ -16,8 +16,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model; namespace D3\Linkmobility4OXID\Application\Model;
use D3\LinkmobilityClient\Client; use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use Psr\Log\LoggerInterface;
class MessageClient class MessageClient
{ {
@ -32,12 +30,6 @@ class MessageClient
/** @var Client $client */ /** @var Client $client */
$client = oxNew(Client::class, $configuration->getApiToken()); $client = oxNew(Client::class, $configuration->getApiToken());
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
/** @var LoggerInterface $logger */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class);
$loggerHandler->setLogger($logger);
return $client; return $client;
} }
} }

View File

@ -20,7 +20,6 @@ use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\LinkmobilityClient\LoggerHandler; use D3\LinkmobilityClient\LoggerHandler;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
class MessageSender class MessageSender
{ {

View File

@ -24,6 +24,7 @@ use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Client; use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Exceptions\RecipientException; use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\RecipientsList\RecipientsList; use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface; use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\Request\RequestInterface;
@ -51,12 +52,12 @@ class Sms extends AbstractMessage
*/ */
public function sendUserAccountMessage(User $user): bool public function sendUserAccountMessage(User $user): bool
{ {
$this->getLogger()->debug('startRequest', ['userId' => $user->getId()]); $this->getLogger()->debug('Linkmobility: startRequest', ['userId' => $user->getId()]);
$return = $this->sendCustomRecipientMessage($this->getUserRecipientsList($user)); $return = $this->sendCustomRecipientMessage($this->getUserRecipientsList($user));
if ($return) { if ($return) {
$this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage()); $this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage());
} }
$this->getLogger()->debug('finishRequest', ['userId' => $user->getId()]); $this->getLogger()->debug('Linkmobility: finishRequest', ['userId' => $user->getId()]);
return $return; return $return;
} }
@ -91,12 +92,12 @@ class Sms extends AbstractMessage
*/ */
public function sendOrderMessage(Order $order): bool public function sendOrderMessage(Order $order): bool
{ {
$this->getLogger()->debug('startRequest', ['orderId' => $order->getId()]); $this->getLogger()->debug('Linkmobility: startRequest', ['orderId' => $order->getId()]);
$return = $this->sendCustomRecipientMessage($this->getOrderRecipientsList($order)); $return = $this->sendCustomRecipientMessage($this->getOrderRecipientsList($order));
if ($return) { if ($return) {
$this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage()); $this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
} }
$this->getLogger()->debug('finishRequest', ['orderId' => $order->getId()]); $this->getLogger()->debug('Linkmobility: finishRequest', ['orderId' => $order->getId()]);
return $return; return $return;
} }
@ -245,8 +246,8 @@ class Sms extends AbstractMessage
*/ */
public function getLogger(): LoggerInterface public function getLogger(): LoggerInterface
{ {
/** @var LoggerInterface $logger */ /** @var LoggerHandler $loggerHandler */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class); $loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
return $logger; return $loggerHandler->getLogger();
} }
} }

View File

@ -24,6 +24,8 @@ services:
factory: factory:
- 'D3\LinkmobilityClient\LoggerHandler' - 'D3\LinkmobilityClient\LoggerHandler'
- 'getInstance' - 'getInstance'
calls:
- [setLogger, ['@d3ox.linkmobility.Psr\Log\LoggerInterface']]
shared: true shared: true
D3\LinkmobilityClient\Client: D3\LinkmobilityClient\Client:

View File

@ -15,12 +15,10 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Modules\Core; namespace D3\Linkmobility4OXID\Modules\Core;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageSender; use D3\Linkmobility4OXID\Application\Model\MessageSender;
use D3\TestingTools\Production\IsMockable; use D3\TestingTools\Production\IsMockable;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;

View File

@ -16,10 +16,10 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Setup; namespace D3\Linkmobility4OXID\Setup;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage; use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException; use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Statement; use Doctrine\DBAL\Statement;
use Monolog\Logger; use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Content; use OxidEsales\Eshop\Application\Model\Content;
@ -37,7 +37,6 @@ use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInt
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
class Actions class Actions
{ {
@ -53,9 +52,9 @@ class Actions
$this->addRemarkTypeEnumValue(); $this->addRemarkTypeEnumValue();
} }
} catch (StandardException|DoctrineDriverException|DoctrineException $e) { } catch (StandardException|DoctrineDriverException|DoctrineException $e) {
/** @var Logger $logger */ /** @var LoggerHandler $loggerHandler */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class); $loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$logger->error($e->getMessage()); $loggerHandler->getLogger()->error($e->getMessage());
/** @var UtilsView $utilsView */ /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class); $utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e->getMessage()); $utilsView->addErrorToDisplay($e->getMessage());

View File

@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Exception; use Exception;
@ -34,7 +35,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class adminUserTest extends LMIntegrationTestCase class adminUserTest extends LMIntegrationTestCase
{ {
@ -61,7 +61,7 @@ class adminUserTest extends LMIntegrationTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->method('error'); $loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock); d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\integration; namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Exception; use Exception;
@ -33,7 +34,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class canceledOrderTest extends LMIntegrationTestCase class canceledOrderTest extends LMIntegrationTestCase
{ {
@ -62,7 +62,7 @@ class canceledOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->method('error'); $loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock); d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);

View File

@ -18,6 +18,7 @@ namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Modules\Core\EmailCore; use D3\Linkmobility4OXID\Modules\Core\EmailCore;
use D3\Linkmobility4OXID\Modules\Core\EmailCore_parent; use D3\Linkmobility4OXID\Modules\Core\EmailCore_parent;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Exception; use Exception;
@ -36,7 +37,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class finishedOrderTest extends LMIntegrationTestCase class finishedOrderTest extends LMIntegrationTestCase
{ {
@ -65,7 +65,7 @@ class finishedOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->method('error'); $loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock); d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */ /** @var User $user */
$this->user = $user = oxNew(User::class); $this->user = $user = oxNew(User::class);

View File

@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Modules\Core\EmailCore; use D3\Linkmobility4OXID\Modules\Core\EmailCore;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Exception; use Exception;
@ -35,7 +36,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class sendedNowOrderTest extends LMIntegrationTestCase class sendedNowOrderTest extends LMIntegrationTestCase
{ {
@ -378,7 +378,7 @@ class sendedNowOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->method('error'); $loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock); d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
$this->setClientResponse( $this->setClientResponse(
new RequestException( new RequestException(

View File

@ -27,7 +27,6 @@ use D3\LinkmobilityClient\SMS\Response;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use InvalidArgumentException; use InvalidArgumentException;
use JetBrains\PhpStorm\ArrayShape;
use OxidEsales\Eshop\Core\Request; use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;

View File

@ -19,10 +19,8 @@ use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\MessageClient; use D3\Linkmobility4OXID\Application\Model\MessageClient;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\Client; use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException; use ReflectionException;
class MessageClientTest extends LMUnitTestCase class MessageClientTest extends LMUnitTestCase
@ -54,12 +52,5 @@ class MessageClientTest extends LMUnitTestCase
'getClient' 'getClient'
) )
); );
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$this->assertInstanceOf(
LoggerInterface::class,
$loggerHandler->getLogger()
);
} }
} }

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Model\MessageTypes; namespace D3\Linkmobility4OXID\tests\unit\Application\Model\MessageTypes;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageClient; use D3\Linkmobility4OXID\Application\Model\MessageClient;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients; use D3\Linkmobility4OXID\Application\Model\OrderRecipients;

View File

@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\tests\unit\Setup;
use D3\Linkmobility4OXID\Setup\Actions; use D3\Linkmobility4OXID\Setup\Actions;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
@ -30,7 +31,6 @@ use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactory; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactory;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException; use ReflectionException;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
@ -56,7 +56,7 @@ class ActionsTest extends LMUnitTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$loggerMock->expects($this->exactly((int) $throwException))->method('error'); $loggerMock->expects($this->exactly((int) $throwException))->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock); d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var UtilsView|MockObject $utilsViewMock */ /** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class) $utilsViewMock = $this->getMockBuilder(UtilsView::class)