Skip to content

Commit 6744005

Browse files
authored
Merge pull request #5 from Micro-PHP/v1.4
Version 1.4
2 parents e198512 + 247ef5a commit 6744005

File tree

10 files changed

+33
-23
lines changed

10 files changed

+33
-23
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<directory suffix=".php">src/</directory>
2222
<exclude>
2323
<directory>src/Exception</directory>
24-
<file>src/LoggerMonologPlugin.php</file>
24+
<file>src/MonologPlugin.php</file>
2525
</exclude>
2626
</whitelist>
2727
</filter>

psalm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
<UnnecessaryVarAnnotation>
2020
<errorLevel type="suppress">
21-
<file name="src/LoggerMonologPlugin.php"/>
21+
<file name="src/MonologPlugin.php"/>
2222
</errorLevel>
2323
</UnnecessaryVarAnnotation>
2424

2525
<MissingConstructor>
2626
<errorLevel type="suppress">
27-
<file name="src/LoggerMonologPlugin.php"/>
27+
<file name="src/MonologPlugin.php"/>
2828
</errorLevel>
2929
</MissingConstructor>
3030

3131
<ImplementedReturnTypeMismatch>
3232
<errorLevel type="suppress">
33-
<file name="src/LoggerMonologPlugin.php"/>
33+
<file name="src/MonologPlugin.php"/>
3434
</errorLevel>
3535
</ImplementedReturnTypeMismatch>
3636
</issueHandlers>

src/Business/Handler/HandlerFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Micro\Plugin\Logger\Monolog\Business\Handler;
1313

1414
use Micro\Component\DependencyInjection\Container;
15+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1516
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationFactoryInterface;
1617
use Monolog\Handler\HandlerInterface;
1718

@@ -23,14 +24,15 @@ public function __construct(
2324
) {
2425
}
2526

26-
public function create(string $handlerName): HandlerInterface
27+
public function create(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration, string $handlerName): HandlerInterface
2728
{
2829
$handlerConfiguration = $this->handlerConfigurationFactory->create($handlerName);
2930
$handlerClassName = $handlerConfiguration->getHandlerClassName();
3031

3132
return new $handlerClassName(
3233
$this->container,
33-
$handlerConfiguration
34+
$handlerConfiguration,
35+
$loggerProviderTypeConfiguration
3436
);
3537
}
3638
}

src/Business/Handler/HandlerFactoryInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Micro\Plugin\Logger\Monolog\Business\Handler;
1313

14+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1415
use Monolog\Handler\HandlerInterface;
1516

1617
interface HandlerFactoryInterface
1718
{
18-
public function create(string $handlerName): HandlerInterface;
19+
public function create(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration, string $handlerName): HandlerInterface;
1920
}

src/Business/Handler/HandlerProvider.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Micro\Plugin\Logger\Monolog\Business\Handler;
1313

14+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1415
use Monolog\Handler\HandlerInterface;
1516

1617
class HandlerProvider implements HandlerProviderInterface
@@ -25,13 +26,10 @@ public function __construct(private HandlerFactoryInterface $handlerFactory)
2526
$this->handlerCollection = [];
2627
}
2728

