1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Micro framework package. |
5
|
|
|
* |
6
|
|
|
* (c) Stanislau Komar <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Micro\Plugin\Logger; |
13
|
|
|
|
14
|
|
|
use Micro\Component\DependencyInjection\Container; |
15
|
|
|
use Micro\Framework\Kernel\KernelInterface; |
16
|
|
|
use Micro\Framework\Kernel\Plugin\ConfigurableInterface; |
17
|
|
|
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; |
18
|
|
|
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; |
19
|
|
|
use Micro\Plugin\Logger\Business\Provider\LoggerProvider; |
20
|
|
|
use Micro\Plugin\Logger\Business\Provider\LoggerProviderInterface; |
21
|
|
|
use Micro\Plugin\Logger\Configuration\LoggerPluginConfigurationInterface; |
22
|
|
|
use Micro\Plugin\Logger\Facade\LoggerFacade; |
23
|
|
|
use Micro\Plugin\Logger\Facade\LoggerFacadeInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Stanislau Komar <[email protected]> |
27
|
|
|
* |
28
|
|
|
* @method LoggerPluginConfigurationInterface configuration() |
29
|
|
|
*/ |
30
|
|
|
class LoggerPlugin implements DependencyProviderInterface, ConfigurableInterface |
31
|
|
|
{ |
32
|
|
|
use PluginConfigurationTrait; |
33
|
|
|
|
34
|
|
|
private ?LoggerProviderInterface $loggerProvider = null; |
35
|
|
|
|
36
|
|
|
private KernelInterface $kernel; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
|
|
public function provideDependencies(Container $container): void |
42
|
|
|
{ |
43
|
|
|
$container->register(LoggerFacadeInterface::class, function ( |
44
|
|
|
KernelInterface $kernel |
45
|
|
|
) { |
46
|
|
|
$this->kernel = $kernel; |
47
|
|
|
|
48
|
|
|
return $this->createLoggerFacade(); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getLoggerProvider(): LoggerProviderInterface |
53
|
|
|
{ |
54
|
|
|
if (!$this->loggerProvider) { |
55
|
|
|
$this->loggerProvider = $this->createLoggerProvider(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->loggerProvider; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function createLoggerProvider(): LoggerProviderInterface |
62
|
|
|
{ |
63
|
|
|
return new LoggerProvider( |
64
|
|
|
$this->kernel, |
65
|
|
|
$this->configuration() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function createLoggerFacade(): LoggerFacadeInterface |
70
|
|
|
{ |
71
|
|
|
return new LoggerFacade($this->getLoggerProvider()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|