This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModule.php
105 lines (89 loc) · 3.3 KB
/
Module.php
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace SoliantEntityAudit;
use Zend\Mvc\MvcEvent
, SoliantEntityAudit\Options\ModuleOptions
, SoliantEntityAudit\Service\AuditService
, SoliantEntityAudit\Loader\AuditAutoloader
, SoliantEntityAudit\EventListener\LogRevision
, SoliantEntityAudit\View\Helper\DateTimeFormatter
, SoliantEntityAudit\View\Helper\EntityValues
;
class Module
{
private static $moduleOptions;
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
'SoliantEntityAudit\Loader\AuditAutoloader' => array(
'namespaces' => array(
'SoliantEntityAudit\Entity' => __DIR__,
)
),
);
}
public function onBootstrap(MvcEvent $e)
{
$moduleOptions = $e->getApplication()->getServiceManager()->get('auditModuleOptions');
self::setModuleOptions($moduleOptions);
}
public static function setModuleOptions(ModuleOptions $moduleOptions)
{
self::$moduleOptions = $moduleOptions;
}
public static function getModuleOptions()
{
return self::$moduleOptions;
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'auditModuleOptions' => function($serviceManager){
$config = $serviceManager->get('Application')->getConfig();
$auditConfig = new ModuleOptions();
$auditConfig->setDefaults($config['audit']);
$auditConfig->setEntityManager($serviceManager->get('doctrine.entitymanager.orm_default'));
$auditConfig->setAuditService($serviceManager->get('auditService'));
$auth = $serviceManager->get($auditConfig->getAuthenticationService());
if ($auth->hasIdentity()) {
if ($auditConfig->getEntityManager()->contains($auth->getIdentity())) {
$auditConfig->setUser($auth->getIdentity());
} else {
$auditConfig->setUser($auditConfig->getEntityManager()->merge($auth->getIdentity()));
}
}
return $auditConfig;
},
'auditService' => function($sm) {
return new AuditService();
}
),
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'auditDateTimeFormatter' => function($sm) {
$Servicelocator = $sm->getServiceLocator();
$config = $Servicelocator->get("Config");
$format = $config['audit']['datetimeFormat'];
$formatter = new DateTimeFormatter();
return $formatter->setDateTimeFormat($format);
},
'auditService' => function($sm) {
return new AuditService();
}
)
);
}
}