-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathModule.php
More file actions
133 lines (116 loc) · 5.1 KB
/
Module.php
File metadata and controls
133 lines (116 loc) · 5.1 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace ZF2EntityAudit;
use Zend\Mvc\MvcEvent;
use ZF2EntityAudit\Audit\Configuration;
use ZF2EntityAudit\Audit\Manager ;
use ZF2EntityAudit\EventListener\CreateSchemaListener;
use ZF2EntityAudit\EventListener\LogRevisionsListener;
use ZF2EntityAudit\View\Helper\DateTimeFormatter;
use ZF2EntityAudit\View\Helper\EntityLabel;
use ZF2EntityAudit\View\Helper\User as UserBlock;
use ZF2EntityAudit\View\Helper\Dump ;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\Console\Adapter\AdapterInterface as Console;
class Module implements ConsoleUsageProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function onBootstrap(MvcEvent $e)
{
// Initialize the audit manager by creating an instance of it
$sm = $e->getApplication()->getServiceManager();
$sm->get('auditManager');
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'auditConfig' => function($sm){
$config = $sm->get('Config');
$auditconfig = new Configuration();
$auditconfig->setAuditedEntityClasses($config['zf2-entity-audit']['entities']);
$auditconfig->setZfcUserEntityClass($config['zf2-entity-audit']['zfcuser.entity_class']);
if (!empty($config['zf2-entity-audit']['note'])) {
$auditconfig->setNote($config['zf2-entity-audit']['note']);
}
if (!empty($config['zf2-entity-audit']['noteFormField'])) {
$auditconfig->setNoteFormField($config['zf2-entity-audit']['noteFormField']);
}
return $auditconfig;
},
'auditManager' => function ($sm) {
$config = $sm->get('Config');
$evm = $sm->get('doctrine.eventmanager.orm_default');
$auditconfig = $sm->get('auditConfig');
if ($config['zf2-entity-audit']['zfcuser.integration'] === true) {
$auth = $sm->get('zfcuser_auth_service');
if ($auth->hasIdentity()) {
$identity = $auth->getIdentity();
$auditconfig->setCurrentUser($identity);
}
/* need to handle the unauthenticated user action case, do it your own , 99% i will drop support for unauthenticated user auditing */
}
$auditManager = new Manager($auditconfig);
$evm->addEventSubscriber(new CreateSchemaListener($auditManager));
$evm->addEventSubscriber(new LogRevisionsListener($auditManager));
return $auditManager;
},
'auditReader' => function($sm) {
$auditManager = $sm->get('auditManager');
$entityManager = $sm->get('doctrine.entitymanager.orm_default');
return $auditManager->createAuditReader($entityManager);
},
),
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'DateTimeFormatter' => function($sm) {
$Servicelocator = $sm->getServiceLocator();
$config = $Servicelocator->get("Config");
$format = $config['zf2-entity-audit']['ui']['datetime.format'];
$formatter = new DateTimeFormatter();
return $formatter->setDateTimeFormat($format);
},
'UserBlock' => function($sm){
$Servicelocator = $sm->getServiceLocator();
$em = $Servicelocator->get("doctrine.entitymanager.orm_default");
$config = $Servicelocator->get("Config");
$helper = new UserBlock();
$helper->setEntityManager($em);
$helper->setZfcUserEntityClass($config['zf2-entity-audit']['zfcuser.entity_class']);
return $helper ;
},
'EntityLabel' => function($sm){
$helper = new EntityLabel();
return $helper ;
},
'Dump' => function(){
$helper = new Dump();
return $helper;
}
)
);
}
public function getConsoleUsage(Console $console)
{
return array(
"update" => "update the database from 0.1 to be 0.2 compatibale ",
"initialize-revisions <userEmail>" => "create initial revisions for all audited entities that do not have any revision"
);
}
}