-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
executable file
·91 lines (81 loc) · 2.61 KB
/
Module.php
File metadata and controls
executable file
·91 lines (81 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace BaseModule;
use BaseModule\Helper\EnvironmentHelper;
use BaseModule\Logger\ErrorHandler;
use BaseModule\Factory\ErrorHandler as ErrorHandlerFactory;
use Zend\Config\Config;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceManager;
/**
* Module.php
*
* @copyright Felix Buchheim
* @author Felix Buchheim <hanibal4nothing@gmail.com>
*/
class Module
{
/**
* @param MvcEvent $oEvent
*/
public function onBootstrap(MvcEvent $oEvent)
{
$oApp = $oEvent->getTarget();
$oEventManager = $oApp->getEventManager();
$oServiceManager = $oApp->getServiceManager();
$oErrorService = $oServiceManager->get('BaseModule\Logger\ErrorHandler');
/* @var ErrorHandler $oErrorService */
$aConfig = $oServiceManager->get('config');
if (true === $aConfig['baseModule']['errorHandler'][ErrorHandlerFactory::SYS_LOGGER_LOGGER]['enabled']) {
$oErrorService->registerAsErrorHandler();
}
if (true === $aConfig['baseModule']['errorHandler'][ErrorHandlerFactory::FATAL_ERROR_LOGGER]['enabled']) {
$oErrorService->registerFatalErrorHandler();
}
if (true === $aConfig['baseModule']['errorHandler'][ErrorHandlerFactory::EXCEPTION_LOGGER]['enabled']) {
/**
* Log every none-catched exception
*/
$oEventManager->attach('dispatch.error', function ($oEvent) use ($oErrorService) {
$oException = $oEvent->getResult()->exception;
if (true === isset ($oException)) {
$oErrorService->log($oException);
}
});
}
$this->fetchEnvironment($oServiceManager);
}
/**
* @return array
*/
public function getConfig()
{
return require __DIR__ . '/../../config/module.config.php';
}
/**
* @return array
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
__NAMESPACE__ . 'Test' => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
/**
* prepare the EnvironmentHelper
*
* @param ServiceManager $oSm
*
* @return $this
*/
protected function fetchEnvironment(ServiceManager $oSm)
{
$aConfig = $oSm->get('config');
EnvironmentHelper::fetchEnvironment(new Config($aConfig['baseModule']['environmentHelper']));
return $this;
}
}