forked from cdli/CdliUserProfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
92 lines (85 loc) · 3.73 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
<?php
namespace CdliUserProfile;
use Zend\ModuleManager\ModuleManager,
Zend\EventManager\StaticEventManager,
Zend\ModuleManager\Feature\AutoloaderProviderInterface,
Zend\ModuleManager\Feature\BootstrapListenerInterface,
Zend\ModuleManager\Feature\ConfigProviderInterface,
Zend\EventManager\EventInterface;
class Module implements
BootstrapListenerInterface,
AutoloaderProviderInterface,
ConfigProviderInterface
{
public function onBootstrap(EventInterface $e)
{
$serviceManager = $e->getTarget()->getServiceManager();
$profileEvents = $serviceManager->get('CdliUserProfile\Service\Profile')->getEventManager();
$profileEvents->attachAggregate($serviceManager->get('CdliUserProfile\Integration\ZfcUser'));
}
public function getServiceConfig()
{
return array(
'factories' => array(
'cdliuserprofile_module_options' => function ($sm) {
$config = $sm->get('Configuration');
return new Options\ModuleOptions($config['cdli-user-profile']);
},
'CdliUserProfile\Service\Profile' => function($sm) {
$obj = new Service\Profile($sm->get('cdliuserprofile_module_options'));
return $obj;
},
'CdliUserProfile\Integration\ZfcUser' => function($sm) {
$obj = new Integration\ZfcUser();
$obj->setServiceLocator($sm);
return $obj;
},
'CdliUserProfile\Form\Section\ZfcUser' => function($sm) {
$obj = new Form\Section\ZfcUser($sm->get('zfcuser_module_options'));
$obj->setInputFilter($sm->get('CdliUserProfile\Form\Section\ZfcUserFilter'));
$obj->setHydrator($sm->get('zfcuser_user_hydrator'));
return $obj;
},
'CdliUserProfile\Form\Section\ZfcUserFilter' => function($sm) {
return new Form\Section\ZfcUserFilter(
$sm->get('cdliuserprofile_uemail_validator'),
$sm->get('cdliuserprofile_uusername_validator')
);
},
'cdliuserprofile_uemail_validator' => function($sm) {
$user = $sm->get('CdliUserProfile\Service\Profile')->getUser();
return new Validator\NoRecordExistsExceptIgnored(array(
'ignored_record_ids' => is_null($user) ? NULL : $user->getId(),
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
));
},
'cdliuserprofile_uusername_validator' => function($sm) {
$user = $sm->get('CdliUserProfile\Service\Profile')->getUser();
return new Validator\NoRecordExistsExceptIgnored(array(
'ignored_record_ids' => is_null($user) ? NULL : $user->getId(),
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'username'
));
}
)
);
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig($env = NULL)
{
return include __DIR__ . '/config/module.config.php';
}
}