28-
/**
29-
* {@inheritDoc}
30-
*/
31-
public function getHandler(string $handlerName): HandlerInterface
29+
public function getHandler(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration, string $handlerName): HandlerInterface
3230
{
3331
if (!\array_key_exists($handlerName, $this->handlerCollection)) {
34-
$this->handlerCollection[$handlerName] = $this->handlerFactory->create($handlerName);
32+
$this->handlerCollection[$handlerName] = $this->handlerFactory->create($loggerProviderTypeConfiguration, $handlerName);
3533
}
3634

3735
return $this->handlerCollection[$handlerName];

src/Business/Handler/HandlerProviderInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Micro\Plugin\Logger\Monolog\Business\Handler;
1313

14+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1415
use Monolog\Handler\HandlerInterface;
1516

1617
interface HandlerProviderInterface
1718
{
18-
public function getHandler(string $handlerName): HandlerInterface;
19+
public function getHandler(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration, string $handlerName): HandlerInterface;
1920
}

src/Business/Handler/HandlerResolver.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1515
use Micro\Plugin\Logger\Monolog\Configuration\Logger\MonologPluginConfigurationInterface;
1616

17-
class HandlerResolver implements HandlerResolverInterface
17+
readonly class HandlerResolver implements HandlerResolverInterface
1818
{
1919
public function __construct(
20-
private readonly MonologPluginConfigurationInterface $pluginConfiguration,
21-
private readonly HandlerProviderInterface $handlerProvider,
22-
private readonly LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration
20+
private MonologPluginConfigurationInterface $pluginConfiguration,
21+
private HandlerProviderInterface $handlerProvider,
22+
private LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration
2323
) {
2424
}
2525

2626
public function resolve(): \Traversable
2727
{
28-
$loggerConfiguration = $this->pluginConfiguration->getLoggerConfiguration($this->loggerProviderTypeConfiguration->getLoggerName());
28+
$loggerConfiguration = $this->pluginConfiguration
29+
->getLoggerConfiguration($this->loggerProviderTypeConfiguration->getLoggerName());
2930

3031
foreach ($loggerConfiguration->getHandlerList() as $handlerName) {
31-
yield $this->handlerProvider->getHandler($handlerName);
32+
yield $this->handlerProvider->getHandler($this->loggerProviderTypeConfiguration, $handlerName);
3233
}
3334
}
3435
}

src/LoggerMonologPlugin.php renamed to src/MonologPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* @method MonologPluginConfigurationInterface configuration()
3939
*/
40-
class LoggerMonologPlugin implements DependencyProviderInterface, PluginDependedInterface, LoggerProviderPluginInterface, ConfigurableInterface
40+
class MonologPlugin implements DependencyProviderInterface, PluginDependedInterface, LoggerProviderPluginInterface, ConfigurableInterface
4141
{
4242
use PluginConfigurationTrait;
4343

tests/Unit/Business/Handler/HandlerFactoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Micro\Plugin\Logger\Monolog\Test\Unit\Business\Handler;
1515

1616
use Micro\Component\DependencyInjection\Container;
17+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1718
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerFactory;
1819
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationFactoryInterface;
1920
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationInterface;
@@ -36,7 +37,9 @@ public function testCreate()
3637
->willReturn($handlerConfig);
3738

3839
$handlerFactory = new HandlerFactory($container, $handlerConfigurationFactory);
39-
$handler = $handlerFactory->create('test');
40+
$handler = $handlerFactory->create(
41+
$this->createMock(LoggerProviderTypeConfigurationInterface::class),
42+
'test');
4043

4144
$this->assertInstanceOf(TestHandlerImpl::class, $handler);
4245
}

tests/Unit/Business/Handler/HandlerProviderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Micro\Plugin\Logger\Monolog\Test\Unit\Business\Handler;
1515

16+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
1617
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerFactoryInterface;
1718
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerProvider;
1819
use Monolog\Handler\HandlerInterface;
@@ -22,15 +23,18 @@ class HandlerProviderTest extends TestCase
2223
{
2324
public function testGetHandler()
2425
{
26+
$loggerProviderTypeCfg = $this->createMock(LoggerProviderTypeConfigurationInterface::class);
2527
$handlerFactory = $this->createMock(HandlerFactoryInterface::class);
2628
$handlerFactory->expects($this->once())
2729
->method('create')
2830
->willReturn(new TestHandlerImpl());
2931

3032
$provider = new HandlerProvider($handlerFactory);
31-
$handler = $provider->getHandler('test');
33+
$handler = $provider->getHandler(
34+
$loggerProviderTypeCfg,
35+
'test');
3236

33-
$this->assertSame($handler, $provider->getHandler('test'));
37+
$this->assertSame($handler, $provider->getHandler($loggerProviderTypeCfg, 'test'));
3438
$this->assertInstanceOf(HandlerInterface::class, $handler);
3539
}
3640
}

0 commit comments

Comments
 (0)