|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Polder Knowledge / log-module (https://polderknowledge.com) |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/polderknowledge/log-module for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2016-2017 Polder Knowledge (https://polderknowledge.com) |
|
7
|
|
|
* @license https://github.com/polderknowledge/log-module/blob/master/LICENSE.md MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace PolderKnowledge\LogModule; |
|
11
|
|
|
|
|
12
|
|
|
use Monolog\ErrorHandler; |
|
13
|
|
|
use PolderKnowledge\LogModule\Helper\ZendLogUtils; |
|
14
|
|
|
use PolderKnowledge\LogModule\Listener\MvcEventError; |
|
15
|
|
|
use PolderKnowledge\LogModule\Service\FormatterPluginManager; |
|
16
|
|
|
use PolderKnowledge\LogModule\Service\HandlerPluginManager; |
|
17
|
|
|
use PolderKnowledge\LogModule\Service\ProcessorPluginManager; |
|
18
|
|
|
use Psr\Container\ContainerInterface; |
|
19
|
|
|
use Zend\EventManager\EventInterface; |
|
20
|
|
|
use Zend\Log\Logger; |
|
21
|
|
|
use Zend\ModuleManager\Feature\BootstrapListenerInterface; |
|
22
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
|
23
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
|
24
|
|
|
use Zend\ModuleManager\Listener\ServiceListenerInterface; |
|
25
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
|
26
|
|
|
use Zend\Mvc\MvcEvent; |
|
27
|
|
|
|
|
28
|
|
|
final class Module implements ConfigProviderInterface, BootstrapListenerInterface, InitProviderInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Returns configuration to merge with application configuration |
|
32
|
|
|
* |
|
33
|
|
|
* @return array|\Traversable |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function getConfig() |
|
36
|
|
|
{ |
|
37
|
3 |
|
return include __DIR__ . '/../config/module.config.php'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Listen to the bootstrap event |
|
42
|
|
|
* |
|
43
|
|
|
* @param EventInterface $event |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
6 |
|
public function onBootstrap(EventInterface $event) |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var MvcEvent $mvcEvent */ |
|
49
|
6 |
|
$mvcEvent = $event; |
|
50
|
|
|
|
|
51
|
6 |
|
$container = $mvcEvent->getApplication()->getServiceManager(); |
|
52
|
6 |
|
$mvcErrorLogger = $container->get(MvcEventError::class); |
|
53
|
6 |
|
$phpErrorLogger = $container->get('ErrorLogger'); |
|
54
|
|
|
|
|
55
|
|
|
// @todo Remove this statement in the next major version. This is just here for backwards compatibility. |
|
56
|
6 |
|
if ($phpErrorLogger instanceof Logger) { |
|
57
|
3 |
|
$phpErrorLogger = ZendLogUtils::extractPsrLogger($phpErrorLogger); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
6 |
|
ErrorHandler::register($phpErrorLogger); |
|
61
|
|
|
|
|
62
|
6 |
|
$eventManager = $mvcEvent->getApplication()->getEventManager(); |
|
63
|
6 |
|
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, $mvcErrorLogger); |
|
64
|
6 |
|
$eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, $mvcErrorLogger); |
|
65
|
6 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Initialize workflow |
|
69
|
|
|
* |
|
70
|
|
|
* @param ModuleManagerInterface $manager |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
3 |
|
public function init(ModuleManagerInterface $manager) |
|
74
|
|
|
{ |
|
75
|
|
|
// Load WShafer's PSR11MonoLog module so we have access to all Monolog factories. |
|
76
|
3 |
|
$manager->loadModule('WShafer\\PSR11MonoLog'); |
|
77
|
3 |
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|