extract dependend OXID methods

This commit is contained in:
Daniel Seifert 2024-12-25 22:39:03 +01:00
parent 6ab1cabc16
commit 871c8bc015
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
7 changed files with 105 additions and 23 deletions

View File

@ -1,8 +1,6 @@
parameters:
scanFiles:
- vendor/oxid-esales/oxideshop-ce/source/bootstrap.php
- vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php
- vendor/oxid-esales/oxideshop-ce/source/overridablefunctions.php
bootstrapFiles:
- tests\Helpers\classAliases.php
paths:
- src
level: 10

View File

@ -0,0 +1,42 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\GuzzleFactory\Apps;
use OxidEsales\Eshop\Core\Registry;
use RuntimeException;
trait OxidLoggerTrait
{
public function addOxidLogger(): void
{
if (!class_exists(Registry::class)) {
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
}
$this->loggers['oxid'] = Registry::getLogger();
}
public function getOxidLogPath(string $fileName): string
{
if (!defined(OX_BASE_PATH)) {
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
}
return OX_BASE_PATH . 'log' . DIRECTORY_SEPARATOR . $fileName;
}
}

View File

@ -17,36 +17,32 @@ declare(strict_types=1);
namespace D3\GuzzleFactory;
use D3\GuzzleFactory\Apps\OxidLoggerTrait;
use Exception;
use InvalidArgumentException;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use OxidEsales\Eshop\Core\Registry;
use Psr\Log\LoggerInterface;
trait LoggerTrait
{
use OxidLoggerTrait;
/** @var LoggerInterface[] */
protected array $loggers = [];
protected ?int $messageLevel = null;
public function addOxidLogger(): void
{
$this->loggers['oxid'] = Registry::getLogger();
}
public function addFileLogger(string $loggerName, string $fileName, int $logLevel = Logger::INFO, ?int $maxFiles = null): void
/**
* @throws Exception
* @throws InvalidArgumentException
*/
public function addFileLogger(string $loggerName, string $filePath, int $logLevel = Logger::INFO, ?int $maxFiles = null): void
{
$logger = new Logger($loggerName);
$stream_handler = is_null($maxFiles) ?
new StreamHandler(
OX_BASE_PATH . 'log' . DIRECTORY_SEPARATOR . $fileName,
$logLevel
) :
new RotatingFileHandler(
OX_BASE_PATH . 'log' . DIRECTORY_SEPARATOR . $fileName,
$maxFiles,
$logLevel
);
new StreamHandler($filePath, $logLevel) :
new RotatingFileHandler($filePath, $maxFiles, $logLevel);
$logger->pushHandler($stream_handler);
$this->loggers[$loggerName] = $logger;

View File

@ -33,7 +33,7 @@ abstract class ApiTestCase extends TestCase
* @return mixed
* @throws ReflectionException
*/
public function callMethod(object $object, string $methodName, array $arguments = []): mixed
public function callMethod(object $object, string $methodName, array $arguments = [])
{
$class = new ReflectionClass($object);
$method = $class->getMethod($methodName);
@ -65,7 +65,7 @@ abstract class ApiTestCase extends TestCase
* @return mixed
* @throws ReflectionException
*/
public function getValue(object $object, string $valueName): mixed
public function getValue(object $object, string $valueName)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);

View File

@ -32,4 +32,4 @@ class GuzzleFactoryTest extends ApiTestCase
$this->assertInstanceOf(GuzzleFactory::class, $instance);
}
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\OxidGuzzleFactory\tests\Helpers;
use Monolog\Logger;
class OxidRegistryStub
{
public static function getLogger(): Logger
{
return new Logger('loggerFixture');
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
use D3\OxidGuzzleFactory\tests\Helpers\OxidRegistryStub;
const OX_BASE_PATH = __DIR__;
class_alias(OxidRegistryStub::class, '\OxidEsales\Eshop\Core\Registry');