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;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use Psr\Log\LoggerInterface;
class MessageClient
{
@ -32,12 +30,6 @@ class MessageClient
/** @var Client $client */
$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;
}
}

View File

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

View File

@ -24,6 +24,7 @@ use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
use D3\LinkmobilityClient\Request\RequestInterface;
@ -51,12 +52,12 @@ class Sms extends AbstractMessage
*/
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));
if ($return) {
$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;
}
@ -91,12 +92,12 @@ class Sms extends AbstractMessage
*/
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));
if ($return) {
$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;
}
@ -245,8 +246,8 @@ class Sms extends AbstractMessage
*/
public function getLogger(): LoggerInterface
{
/** @var LoggerInterface $logger */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class);
return $logger;
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
return $loggerHandler->getLogger();
}
}

View File

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

View File

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

View File

@ -16,10 +16,10 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Setup;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Statement;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Content;
@ -37,7 +37,6 @@ use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInt
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
class Actions
{
@ -53,9 +52,9 @@ class Actions
$this->addRemarkTypeEnumValue();
}
} catch (StandardException|DoctrineDriverException|DoctrineException $e) {
/** @var Logger $logger */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class);
$logger->error($e->getMessage());
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->error($e->getMessage());
/** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$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\Controller\Admin\AdminUser;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
@ -34,7 +35,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class adminUserTest extends LMIntegrationTestCase
{
@ -61,7 +61,7 @@ class adminUserTest extends LMIntegrationTestCase
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */
$this->user = $user = oxNew(User::class);

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
@ -33,7 +34,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class canceledOrderTest extends LMIntegrationTestCase
{
@ -62,7 +62,7 @@ class canceledOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */
$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\Modules\Core\EmailCore;
use D3\Linkmobility4OXID\Modules\Core\EmailCore_parent;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
@ -36,7 +37,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class finishedOrderTest extends LMIntegrationTestCase
{
@ -65,7 +65,7 @@ class finishedOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
/** @var User $user */
$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\Modules\Core\EmailCore;
use D3\LinkmobilityClient\LoggerHandler;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
@ -35,7 +36,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
class sendedNowOrderTest extends LMIntegrationTestCase
{
@ -378,7 +378,7 @@ class sendedNowOrderTest extends LMIntegrationTestCase
->disableOriginalConstructor()
->getMock();
$loggerMock->method('error');
d3GetOxidDIC()->set('d3ox.linkmobility.'.LoggerInterface::class, $loggerMock);
d3GetOxidDIC()->get(LoggerHandler::class)->setLogger($loggerMock);
$this->setClientResponse(
new RequestException(

View File

@ -27,7 +27,6 @@ use D3\LinkmobilityClient\SMS\Response;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Development\CanAccessRestricted;
use InvalidArgumentException;
use JetBrains\PhpStorm\ArrayShape;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView;
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\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
class MessageClientTest extends LMUnitTestCase
@ -54,12 +52,5 @@ class MessageClientTest extends LMUnitTestCase
'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;
use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageClient;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
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\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
@ -30,7 +31,6 @@ use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
use Symfony\Component\DependencyInjection\Container;
@ -56,7 +56,7 @@ class ActionsTest extends LMUnitTestCase
->disableOriginalConstructor()
->getMock();
$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 */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)